2015-10-21 20 views
10

特定の属性と一致する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のバグですか?回避策のアイデアは非常に高く評価されます。

+0

アイデンティティテンプレートだけを適用するとSafariの結果はどうなりますか?出力はソースXML文書と同じですか/同等ですか?出力が正しい場合、 "test-"で始まるlocal-name()で任意の属性に一致する削除テンプレート(空の本文)を追加するとどうなりますか? SafariまたはXSLTエンジンだけでXSLT変換を実行するにはどうすればよいですか? –

+0

JavaScriptを使って変換を行っているのですか? '<?xml-stylesheet ..?>を使ってxsltを関連付けたソース文書を開いていますか? – Flynn1179

+0

Safari 5.1.7(7534.57.2)for Windows (x86)。どのバージョンを使用していますか? – Flynn1179

答えて

1

これとは逆の証拠はありませんが、これはSafariのバグのようです。私はこれをAppleに報告したが(rdar://23207226)、これまで何も聞いていない。

利用可能な回避策は、XSLTを他のエンジン(サーバー側、またはサードパーティ製のJavaScriptエンジン)で実行することです。

1

これはバグだと思います。あなたの周りの仕事は、あなたが望む名前空間をxsl:attribute namespace="urn:test:ns2"に設定しようとする可能性があります。

+0

これを試してみても差はありません。私はそれを含めるために私の質問を更新しました。しかし、提案をありがとう。私はこれがSafariのバグのように見えることに同意します。 – murrayju

+0

名前空間宣言 'xmlns:ns2 =" urn:test:ns2 "'を 'xsl:attribute'に置くとどうなりますか? –

+0

また、違いはありません。しかし、うまくいきませんでした。それは冗長でした。 – murrayju

関連する問題