xml – Safari XSLT引擎在属性上丢失命名空间
发布时间:2020-12-16 07:42:54 所属栏目:百科 来源:网络整理
导读:我有一个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:o
我有一个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”上设置所需的命名空间.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |