如何转换XML使用XSLT维护 在文本标签(how to transform xml with

2019-10-28 11:28发布

我想变换(与jquery.xslt.js)XML是在文本节点保存标签。 XML是什么样子:

<example>
   <text>
      Some text with <br /> and <img src="source" /> then text ....
   </text>
</example>

我希望有:

 <div class="example"> 
  <p>Some text with <br /> and <img src="source" /> then text ....</p> 
 </div>

如果我使用<xsl:value-of select="."/>我会得到

 "Some text with and then text ...."

如果我添加<xsl:apply-templates />我会得到

"Some text with and then text .... <br/><img src="source" />"

有没有什么办法来准确改写标签的内容?

Answer 1:

尝试是这样的:

<xsl:template match="/example/text">
  <div class="example">
    <p>
      <xsl:copy-of select="@* | node()"/>
    </p>
  </div>
</xsl:template>


文章来源: how to transform xml with xslt preserving
tags in a text