Re: [xsl] Removing namespaces without escaping CDATA???

Subject: Re: [xsl] Removing namespaces without escaping CDATA???
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 09 Apr 2007 18:58:59 +0200
David Carlisle wrote:

Also, specifying cdata-section-elements here, <xsl:output
cdata-section-elements="qnames" /> seem to have a shortcoming, that
it's too global (as I said earlier). Do you agree to this point?

It has to be global or you have to be able to somehow annotate individual elements in the result tree but teh need to annotate teh result tree leads to all sorts of problems if teh result tree is not immediately serialised by XSLT but passed to some other process, which is why disable-output-escaping is such a problem. There is no standard way of passing a result tree to some other process and recording places where doe is used.

You can 'annotate' the result tree in XSLT 2.0, though possibly not as conveniently as Mukul Gandhi requests. The attribute 'cdata-section-elements' is an AVT in the xsl:result-document element and it must result in one or more qnames. But this requires redesigning your stylesheets in such a way that you use xsl:result-document, instead of xsl:output (but that should not be too hard if it is 'global'). This:


<xsl:variable name="my-cdata" select="'as-cdata'" />
<xsl:result-document cdata-section-elements="{$my-cdata}" href="analyze.xml">
<as-cdata>
<xsl:text>Has some text</xsl:text>
<not-cdata />
</as-cdata>
<as-cdata>Less then is: &lt;, ampersand is: &amp;</as-cdata>
</xsl:result-document>



results in the following output (Saxon 8.9):


<as-cdata><![CDATA[Has some text]]><not-cdata/>
</as-cdata>
<as-cdata><![CDATA[Less then is: <, ampersand is: &]]></as-cdata>


You have all freedom, the only drawback compared to your d-o-e-like approach is that you will have to determine the contents of the AVT beforehand, instead of per element. But as Michael and David already pointed out, would you really want to do this?


Cheers,
-- Abel

PS: it is probably better to declare $my-cdata as 'xs:Qname' or 'xs:Qname*'.

Current Thread