This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: CDATA in XML->XML transformation


> right now i got
>
>    <xsl:template match="Action">
>       <solution><xsl:apply-templates select="text()|i|b" /></solution>
>    </xsl:template>
>
> which produces an output like
>
>    <solution>this is a <i>nice</i> test</solution>
>
> but now i need the output to be a CDATA section, as i don't want the
> <i></i> part being parsed further, eg the output must look like
>
>    <solution><![CDATA[this is a <i>nice</i> test]]></solution>
>

You can get CDATA sections in the output using <xsl:output
cdata-section-elements="..."/>.

But this isn't the whole answer. In your example, you have generated
<i>nice</i> as an element node. But if you want to produce <![CDATA[this is
a <i>nice</i> test]]>, then the angle brackets within the CDATA must be
generated as text characters, not as markup - the whole point of CDATA is to
say that characters such as "<" are not to be regarded as markup. So instead
of producing <i>nice</i> as an element, you will have to generate the "tags"
(i.e., the things that look like tags, though they aren't) by hand, e.g. as:

<![CDATA[<i>]]><xsl:value-of select="."/><![CDATA[</i>]]>

I am at a loss to know why you want to use CDATA in this situation, as it
means your nicely marked-up text can no longer be processed as XML, but no
doubt you have your reasons.

Mike Kay


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]