2010-04-24 21 views
0

我想轉換(使用jquery.xslt.js)xml以保留文本節點中的標記。 XML是什麼樣子:如何轉換xml保留<br />在文本中的標記

<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" />" 

是否有任何方法來確切重寫標籤的內容?

回答

1

嘗試這樣:

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