Subject: Re: [xsl] Getting the root namespace from the input document|
From: "bryan rasmussen" <rasmussen.bryan@xxxxxxxxx>
Date: Tue, 6 Feb 2007 12:52:34 +0100
Okay I haven't gone and checked but I would expect that some processors would change the namespace to fit the copy-of namespace. At any rate what were the outputs like? Did you have an output from the processors that was illegal? If not, what did they do?
This seems like a useful transform to test a lot of processor outputs on actually. Cheers, Bryan Rasmussen
Michael Kay wrote:!
> There's also sometimes a theoretical risk that prefixes > will be changed because XSLT 1.0 permits it
Yes, it is what I thought about.
> but mainstream processors all do the decent thing in > straightforward cases.
And that is why I use it. But I'm not very comfortable with the use of this "observable behaviour" without knowing exactly how this happens (prefixes will be changed in particular cases or not?).
In XSLT 2.0, the transformation fails if you try to create a namespace node whose the prefix is already bound to another namespace URI. I like that. In XSLT 1.0, the transformation succeed, your result is not correct and the error will propagate further in the chain.
Mmh, before to post, I just wrote a little test. Input:
<my:same xmlns:my="namespace-double.xsl"> <my:other xmlns:my="other-uri"/> </my:same>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:my="namespace-double.xsl" exclude-result-prefixes="exsl" version="1.0">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="*"> <xsl:variable name="dummy-ns"> <my:e/> </xsl:variable> <xsl:copy> <xsl:copy-of select=" exsl:node-set($dummy-ns)/*/namespace::*"/> <xsl:attribute name="added">my:value</xsl:attribute> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:template match="@*|node()" priority="-1"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
I tested it with Saxon 6, Saxon 8, Xalan and xsltproc. Actually, Saxon 6 was the only one to generate an error:
Error at xsl:copy-of on line 16 of namespace-double.xsl: Cannot create two namespace nodes with the same name Transformation failed: Run-time errors were reported
I thought in this case an XSLT 1.0 processor will change one of the prefixes and not generate an error, but I didn't find the right verses in the XSLT 1.0 REC. Does any one know those verses?
Furthemore, I thought Saxon 8 didn't throw an error because it was in compatibility mode, but the transformation succeed even with an XSLT 2.0 stylesheet. It fails if we use xsl:namespace to create the node, but not if we use xsl:copy-of to copy it. Again, I didn't find in the XSLT 2.0 REC the difference between xsl:namespace and xsl:copy-of regarding the duplicate namespace node names. Any pointer?
___________________________________________________________________________ Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions
Profitez des connaissances, des opinions et des expiriences des internautessur Yahoo! Questions/Riponses