Subject: Re: [xsl] Removing namespaces without escaping CDATA??? From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Tue, 10 Apr 2007 08:27:15 +0530 |
Hmm, not really an improvement, but when things "cannot be done" and when "things" cover a rather unusual request, I tend to try a rather unusual approach to solving it. If you want this, really, you don't need any d-o-e on elements, or implementation specific extension attributes. If you'd feel comfortable with using functions or call-template to achieve this goal, here's how, in plain portable XSLT 2.0 syntax (it is fairly straightforward):
<xsl:output use-character-maps="cdata" />
<xsl:character-map name="cdata"> <xsl:output-character character="" string="<![CDATA["/> <xsl:output-character character="" string="]]>"/> <xsl:output-character character="" string="<"/> <xsl:output-character character="" string="&"/> </xsl:character-map>
<xsl:template match="/"> <xsl:copy-of select="f:make-cdata('my-cdata', 'less-then < and ampersand: &')" /> </xsl:template>
<xsl:function name="f:make-cdata"> <xsl:param name="elem-name" /> <xsl:param name="content" /> <xsl:element name="{$elem-name}"> <xsl:text></xsl:text> <xsl:sequence select="replace(replace($content, '<', ''), '&', '')" /> <xsl:text></xsl:text> </xsl:element> </xsl:function>
<!-- output of the above --> <my-cdata><![CDATA[less-then < and ampersand: &]]></my-cdata>
Not that I consider this good coding, but it offers a solution to your request (having control on which elements receive 'CDATA treatment'). I just want to show you that you can get it any way you'd like with the current possibilities of XSLT/XPath 2.0. Use xsl:output if the elements are static, use xsl:result-document if they are dynamic, use the above approach if you want full control.
I know, in your post you say you want to give some kind of xpath or similar that points to the elements that need be escaped. This is most easiest achieved with either a micro-pipeline (take your whole output and process it again using the above function, but only for the required elements) or an extra cycle.
Cheers, -- Abel Braaksma http://www.nuntia.nl
PS: not that with xsl:result-document all attributes are AVTs, _except_ use-character-maps (taking multiple qnames), which means that you have to choose your character mappings carefully to prevent collisions.
-- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Removing namespaces witho, Abel Braaksma | Thread | Re: [xsl] Removing namespaces witho, Colin Paul Adams |
[xsl] XSLT 2.0 contains question, David Carver | Date | [xsl] Altsoft Xml2PDF 2007 is avail, Stanislav Sobolevsky |
Month |