【问题标题】:How to replace text defined in a given tag or element using xslt, xslt string replace如何使用 xslt、xslt 字符串替换替换给定标记或元素中定义的文本
【发布时间】:2011-03-02 19:03:21
【问题描述】:

请帮我完成这个 xslt 转换。

源 Xml

<xml>
 <test>This is a <bold>sample</bold> description. Please help me with a sample</text>
</xml>

预期输出:这是一个示例描述。请帮我提供样品

我只需要将 xml 标记的指定文本加粗即可。

谢谢

【问题讨论】:

  • 你想要什么样的输出格式? html ? rtf ? ps? ...
  • 好问题 (+1)。请参阅我的答案以获得完整的解决方案。

标签: string xslt replace


【解决方案1】:

这种转变

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="text">
   <p>
     <xsl:apply-templates/>
   </p>
 </xsl:template>

 <xsl:template match="bold">
   <b><xsl:apply-templates/></b>
 </xsl:template>
</xsl:stylesheet>

应用于提供的 XML 文档时

<xml>
 <text>This is a <bold>sample</bold> description. Please help me with a sample</text>
</xml>

在 HTML 中生成所需的结果

 <p>This is a <b>sample</b> description. Please help me with a sample</p>

【讨论】:

  • @m00sila:很高兴它有效。在这种情况下,您应该接受答案(单击必须显示在答案附近某处的复选标记)。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-05
  • 1970-01-01
  • 2021-10-10
  • 2017-01-11
  • 1970-01-01
  • 2021-07-19
相关资源
最近更新 更多