我正在进行XSL 1.0转换,以在Firefox中显示XML时获取HTML可视化。 我在原来的XML,我有这样XSL中的特殊字符
é è ‘...
字符我需要将它们转换成
é, è, ‘...
我已经使用这个模板:
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
呼唤每个特殊字符(这里例如& egrave;):
<xsl:variable name="newtext">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$originaltext" />
<xsl:with-param name="replace" select="'&egrave;'" />
<xsl:with-param name="by" select="'è'" />
</xsl:call-template>
</xsl:variable>
是否有解决方案,我可以直接将&
替换为&,例如,无需为每个我希望存在的特殊字符调用替换模板?
我能想到的唯一改进就是不用切换到XSLT 2。0,将在您的样式表中创建特殊字符的“表”,并循环遍历它,为前一次调用的输出中的每个“行”调用'string-replace-all'。不过,涉及扩展功能的选项可能更好,例如http://exslt.org/dyn/functions/evaluate/index.html,具体取决于您使用的XSLT处理器。 – LarsH
我需要使用Firefox直接显示带有其转换的XML,而无需特殊的预处理器。 –
好吧,既然Firefox是你的环境,为什么不让你的样式表输出一些Javascript。在加载页面后,JS代码可以通过'&'替代'&'。我不确定它会起作用,但值得一试。 – LarsH