2009-08-26 48 views

回答

1

XSLT將CDATA節作爲普通文本處理,因此您可以像處理文本節點一樣對待它們。請注意,XSLT不會將CDATA部分保留爲與周圍文本分開。因此,如果你有

<foo>bar <![CDATA[baz]]> qux</foo> 

源樹將

  • 文件
    • 元素:FOO
      • 文字: 「欄巴茲qux」
2

閱讀這篇文章 - CDATA Sections

摘要:在XSLT樣式表, CDATA節是純粹的實用 由具有逃避所有 的「<」等目標阻止你你'瞄準 是因爲正在將您的XML源中有 的東西直接複製到您的 HTML輸出中。 xsl:copy-of的元素 正是爲此設計的 的用途。 xsl:copy-of將給出您選擇的 的精確副本, 包括屬性和內容。

XML文檔。

<?xml version="1.0" encoding="iso-8859-1"?> 
<know> 
    <title/> 
    <topic title="" href=""> 
    <![CDATA[ 
     Text 
     ]]> 
    </p>  
    </topic> 
</know> 

xsl Document。

<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="know"> 
    <xsl:value-of select="title"/> 
    <xsl:for-each select="topic"> 
     <xsl:value-of select="@title"/> 
      <xsl:value-of select="." disable-output-escaping="yes"/> 
    </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 
相關問題