Re: [xsl] Serializing elements in CDATA, based on an attribute value

Subject: Re: [xsl] Serializing elements in CDATA, based on an attribute value
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 Apr 2017 16:14:02 -0000
The only way of getting CDATA sections output by the serializer using standard
XSLT capabilities, or using standard Saxon capabilities, is the
cdata-section-elements property, and that is driven entirely by element name.
For finer-grained control you'll have to do something else.

One approach would be output the relevant elements with a different name, e.g.
METADATA, and specify cdata-section-elements="METADATA". You can then replace
< METADATA and </METADATA by <metadata and </metadata by post-processing the
serialized output at the text level.

If you're feeling more adventurous it's not difficult to inject a custom
processing step into the Saxon serialization pipeline by nominating your own
subclass of Saxon's SerializerFactory.

Michael Kay

> On 12 Apr 2017, at 14:23, cmarchand@xxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> Hello,
> In a document, I write many tags of metadata. Part of them, based on @code
value (debug & info), MUST be serialized with a CDATA content.
> With this input :
> <metadata code="dummy">Standard serialization</metadata>
> <metadata code="debug">C-Data serialization</metadata>
> <metadata code="foe">Standard serialization</metadata>
> <metadata code="info">C-Data serialization</metadata>
> I do expect this :
> <metadata code="dummy">Standard serialization</metadata>
> <metadata code="debug"><![CDATA[C-Data serialization]]></metadata>
> <metadata code="foe">Standard serialization</metadata>
> <metadata code="info"><![CDATA[C-Data serialization]]></metadata>
> What must I define as serialization parameters to get this ? I use Saxon
9.7EE, so I can use Saxon extensions.
> Thanks in advance,
> Christophe

Current Thread