【问题标题】:how to transform xml with xslt preserving <br /> tags in a text如何使用 xslt 转换 xml,在文本中保留 <br /> 标签
【发布时间】:2010-04-24 16:02:11
【问题描述】:

我想将(使用 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>

如果我使用&lt;xsl:value-of select="."/&gt; 我会得到

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

如果我添加&lt;xsl:apply-templates /&gt; 我会得到

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

有什么方法可以精确重写标签的内容吗?

【问题讨论】:

    标签: jquery html xml xslt


    【解决方案1】:

    试试这样的:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 2017-12-25
      • 2013-01-17
      • 1970-01-01
      • 2013-08-08
      相关资源
      最近更新 更多