Re: Parentless attribute nodes and namespaces, text says it is disallowed, processors appear to allow it

> On 23 Sep 2015, at 20:30, Abel Braaksma <abel.braaksma@xs4all.nl> wrote:
> 
> I was wondering if the statement we have about parentless attribute nodes is still valid. Under 5.8 Sequence Constructors we say:
> 
> <quote>
> Parentless attribute nodes require particular care because they have no namespace nodes associated with them. A parentless attribute node is not permitted to contain namespace-sensitive content (for example, a QName or an XPath expression) because there is no information enabling the prefix to be resolved to a namespace URI. Parentless attributes can be useful in an application (for example, they provide an alternative to the use of attribute sets: see 10.2 Named Attribute Sets) but they need to be handled with care.
> </quote>
> 
> For instance, if I write something like this:
> 
> <xsl:template match="x">
>   <xsl:copy>
>     <xsl:variable name="attr" as="attribute()">
>        <xsl:attribute name="test" namespace="urn:myns" />
>     </xsl:variable>
>     <xsl:copy-of select="$attr" />
>   </xsl:copy>
> </xsl:template>
> 
> It creates <x ns1:test="" xmlns:ns1="urn:myns" />

This attribute does not have namespace-sensitive content (its value is not a QName or similar type).
> 
> I doubt it should fail as the test suggests. When I try this with several processors, they all create a new namespace node with the URI of the namespace attribute and place the new attribute in that namespace. This seems reasonable, but if we allow that as a proper status-quo-in-the-wild (tested in XSLT 2.0 and 3.0), then perhaps we should reconsider that Note. Or am I misinterpreting it?
> 
> Also, what is meant by "or an XPath expression"? A namespace node does not *contain* an XPath expression.

“an XPath expression” here is being used as an example of namespace-sensitive content. The text is talking about the content of an attribute node, not about the content of a namespace node.
> 

I think the text as written is correct, though it may be that the note here no longer serves any useful purpose. There are plently of other places in the spec where we warn about the difficulties that can arise when attributes have namespace-sensitive values (search for “namespace-sensitive” to find them), and the note here is not especially helpful.

Michael Kay
Saxonica

Received on Sunday, 27 September 2015 22:04:53 UTC