我正在使用 Sax 转换器工厂对大量 xsd 文件进行 XSLT 转换,因此 xslt 的特定行如下。
<xsl:result-document href="{$fileName}"
doctype-public="-//OASIS//DTD DITA Reference//EN"
doctype-system="reference.dtd">
<reference id="{$guid}" xml:lang="EN-US" outputclass="landscape">
<title>
<xsl:value-of select="$typeName"/>
</title>
<abstract>....
引用标记是文档的根,但结果有一个不需要的 xmlns:xsd 属性,如下所示。
...<reference xmlns:xsd="http://www.w3.org/2001/XMLSchema"
id="RANDOM-ID".....
此附加属性会导致使用转换后的 xml 的解析器出现问题。
这是 XSLT 或 SAXON api 的问题,我该如何避免?
最佳答案
默认情况下,xsl 转换会将样式表中定义的命名空间复制到输出文档。您可以通过指定 exclude-result-prefixes
排除此命名空间。在 xsl:stylesheet
或 reference
值为“xsd”的元素。
这是xslt sepcification的相关部分:
The created element node will also have a copy of the namespace nodes that were present on the element node in the stylesheet (...)
A namespace URI is designated as an excluded namespace by using an exclude-result-prefixes attribute on an xsl:stylesheet element or an xsl:exclude-result-prefixes attribute on a literal result element. The value of both these attributes is a whitespace-separated list of namespace prefixes.
关于xslt - Saxon Transformerfactory 放置不需要的 xmlns :xsd ="http://www.w3.org/2001/XMLSchema" in transformer output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5258660/