如何使用xslt保存< br />来转换xml标签在文本中 [英] how to transform xml with xslt preserving <br /> tags in a text

查看:100
本文介绍了如何使用xslt保存< br />来转换xml标签在文本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换(使用jquery.xslt.js)xml以保留文本节点中的标签。
Xml看起来像:

 < example> 
< text>
一些带有< br />的文字和< img src =source/>然后是文字....
< / example>

我想要:

 < div class =example> 
< p>一些带有< br />的文字和< img src =source/>然后是文字....< / p>
< / div>

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

 一些带有文字的文字.... 

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

 一些带有文字的文字....< br /> < img src =source/> 

是否有任何方法可以精确地重写标记内容?



 < xsl:template match; 

= /示例/文本 >
< div class =example>
< p>
< xsl:copy-of select =@ * | node()/>
< / p>
< / div>
< / xsl:template>


I want to transform (with jquery.xslt.js) xml to be preserving tags in text nodes. Xml looks like:

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

I want to have:

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

If I use <xsl:value-of select="."/> I'll get

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

If I add <xsl:apply-templates /> I'll get

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

Is there any way to exact rewrite content of tag?

解决方案

Try something like this:

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

这篇关于如何使用xslt保存&lt; br /&gt;来转换xml标签在文本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆