Reputation: 57
Using XSLT how do we render CDATA tag?
In xslt I dont want to create CDATA tag using text or declaring in xml output tag using cdata-section-elements, it should read it dynamically from input, if element value is around CDATA than then xslt should render the same, as shown below
Input:
<A><![CDATA[Hello World]]></A>
XSLT Output :
<A><![CDATA[Hello World]]></A>
Upvotes: 0
Views: 247
Reputation: 167716
The data model XSLT/XPath/XQuery operate on does not know any CDATA sections so you can't simply preserve them as the tree you operate on simply contains a text node in both cases (i.e. for <foo>a & b</foo>
and <foo><![CDATA[a & b]]></foo>
the tree is a foo
element containing a single text child node with the string value a & b
).
So there is no way in pure XSLT to achieve what you want, unless you pre-process the input to convert CDATA sections into some structure like elements the XSLT data model allows you to detect and distinguish. Andrew Welch has http://andrewjwelch.com/lexev/ to do that in a Java environment.
Thus if you use an XSLT 2.0 processor like Saxon 9 with Java you could use that approach.
Upvotes: 4