xsl-list
[Top] [All Lists]

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

2017-04-12 11:14:08
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
Saxonica

On 12 Apr 2017, at 14:23, cmarchand(_at_)oxiane(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>