【问题标题】:how to replace character '#' with newline in xslt?如何在xslt中用换行符替换字符'#'?
【发布时间】:2016-05-29 20:51:14
【问题描述】:

我在 xml 中得到一个字符串,类似于 hello world#how r u#blahblah#blah。 我需要用换行符替换每个#。所以在html中它应该显示为

hello world
how r u
blahblah
blah

我试过translate

<xsl:value-of select="translate('hello world#howru#blahblah#blah','#','&#xa;&#xd;')" />

它可以编译,但不能在 IE 和 FIREFOX 中运行。

【问题讨论】:

  • 我试过了,不行
  • 浏览器需要&lt;br/&gt; 来创建新行。您不能为此使用 translate() 函数,您需要一个递归命名模板 - 参见,例如:stackoverflow.com/questions/24995282/…

标签: xml xslt newline


【解决方案1】:

在 XSLT 2.0 中,

<xsl:analyze-string select="$in" regex="#">
  <xsl:matching-substring><br/></xsl:matching-substring>
  <xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring>
</xsl:analyze-string>

【讨论】:

  • 不,我没有使用 XSLT2.0。谢谢你的回答。
  • 在没有语法指导的编辑器的情况下工作是多么的失败!现已修复。
猜你喜欢
  • 1970-01-01
  • 2011-03-05
  • 2013-05-10
  • 2010-09-09
  • 2010-10-11
  • 2020-08-11
相关资源
最近更新 更多