xml – Safari XSLT引擎在属性上丢失命名空间

我有一个XSLT匹配某些属性,并将它们放在不同的命名空间中.这是一个简化版本:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="urn:test:ns1"
    xmlns:ns2="urn:test:ns2">
    <xsl:output method="xml" indent="no" encoding="UTF-8"/>

    <!-- copy all nodes -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@*[starts-with(local-name(),'test-')]">
        <xsl:attribute name="ns2:{substring-after(local-name(),'-')}" namespace="urn:test:ns2">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

以下是一些示例输入:

<?xml version="1.0" encoding="UTF-8" ?>
<hello-world
    xmlns="urn:test:ns1"
    xmlns:ns3="urn:test:ns3"
    rootAttr="stays in implicit namespace"
    ns3:passMe="stays in the ns3 namespace"
    test-someRootAttr="goes into the ns2 namespace,pulls up ns declaration">
    <test
        defaultAttr="stays in implicit namespace"
        test-someAttr="goes into the ns2 namespace"
        ns3:namedAttr="stays in the ns3 namespace">
        Something
    </test>
    <ns3:cat
        defaultAttr="stays in the implicit namespace"
        test-catName="goes into the ns2 namespace"
        ns3:namedAttr="stays in the ns3 namespace">
        a cat
    </ns3:cat>
</hello-world>

这是预期的输出:

<?xml version="1.0" encoding="UTF-8" ?>
<hello-world
    xmlns="urn:test:ns1"
    xmlns:ns2="urn:test:ns2"
    xmlns:ns3="urn:test:ns3"
    rootAttr="stays in implicit namespace"
    ns3:passMe="stays in the ns3 namespace"
    ns2:someRootAttr="goes into the ns2 namespace,pulls up ns declaration">
    <test
        defaultAttr="stays in implicit namespace"
        ns2:someAttr="goes into the ns2 namespace"
        ns3:namedAttr="stays in the ns3 namespace">
        Something
    </test>
    <ns3:cat
        defaultAttr="stays in the implicit namespace"
        ns2:catName="goes into the ns2 namespace"
        ns3:namedAttr="stays in the ns3 namespace">
        a cat
    </ns3:cat>
</hello-world>

这可以在Chrome,Firefox,IE 9和Android上正常工作.但是在Safari中,我会得到以下输出:

<?xml version="1.0" encoding="UTF-8" ?>
<hello-world
    xmlns="urn:test:ns1"
    xmlns:ns3="urn:test:ns3"
    xmlns:ns2="urn:test:ns2"
    rootAttr="stays in implicit namespace"
    passMe="stays in the ns3 namespace"
    someRootAttr="goes into the ns2 namespace,pulls up ns declaration">
    <test
        defaultAttr="stays in implicit namespace" 
        someAttr="goes into the ns2 namespace" 
        namedAttr="stays in the ns3 namespace">
        Something
    </test>
    <ns3:cat
        defaultAttr="stays in the implicit namespace" 
        catName="goes into the ns2 namespace" 
        namedAttr="stays in the ns3 namespace">
        a cat
    </ns3:cat>
</hello-world>

请注意,命名空间声明是正确的,但属性缺少所需的命名空间前缀.

所有这些代码都是github project,它由TravisCI构建,并使用Sauce Labs在不同的浏览器/操作系统上进行测试.

我可以用XSLT做一些不同的事情,这将是一个更正确的方式来完成这一点,这可能适用于所有的引擎?还是这只是Safari中的一个bug?任何解决方法的想法将不胜感激.

我认为这是一个bug.作为一个工作,您可以尝试在xsl:attribute namespace =“urn:test:ns2”上设置所需的命名空间.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇