在網上尋找答案後,提出「幾乎」的解決方案......我決定將問題簡化爲一個非常簡單的案例。未使用的命名空間聲明出現在XSLT後
考慮下面的XML片段:
<me:root xmlns:me="http://stackoverflow.com/xml"
xmlns="http://www.w3.org/1999/xhtml">
<me:element>
<p>Some HTML code here.</p>
</me:element>
</me:root>
注意,p
元素是XHTML的命名空間,這是該文檔的默認之一。
現在考慮下面的簡單樣式表。我想創建一個XHTML文檔,其內容爲me:element
。
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:me="http://stackoverflow.com/xml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="me">
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
</head>
<body>
<xsl:copy-of select="me:root/me:element/node()"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
注意,我包括exclude-result-prefixes
...但是看看我得到:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
</head>
<body>
<p xmlns:me="http://stackoverflow.com/xml">Some HTML code here.</p>
</body>
</html>
,什麼是我瘋狂這是爲什麼,哦,爲什麼xmlns:me
出現p
元素裏面?
無論我嘗試了什麼,我都無法讓東西上班。我有一個奇怪的感覺,問題是我的xsl:copy-of
聲明。
好問題(+1)。查看我的答案以獲得詳細的解釋和完整的解決方案。 – 2010-09-30 04:44:38