membersound membersound - 1 year ago 125
Java Question

Keep CDATA for xstl transformation?

I'm doing a xstl transformation with saxon from an XML document.
The doc is not standard-valid XML, and I want to preserve all

elements that are found in there.

However using the .xsl file for transformation with

Transformer trans = TransformerFactory.newInstance().newTransformer(new StreamSource(new File("foo.xsl"));
trans.transform(new StreamSource(new File("foo.xml"), new StreamResult(new File("output.xml")));

results in stripping out these CDATA entries. How can I prevent this?

Answer Source

You can't, as the distinction whether a text originated from a cdata section is not available in the datamodel used by xslt. You can however define in your stylesheet that certain result elements are to be wrapped inside cdata. This is done using the cdata-section-elements attribute of the xsl:output element in your stylesheet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download