Possiedo un XSLT che corrisponde a determinati attributi e li inserisce in uno spazio dei nomi diverso. Ecco una versione semplificata:Il motore Safari XSLT perde lo spazio dei nomi sugli attributi
<?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>
Ecco qualche esempio di ingresso:
<?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>
E qui è il risultato atteso:
<?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>
Questo funziona bene su Chrome, Firefox, IE 9 + e Android. Tuttavia su Safari, ottengo il seguente output, invece:
<?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>
Si noti che lo spazio dei nomi dichiarazioni sono corretti, ma gli attributi mancano il prefisso dello spazio dei nomi desiderato.
Tutto questo codice è in un github project, che è costruito da TravisCI e utilizza Sauce Labs per testare su diverse combinazioni browser/OS.
Posso fare qualcosa di diverso con il mio XSLT che sarebbe un modo più corretto per farlo, che potrebbe funzionare su tutti i motori? O è solo un bug in Safari? Qualsiasi idea per soluzioni alternative sarebbe molto apprezzata.
Qual è il risultato di Safari se si applica solo il modello di identità? L'output è identico/equivalente al documento XML di origine? Se l'output è corretto, cosa succede quando aggiungi un modello di eliminazione (con corpo vuoto) che corrisponde a qualsiasi attributo con nome-locale() che inizia con "test-"? Come posso eseguire una trasformazione XSLT con Safari o semplicemente con il suo motore XSLT? –
Stai facendo la trasformazione tramite qualche javascript, o stai aprendo il documento sorgente con il xslt associato usando '' – Flynn1179
Sembra funzionare bene in Safari 5.1.7 (7534.57.2) per Windows (x86). Che versione stai usando? – Flynn1179