tags:

views:

404

answers:

2

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.

A: 

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.

Jim Garrison
Yes, that does work... with XSLT. I'm trying to achieve the same with XQuery.
Hans
The same cdata-section-elements option is available in the XQuery spec. You'll have to determine how XSLPalette specifies XQuery serialization parameters.
Jim Garrison
A: 

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.

Hans