xslt - Saxon Transformerfactory 放置不需要的 xmlns :xsd ="http://www.w3.org/2001/XMLSchema" in transformer output

标签 xslt attributes namespaces saxon

我正在使用 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:stylesheetreference值为“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/

相关文章:

java - XSLT 中的页脚(xml-html-pdf 转换)

java - XSLT 处理递归深度

jquery - 为什么 jquery 验证插件的远程属性对我不起作用?

jsf-2 - 如何检查复合组件中是否存在可选属性

php - Psr-4 composer 自动加载自己的类 - 未找到

php - 从 PHP 文件生成并使用 XSLT 翻译的 XML 获取 PDF 输出

java - 在 Spring MVC 中实现 XSLT View

c# - 扩展枚举,矫枉过正?

typescript - tslint:不允许命名空间和模块

c++ - 通过 ADL 从另一个函数调用一个函数