嘿,我有一个节点 ,其中包含一条消息,例如
string1
字符串2
刺3
但是,当它渲染时,它会渲染所有一行,我如何将所有 \n 替换为
's。
我试过了
但我收到这个错误
加载样式表时出错:XSLT/XPath 函数无效。
我该怎么做呢?
在您要处理的字符串上调用此模板:
<xsl:template name="break">
<xsl:param name="text" select="string(.)"/>
<xsl:choose>
<xsl:when test="contains($text, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<br/>
<xsl:call-template name="break">
<xsl:with-param
name="text"
select="substring-after($text, '
')"
/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
像这样(它将在当前节点上工作):
<xsl:template match="msg">
<xsl:call-template name="break" />
</xsl:template>
或者像这样显式传递参数:
<xsl:template match="someElement">
<xsl:call-template name="break">
<xsl:with-param name="text" select="msg" />
</xsl:call-template>
</xsl:template>
我认为您正在使用XSLT 1.0 处理器,而replace() 是XSLT/XPath 2.0 中引入的函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)