XSL:避免将命名空间定义导出到生成的XML文档 [英] XSL: Avoid exporting namespace defintions to resulting XML documents
问题描述
我想从一些XML文件中获取数据并将其转换为新的XML文档。但是,我不希望XSLT中的命名空间的定义发生在结果文档中。
I'd like to take data from some XML files and transform them into a new XML document. However, I do not want the definition of a namespace in the XSLT to occur in the result document.
换句话说:
来源:
<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进行转换。
I am using msxsl for the transformation.
推荐答案
您可以使用 xsl:stylesheet $ c的
exclude-result-prefixes
属性$ c>元素来抑制输出文档中的命名空间:
You can use the exclude-result-prefixes
attribute of the xsl:stylesheet
element to suppress namespaces from the output document:
<?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>
要从输出文档中抑制多个命名空间,请指定以空格分隔:
To suppress multiple namespaces from the output document specify them separated by whitespace:
exclude-result-prefixes="ns1 ns2 ns3"
从 XSLT规范:
当样式表仅使用命名空间声明来解决源代码树时,在exclude-result-prefixes属性中指定前缀将避免多余结果树中的命名空间声明。
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.
这篇关于XSL:避免将命名空间定义导出到生成的XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!