特定の属性と一致するXSLTがあり、別の名前空間に配置しています。ここでは単純化されたバージョンである:ここではSafari 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>
これは、クロム、Firefoxの、IE 9で正常に動作します+、アンドロイド。しかし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>
お知らせを名前空間宣言は正しいですが、属性が必要な名前空間接頭辞が欠けていること。
このコードはすべて、TravisCIによって構築されたgithub projectにあり、異なるブラウザ/ OSコンボでテストするためにSauce Labsを使用しています。
私のXSLTとは違ったやり方でこれを実現するより正しい方法があります。これはすべてのエンジンで動作するのでしょうか?これはSafariのバグですか?回避策のアイデアは非常に高く評価されます。
アイデンティティテンプレートだけを適用するとSafariの結果はどうなりますか?出力はソースXML文書と同じですか/同等ですか?出力が正しい場合、 "test-"で始まるlocal-name()で任意の属性に一致する削除テンプレート(空の本文)を追加するとどうなりますか? SafariまたはXSLTエンジンだけでXSLT変換を実行するにはどうすればよいですか? –
JavaScriptを使って変換を行っているのですか? '<?xml-stylesheet ..?>を使ってxsltを関連付けたソース文書を開いていますか? – Flynn1179
Safari 5.1.7(7534.57.2)for Windows (x86)。どのバージョンを使用していますか? – Flynn1179