Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

xml - How to use <![CDATA[]]> in XSLT?

I have use in XSLT variable look like:

<xsl:variable name="ShortDescription" select="str[@name = 'ShortDescription']"/>
<!--Short Description field-->
       <xsl:if test="$ShortDescription !=''">

        <shortdescription><![CDATA[ <xsl:value-of select="$ShortDescription" disable-output-escaping="no"/> ]]></shortdescription>

       </xsl:if>

But its display as a text not a value of $ShortDescription variable and output look like:

<shortdescription>
&lt;xsl:value-of select="$ShortDescription" disable-output-escaping="no"/&gt;
</shortdescription>

expected output look like:

<shortdescription>
<![CDATA[Maximum Power: 520 W<br/>+12V Rails: Dual<br/>]]>
</shortdescription>

How to use <![CDATA[]]> in XSLT?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

XSLT is XML so of course you can use a CDATA section in XSLT code, as you have done. However it rather seems you want the output of the XSLT code to contain a CDATA section for the shortdescription contents, in that case you need

<xsl:output method="xml" cdata-section-elements="shortdescription"/>

And the XSLT would simply stay as

<shortdescription><xsl:value-of select="$ShortDescription"/></shortdescription>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...