在网上寻找答案后,提出“几乎”的解决方案......我决定将问题简化为一个非常简单的案例。未使用的命名空间声明出现在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