2011-05-31 58 views
0

我試圖用相應的XSLT樣式表創建一個XML文件。一切形式的作品不錯,但......用XSLT格式化的XML中的XHTML文本

...我輸出節點包含XHTML文本中的他們,就像這樣:

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
    <snippet id="user_surname"> 
     <content> 
      <h1>Some title here</h1> 
      <p>Blah blah blah...</p> 
     </content> 
    </snippet> 
    ... 
</root> 

下面是相應的XSLT樣式表:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
    <html> 
    <body> 
    <xsl:for-each select="root/snippet"> 
     <div> 
     <xsl:value-of select="content" disable-output-escaping="yes" /> 
     </div> 
    </xsl:for-each> 
    </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

我遇到的問題是,h1和p標籤不是作爲h1和p標籤打印的,而是作爲沒有標籤的純文本打印的。

如何讓我的XSLT樣式表按原樣打印這些標籤?我嘗試在CDATA標籤中打包,但似乎沒有幫助。

在此先感謝!

回答

2

嘗試xsl:copy-of而不是xsl:value-of。這應該給你的節點,而不是節點的文字。

+0

非常好!這工作100%!謝謝! – 2011-05-31 15:26:28

+1

@ josef.van.niekerk退房http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – timbooo 2011-05-31 15:34:06