Vojtech
Vojtech

Reputation: 2603

How to use XML wrapped in CDATA inside another XML for XSL transformation?

An XML document contains another XML element, which is wrapped in CDATA.

How can the wrapped XML be used for XSL and XSL-FO transformation (version 1)?

Upvotes: 3

Views: 798

Answers (2)

mzjn
mzjn

Reputation: 50947

This is not possible with standard XSLT 1.0 or 2.0, in a single transformation.

It can be done using Saxon 9 Professional Edition or Enterprise Edition. These products have a saxon:parse() extension function. Or use the XPath 3.0 parse-xml() function, which is also supported by recent versions of Saxon PE/EE.


As @grtjn points out, it is possible to do it with a two-pass process. Stylesheet 1 turns the CDATA-wrapped text into parseable XML (using <xsl:value-of select="whatever" disable-output-escaping="yes"/>). Stylesheet 2 then processes the serialized result produced by stylesheet 1.

Upvotes: 1

grtjn
grtjn

Reputation: 20414

If you are willing to take multiple transformation steps then it is possible. Output the relevant section with disable-output-escaping to turn the escaped XML into valid XML. Process it in a subsequent step.

It does require the escaped XML to be well-formed. And some parsers require the intermediate result to be serialized (to disk or else) first to make sure the escaped XML is properly unescaped before it enters the subsequent transformations.

Upvotes: 2

Related Questions