我已经在下面创建了此XSLT模板,以通过转换为HTML页面的文本块来解析。该模板用于多个位置,但是,它并未成功地转换我一直指定的字符。一个例子如下:
我想要"两个"有"帮助",然后继续看起来"四",但我发现的只是"空虚"。
结果是:我想要"两个"有"帮助",我继续看",但我发现的只是"空虚"。
有什么想法吗?
<xsl:template name="PreserveQuotations">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text,'“')">
<xsl:value-of select="substring-before($text,'“')"/>
<xsl:text>"</xsl:text>
<xsl:call-template name="PreserveQuotations">
<xsl:with-param name="text">
<xsl:value-of select="substring-after($text,'“')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text,'”')">
<xsl:value-of select="substring-before($text,'”')"/>
<xsl:text>"</xsl:text>
<xsl:call-template name="PreserveQuotations">
<xsl:with-param name="text">
<xsl:value-of select="substring-after($text,'”')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
如果您想到表单的字符串
aaa ” bbb “ ccc
有两个明显的解决方案:(1)检查字符串包含特殊字符的情况,然后处理出现的第一个字符;或(2)对每个字符的字符串进行一次通过。(要么将模板分为两个模板,要么指定要在参数中寻找的字符。)