Hans
Hans

Reputation: 71

Outputting CDATA in XQuery

How would I, using XQuery, transform

<author>John Smith</author>

to

<author><![CDATA[John Smith]]></author>

?

Also, how would I transform

<content>&lt;p&gt;&lt;em&gt;Hello&lt;/em&gt;&lt;/p&gt;</content>

to

<content><![CDATA[<p><em>Hello</em></p>]]></content>

?

If it matters, I am using XSLPalette.app.

Upvotes: 2

Views: 5283

Answers (2)

Hans
Hans

Reputation: 71

Solution:

declare namespace saxon="http://saxon.sf.net/";
declare option saxon:output "cdata-section-elements=content";

Thanks to Jim Garrison for inspiring me to search the Saxon documentation a little more carefully.

Upvotes: 1

Jim Garrison
Jim Garrison

Reputation: 86754

XSLPalette seems to use Saxon under the covers, so it should support the cdata-section-elements option on xsl:output. See http://www.w3.org/TR/xslt#output for details.

Essentially, if the underlying XSLT processor supports it, you can code

<xsl:output cdata-section-elements="name1 name2 ... etc"/>

The value of cdata-section-elements is a space-separated list of tag names for which child text nodes are to be output as CDATA sections.

I'll be curious to know if this works with XSLPalette.

Upvotes: 1

Related Questions