XSLT 2 : How to pass an input stream as a parameter to XSL sheet - xslt-2.0

I am using Saxon HE 10
(using Xslt30Transformer)
How to pass input stream as a parameter to XSL?
I see there is a setStylesheetParameters . How to send input stream , as this expects object of type XdmValue?
I used to set the file name parameter , trying to pass the stream instead
<xsl:param name="test" select="'test.xml'"/>

You can pass any Java object (including a Stream) by wrapping it in an XdmExternalObject (which is a subclass of XdmValue). But is it a good idea? What are you actually trying to achieve? A Stream is a mutable object (reading from the stream changes its state) and mutable objects and XSLT don't really play very well together. If we knew what you wanted to achieve we might be able to suggest a better design.

Related

Add Sensorevents to CEP Engine and get a list of all properties

I want to build a CEP-Engine which is dynamic so you can add different event streams. As soon as a new stream is added, Esper should be able to read all the properties of the stream and put it into a list, for example. (For example integer id, long temperature, date timestamp etc.)
Is this possible in Esper?
Would be very grateful for any help
In order to add a stream at runtime you can use create-schema.
create schema MyStream(id int, ...)
For a stream that accepts events that an application sends using EPEventServive#sendEvent you should add the bus and public annotation (or set the equivalent compiler flags).
#public #buseventtype create schema MyStream(id int, ...)
You can now use this stream.
select * from MyStream
You can attach a listener and have it do some logic.
The Esper examples have a lot of detail. The create-schema is used in the "runtimeconfig" example.
Thank you for answering. I'm afraid I didn't make myself clear. I want to be able to add event streams where I don't know beforehand what kind of properties the events have. So I don't know before if there is an integer ID or if there is a date timestamp and which payload might be there. As soon as I add such an unknown event, Esper should examine the stream and return the contained properties of the stream to me.

Operations on a stream produce a result, but do not modify its underlying data source

Unable to understand how "Operations on a stream produce a result, but do not modify its underlying data source" with reference to java 8 streams.
shapes.stream()
.filter(s -> s.getColor() == BLUE)
.forEach(s -> s.setColor(RED));
As per my understanding, forEach is setting the color of object from shapes then how does the top statement hold true?
The value s isn't being altered in this example, however no deep copy is taken, and there is nothing to stop you altering the object referenced.
Are able to can alter an object via a reference in any context in Java and there isn't anything to prevent it. You can only prevent shallow values being altered.
NOTE: Just because you are able to do this doesn't mean it's a good idea. Altering an object inside a lambda is likely to be dangerous as functional programming models assume you are not altering the data being process (always creating new object instead)
If you are going to alter an object, I suggest you use a loop (non functional style) to minimise confusion.
An example of where using a lambda to alter an object has dire consequences is the following.
map.computeIfAbsent(key, k -> {
map.computeIfAbsent(key, k -> 1);
return 2;
});
The behaviour is not deterministic, can result in both key/values being added and for ConcurrentHashMap, this will never return.
As mentioned Here
Most importantly, a stream isn’t a data structure.
You can often create a stream from collections to apply a number of functions on a data structure, but a stream itself is not a data structure. That’s so important, I mentioned it twice! A stream can be composed of multiple functions that create a pipeline that data that flows through. This data cannot be mutated. That is to say the original data structure doesn’t change. However the data can be transformed and later stored in another data structure or perhaps consumed by another operation.
AND as per Java docs
This is possible only if we can prevent interference with the data
source during the execution of a stream pipeline.
And the reason is :
Modifying a stream's data source during execution of a stream pipeline
can cause exceptions, incorrect answers, or nonconformant behavior.
That's all theory, live examples are always good.
So here we go :
Assume we have a List<String> (say :names) and stream of this names.stream(). We can apply .filter(), .reduce(), .map() etc but we can never change the source. Meaning if you try to modify the source (names) you will get an java.util.ConcurrentModificationException .
public static void main(String[] args) {
List<String> names = new ArrayList<>();
names.add("Joe");
names.add("Phoebe");
names.add("Rose");
names.stream().map((obj)->{
names.add("Monika"); //modifying the source of stream, i.e. ConcurrentModificationException
/**
* If we comment the above line, we are modifying the data(doing upper case)
* However the original list still holds the lower-case names(source of stream never changes)
*/
return obj.toUpperCase();
}).forEach(System.out::println);
}
I hope that would help!
I understood the part do not modify its underlying data source - as it will not add/remove elements to the source; I think you are safe since you alter an element, you do not remove it.
You ca read comments from Tagir and Brian Goetz here, where they do agree that this is sort of fine.
The more idiomatic way to do what you want, would be a replace all for example:
shapes.replaceAll(x -> {
if(x.getColor() == BLUE){
x.setColor(RED);
}
return x;
})

How do I edit an XML file using type providers?

I understand how to retrieve data from an XML source using type providers. However, I need to then modify a particular part of the XML and save it to disk. I have tried assigning a value to the node using <- but the property is read-only.
For example:
let doc = MyXml.load fileName
doc.ItemId.Id <- "newId" // doesn't work
doc |> saveXml
There is a similar question for JSON where the suggestion is to create a new object, but this is specifically for XML.
While researching my question I found that you can use the .XElement accessor to get a reference to a mutable XElement object. Thus a solution is:
let doc = MyXml.load fileName
doc.ItemId.XElement.Element(XName.Get "Id").Value <- "newId" // tada
doc.XDocument.Save(...)
Note that you have to use the .XElement accessor on the parent if you're modifying a leaf node. This is because the leaf node's type is a primitive and doesn't have an .XElement accessor of its own. A slight shame, but I suppose it makes life easier on the other side when you want read-only access to the value.

Unmarshalling using castor mapping

I have a doubt in using castor mapping.
I know Castor will look for classes with the same name as that of element name. I have my castor mapping ready and it is working fine.
My doubt is, what if an element is received as null [I mean no value is being passed]? Castor will try to instantiate the class and assign null? or will it skip those classes?
If it tries to create an instance of that class, what performance are we going to loose? something to discard or does it have much impact on performance?
EDIT-Including the XML
<Order>
<Activity>
<ActivityID>String</ActivityID>
<ActivityName>String</ActivityName>
<CurrentActivityInd>String</CurrentActivityInd>
<Description>String</Description>
<Reason>String</Reason>
<StartDateTime>2001-12-17T09:30:47Z</StartDateTime>
<EndDateTime>2001-12-17T09:30:47Z</EndDateTime>
<Status>String</Status>
<Action>String</Action>
<Owner>String</Owner>
</Activity> </Order>
Above is just a part of my XML. "Order can have any number of activity child within it".My question is,
What if I pass the XML like without any value? Will it instantiate Order and Activity class or Order class alone or none of the two?
Thanks!

smart gwt save list as attribute

Hello i am new in smart gwt and now we are migrate from smartgwt 2.1 to smart gwt 3.1p
and i have got problem :
java.lang.UnsupportedOperationException: Can not convert element 0 of
the array to a JavaScriptObject. Instances of class
`com.test.ListDTO'
can not automatically be converted. Please see the SmartClient
documentation of RPCRequest.data for a table of Java types that can be
converted automatically.
someone write :
treeNode.setAttribute(TODO, listDTO.getLis());
how i can fix that code ?
The setAttribute method of the TreeNode tries to convert the list elements internally. That fails with your own domain objects. You can try to set the list with this helper method:
com.smartgwt.client.util.JSOHelper.setObjectAttribute(treeNode.getJsObj(), TODO, listDTO.getLis());
Now the Java object is set on the JavaScriptObject. To get this object back you can call:
treeNode.getAttributeAsObject(TODO);

Resources