5

我正在使用 XSLT 转换,需要将一些数据放在CDATA部分中,并且该值存在于变量中。

查询:如何访问变量CDATA?下面给出的示例:

<xsl:attribute name ="attributeName">
<![CDATA[ 
  I need to access some variable here like
   *<xsl:value-of select ="$AnyVarible"/>* 
 ]]>
</xsl:attribute>

如何在 中使用 varibale CDATA?注意:我不能使用 -->&lt;![CDATA[<xsl:value-of select ="$AnyVarible"/>]]&gt; 在此先感谢。

4

3 回答 3

7

我得到了解决方案...仅供大家参考...

<xsl:text
disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:value-of select ="$AnyVarible"/>
<xsl:text
disable-output-escaping="yes">]]&gt;</xsl:text>
于 2010-02-15T12:40:35.053 回答
3

CDATA 只是文本,就像任何其他元素内容一样......

但是使用该xsl:output元素,您应该能够使用该cdata-section-elements属性指定哪些元素将被写为 CDATA。

编辑:

既然有一个有效的样本,我猜你的意思是:

<xsl:attribute name ="attributeName">
<![CDATA[ 
   I need to access some variable here like
   *]]><xsl:value-of select ="$AnyVarible"/><![CDATA[* 
]]>
</xsl:attribute>
于 2010-02-15T10:48:09.747 回答
3

如果要在输出中包含 CDATA 部分,则应使用 xsl:output 的 cdata-section-elements 属性。这是元素名称的列表。任何此类元素的文本内容都将包含在 CDATA 中。

<xsl:output cdata-section-elements ="foo" />

<foo>
    <xsl:value-of select="$bar' />
</foo>
于 2010-02-15T13:54:02.300 回答