RE: [xsl] data vs. xml

Subject: RE: [xsl] data vs. xml
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Thu, 3 Apr 2003 11:45:25 -0600
bix xslt wrote:

> All,
> 
> Is there a way to identify a node as containing cdata?
> 
> eg.
> <node>
> <dataNotNewXMLTag1, dataVala, dataValb, moreData, ...>
> <dataNotNewXMLTag2, dataVala, dataValb, moreData, ...>
> <dataNotNewXMLTag3, dataVala, dataValb, moreData, ...>
> <dataNotNewXMLTag4, dataVala, dataValb, moreData, ...>
> <dataNotNewXMLTag5, dataVala, dataValb, moreData, ...>
> </node>

I'm assuming that your actual XML source document did not look like the
above; instead it has CDATA sections, as you were implying.
Otherwise, you would immediately get an error from the XSL processor
saying that the source document is not well-formed XML.

> I want to write a simple xsl script that would translate the 
> above into 
> something more manageable for XSLT processing:
> 
> eg.
> <node>
> &lt;dataNotNewXMLTag1, dataVala, dataValb, moreData, ...&gt;
> &lt;dataNotNewXMLTag2, dataVala, dataValb, moreData, ...&gt;
> &lt;dataNotNewXMLTag3, dataVala, dataValb, moreData, ...&gt;
> &lt;dataNotNewXMLTag4, dataVala, dataValb, moreData, ...&gt;
> &lt;dataNotNewXMLTag5, dataVala, dataValb, moreData, ...&gt;
> </node>
> 
> I had tried something like this:
> <x:template match="node">
>   <x:element name="node">
>      <x:variable
>          name="start"
>          select="translate(exslt:node-set(.),"<","&lt;")">
>      <x:variable
>          name="end"
>          select="translate(exslt:node-set($start),"<","&lt;")">
>      <x:copy-of select="exslt:node-set($end)"/>
>   </x:element>
> </x:template>
> 
> But that really didn't work well, producing an error.

What was the error?

One thing that jumps out is that the quotes inside the select=""
string need to be apostrophes instead of double quotes.

I don't understand why you're using node-set inside of translate()
either; you just want the string-value of the current node (<node>),
i.e. the value of its text child.  Right?

As for whether it's necessary to do the translation at all --
I wouldn't think so.  If you use <xsl:output method="xml">,
XSL should escape anything that needs escaping in the output,
including <.  So an ordinary identity transformation
(see http://www.dpawson.co.uk/xsl/sect2/identity.html)
should do what you want, taking in CDATA sections and outputing
escaped data.

Somebody please correct if I'm mistaken...

Lars


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread