递归XSLT模板未替换所有的字符



我已经在下面创建了此XSLT模板,以通过转换为HTML页面的文本块来解析。该模板用于多个位置,但是,它并未成功地转换我一直指定的字符。一个例子如下:

我想要"两个"有"帮助",然后继续看起来"四",但我发现的只是"空虚"。

结果是:我想要"两个"有"帮助",我继续看",但我发现的只是"空虚"。

有什么想法吗?

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

如果您想到表单的字符串

aaa &#8221; bbb &#8220; ccc

有两个明显的解决方案:(1)检查字符串包含特殊字符的情况,然后处理出现的第一个字符;或(2)对每个字符的字符串进行一次通过。(要么将模板分为两个模板,要么指定要在参数中寻找的字符。)

最新更新