Passing XML (node) parameters to XSLT in Saxon

Here should go questions about transforming XML with XSLT and FOP.
michuk
Posts: 8
Joined: Tue Dec 11, 2007 1:52 pm

Passing XML (node) parameters to XSLT in Saxon

Post by michuk »

Hi,

Here is my use case
- I have a Java app from which I'm calling an XSLT to transform XML into HTML
- The XSLT is a file in JAR
- The XML is passed as a stream from another application

Now, the problem is:
- I need to pass another XML document to this XSLT, from a different application and then access it as a node in XSLT

Here are the alternatives I can think of :
1. Using the document() xslt function with XML as stream.
I tried doing it with document() function but it doesn't seem to work in Saxon when the document has to be passed as stream. Here is my moaning: http://groups.google.com/group/XSLT/bro ... 738196933e

2. Using the document() xslt function by refering to an external document (using REST)
I don't really like that idea, as I'd have to expose the service for providing additional data as REST (lots of issues with that, especially permissioning is tricky)

3. Passing the XML documents as parameters to XSLT using something like:

XsltTransformer trans = comp.compile(new StreamSource(MyTransformerClass.getResourceAsStream(XSLT_FILE)).load();
trans.setParameter(new QName(paramName), new XdmAtomicValue(params.get(paramName)));
but with using a XdmNode instead of the XdmAtomicValue.

A few issues with this solution:
- I'm not sure how create an XdmNode - it does not have a public constructor (but probably there is a way, more investigation is needed here)
- More important: not sure if I can use parameters are nodes in XSLT, so that I could declare something like:
<xsl:param name="operatingSystems" as="xs:node" required="yes" />
and then use XPath like $operatingSystems/system[@name='Linux']/defaultHomeDirectory

4. Adding the additional XML at the end of the source XML for my XSLT.

A VERY very ugly solution which just works....

I'm be very glad to hear your ideas!

michuk
michuk
Posts: 8
Joined: Tue Dec 11, 2007 1:52 pm

Re: Passing XML (node) parameters to XSLT in Saxon

Post by michuk »

Here is part II of the story: http://www.daniweb.com/forums/post735870.html

I managed to generate an XdmNode and pass an XML into the
transformation but it works only when a File is used as a parameter to
build method or saxon's DocumentBuilder. When passing a Source, saxon
is throwing a NullPointer. Is this a saxon bug or am I a moron (I
supposed the latter).
michuk
Posts: 8
Joined: Tue Dec 11, 2007 1:52 pm

Re: Passing XML (node) parameters to XSLT in Saxon

Post by michuk »

OK, it was indeed a bug in saxon, I guess, solved in the latest release of Saxon: 9.1.0.3
Sorry for bugging anyone.
Borys
Post Reply