xslt仅在一个节点中替换\ n?

时间:2009-02-18 14:23:14

标签: xslt

嘿,我有一个节点< msg>其中包含

等消息
  

字符串1
  string 2   sting3

但是当它渲染时,它会呈现所有一行,如何用< br />替换所有\ n。

我试过

  

< xsl:value-of select ='replace(msg,“& #xA;”,“< br />”)'/>

但我收到此错误

  

加载样式表时出错:无效的XSLT / XPath函数。

我该怎么做?

3 个答案:

答案 0 :(得分:19)

在您要处理的字符串上调用此模板:

<xsl:template name="break">
  <xsl:param name="text" select="string(.)"/>
  <xsl:choose>
    <xsl:when test="contains($text, '&#xa;')">
      <xsl:value-of select="substring-before($text, '&#xa;')"/>
      <br/>
      <xsl:call-template name="break">
        <xsl:with-param 
          name="text" 
          select="substring-after($text, '&#xa;')"
        />
      </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引入的函数。

答案 1 :(得分:-1)

您也可以通过简单的HTML标记实现这一点,
在你的msg之前试试这个TodayCount标签,然后在msg。

之后关闭它
Jayakumar Kulkarni (Consultant) :
Remark

Jayakumar Kulkarni :
Rematr 01

Jayakumar Kulkarni :
comment

答案 2 :(得分:-1)

&#13;
&#13;
<pre>
Jayakumar Kulkarni (Consultant) :
Rematr 01

Jayakumar Kulkarni (Consultant) :
3rd comment
</pre>
&#13;
&#13;
&#13;

试试以上标签

相关问题