[xquery-talk] Re: Attribute node whose parent is a document node

Michael Kay mhk at mhk.me.uk
Sat Jul 9 10:01:31 PDT 2005

> That's interesting. To recap (and simplify) the piece of code that's
> producing the result you're getting:
> let $a :=
> <root>
> <county name="Devon">
>      <district name="East Devon">
>          <town name="Axminster" pct="East Devon">
>              <town name="Abbey Gate"/>
>           </town>
>          <town name="Aylesbeare" pct="East Devon"/>
>      </district>
> </county>
> </root>
> return
> <attribute>{ $a/county/district/town/@name }</attribute>
> Your code is trying to return the two @name attributes that 
> are reachable via the given path... 
> The latest version of the spec says that having duplicate 
> attributes (ie
> attributes of the same name, something not permitted in xml) 
> in a direct
> element constructor should raise a static error.

This isn't a static error - there aren't two name attributes on the same
element constructor in the source query. It's a dynamic error, XQDY0025, as
described in section, clause 5d.

> Saxon leniently resolves
> the issue by simply picking the second of the two 
> ("Aylesbeare")

Saxon appears to be incorrectly implementing the XSLT semantics here rather
than the XQuery semantics. XSLT always chooses the last of several
attributes with the same name. There seems to be a switch in the code to
enforce the stricter XQuery rules in the path that creates new attributes,
but not in the path that copies existing attributes. 

Michael Kay

More information about the talk mailing list