我在XSLT变量中使用的样子如下:
<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>
Run Code Online (Sandbox Code Playgroud)
但它显示为文本而不是$ShortDescription变量和输出的值如下所示:
<shortdescription>
<xsl:value-of select="$ShortDescription" disable-output-escaping="no"/>
</shortdescription>
Run Code Online (Sandbox Code Playgroud)
预期输出看起来像:
<shortdescription>
<![CDATA[Maximum Power: 520 W<br/>+12V Rails: Dual<br/>]]>
</shortdescription>
Run Code Online (Sandbox Code Playgroud)
如何<![CDATA[]]>在XSLT中使用?
XSLT是XML,所以你当然可以在XSLT代码中使用CDATA部分.但是,您似乎希望XSLT代码的输出包含内容的CDATA部分shortdescription,在这种情况下您需要
<xsl:output method="xml" cdata-section-elements="shortdescription"/>
Run Code Online (Sandbox Code Playgroud)
而XSLT只会保持原样
<shortdescription><xsl:value-of select="$ShortDescription"/></shortdescription>
Run Code Online (Sandbox Code Playgroud)