You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSL标签无法显示撇号字符,disable-output-escaping无效求助

问题分析与解决方法

你的问题核心在于xsl:copy-of的特性和disable-output-escaping(DOE)的适用场景:

  • xsl:copy-of的作用是原样复制节点或值,如果变量$value-of-variable本身存储的就是转义后的字符串My dog's big,copy-of会直接输出这个字符串,DOE对它的文本内容通常不生效——多数XSLT处理器的DOE仅支持xsl:value-of、xsl:text这类直接生成文本输出的指令。
  • 你需要将转义的'还原为',可以通过以下几种方式解决:

解决方案1:改用xsl:value-of + DOE

把xsl:copy-of替换为xsl:value-of,并保留disable-output-escaping="yes":

<xsl:value-of select="$value-of-variable" disable-output-escaping="yes"/>

注意:DOE的支持取决于具体XSLT处理器,部分XSLT 2.0+的实现可能限制DOE的使用场景。

解决方案2:字符串替换(兼容性更强)

如果你的XSLT版本是2.0及以上,推荐使用replace()函数直接替换转义实体,无需依赖DOE:

<xsl:value-of select="replace($value-of-variable, '&amp;apos;', '''')"/>

如果是XSLT 1.0,可通过递归模板实现字符串替换:

<xsl:template name="unescape-apostrophe">
  <xsl:param name="text"/>
  <xsl:choose>
    <xsl:when test="contains($text, '&amp;apos;')">
      <xsl:value-of select="substring-before($text, '&amp;apos;')"/>
      <xsl:text>'</xsl:text>
      <xsl:call-template name="unescape-apostrophe">
        <xsl:with-param name="text" select="substring-after($text, '&amp;apos;')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- 调用模板 -->
<xsl:call-template name="unescape-apostrophe">
  <xsl:with-param name="text" select="$value-of-variable"/>
</xsl:call-template>

额外提示

先确认变量$value-of-variable的类型:如果它是XML节点(而非纯字符串),且节点内文本已转义,需要先获取节点的字符串值再处理。

内容的提问来源于stack exchange,提问作者robbt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:42:36