Project

Profile

Help

XSLT document format command tags not working with s9api?

Added by Allen Bagwell almost 6 years ago

I'm using Saxon-EE 9.6.0.8 and have encountered an odd issue.

In the past I've mapped the javax.xml.transform.TransformerFactory to the net.sf.saxon.TransformerFactoryImpl class for doing XSLT 2.0 transforms. Works perfect. Recently however I attempted to do a complete s9api approach to setting up the transformer. This also worked, but the formatting output ignored the settings for:

<xsl:output ident="no" omit-xml-declaration="no"> <xsl:strip-space elements="*">

That is when I ran my XSLT 2.0 stylesheet using the javax mapping and classes, the entire output document was all on a single line starting with the XML declaration element. When I changed the invocation to use the s9api classes the exact same stylesheet produced formatted XML output (line breaks and indents) and the declaration element was missing. I even tweaked it to run as a 3.0 stylesheet, but it behaved the same way.

Is there something about using the s9api that requires more than the stylesheet output commands to get what I want?

Thanks! Allen


Replies (4)

Please register to reply

RE: XSLT document format command tags not working with s9api? - Added by Michael Kay almost 6 years ago

How did you set up the transformation destination?

RE: XSLT document format command tags not working with s9api? - Added by Allen Bagwell almost 6 years ago

I used

XdmDestination dest = new XdmDestination(); transformer.setDestination(dest);

...

transformer.transform(); String output = dest.getXdmNode().toString();

RE: XSLT document format command tags not working with s9api? - Added by Michael Kay almost 6 years ago

An XdmDestination is just a tree in memory. When you serialize that tree using dest.getXdmNode().toString() the serialization performed by the toString() method has no knowledge of the xsl:output parameters in the stylesheet. You need to send the output of the transformation to a Serializer; the transformer and serializer will communicate with each other to decide which serialization parameters to use.

RE: XSLT document format command tags not working with s9api? - Added by Allen Bagwell almost 6 years ago

Ah, of course. That makes sense. Just didn't think it through. It's working now.

Thanks, Michael! :)

    (1-4/4)

    Please register to reply