XSL:避免将名称空间定义导出到生成的XML文档

我想从一些XML文件获取数据,并将它们转换为一个新的XML文档。但是,我不想在结果文档中出现XSLT中的命名空间的定义。

换一种说法:

资源:

<Namespace:Root xmlns:Namespace="http://www.something.com">

样式表:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:Namespace="http://www.something.com">

结果:

<resultRoot xmlns:Namespace="http://www.something.com">
<!--I don't want the Namespace deFinition above-->

我使用msxsl进行转换。

您可以使用xsl:stylesheet元素的exclude-result-prefixes属性禁止输出文档中的命名空间:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:Namespace="http://www.something.com"
         exclude-result-prefixes="Namespace">

</xsl:stylesheet>

要从输出文档中删除多个命名空间,请使用空格分隔它们:

exclude-result-prefixes="ns1 ns2 ns3"

XSLT specification

When a stylesheet uses a namespace declaration only for the purposes of addressing the source tree,specifying the prefix in the exclude-result-prefixes attribute will avoid superfluous namespace declarations in the result tree.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念