This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
merging of text-nodes and CDATA
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] merging of text-nodes and CDATA
- From: Klaus-Georg Adams <Klaus-Georg dot Adams at sap dot com>
- Date: 05 Sep 2001 16:10:54 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi,
given the following XML fragment:
<strval>
<![CDATA[bla ]]>
</strval>
and the famous identity transformation from the XSL spec:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
indent="yes"
cdata-section-elements="strval"
/>
<xsl:strip-space elements="strval"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I get the following back:
<strval><![CDATA[
bla
]]></strval>
This is with Xalan-J and sablotron. My understanding is that the
parser generates three text nodes:
- one containing the first '\n' after <strval> and a couple of spaces,
- one containing 'bla '
- one with the closing '\n'
These three are merged in one and than whitespace stripping is
performed.
I'd like this order to be reversed: first strip whitespace and than
only merge the textnodes. The result would thus be:
<strval><![CDATA[bla ]]></strval>
, as the first and last node only contain whitespace. This, btw, is
how the XML parser in the application interprets the source fragment.
Note the space after bla, which I don't want to loose. No
normalize_text(), which will eat that space as well.
Now my questions:
- Is the order of merge/strip specified somewhere in the XML or XSL
specifications?
- if not, does somebody have an XSL processor which does it my way?
- can I get the behaviour I want with XSL?
Thanks for your help,
Klaus-Georg Adams
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list