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

Michael Kay mhk at mhk.me.uk
Sun Jul 10 11:47:47 PDT 2005


> 
> Yes :-) However, it's a difficult exercise. 

Of course. But it's more reliable than inferring the spec from the behaviour
of implementations - especially in corner cases!

Please consider 
> this (crazy) 
> example :
> 
> let $a :=
> <root>
>    <foo name="bar"/>
>    <name name="foo">bar</name>
>    <foo name="bar"/>
> </root>
> 
> return
>   <result>{($a//@name|$a//name)}</result>
> 
> As discussed earlier, I get an XTDE0420 error from Saxon as 
> mentionned 
> in http://www.w3.org/TR/xslt20/#error-summary :
> 
> > It is a non-recoverable dynamic error if the result 
> sequence used to construct the content of a document node 
> contains a namespace node or attribute node.

Actually, the error message is

  XTDE0420: Attribute nodes must be created before the children of an
element node

There are a few cases like this where Saxon is currently issuing an XSLT
error code rather than an XQuery error code. It tends to happen in cases
where the underlying run-time code has no knowledge of which host language
was used to generate the code. I fix these as I come across them. But the
error message is basically correct, as I assume you realise.

Error codes were only introduced into Saxon very recently, and at present
they aren't always correct. This is generally because the error (eg. an
undeclared namespace prefix) is detected at a level in the code where one
test is detecting several different error conditions defined separately in
the spec. You can expect this situation to improve gradually over time as
the test suite expands. Please report any discrepancies that you find.
> 
> However :
> 
> > attributes consist of all the attributes specified in the 
> start tag as described in 3.7.1.1 Attributes, together with 
> all the attribute nodes in the content sequence, in 
> implementation-dependent order.
> 
> How should I interpret "all the attribute nodes in the 
> content sequence"

I can't quite see where your difficulty is in interpreting this phrase.
 
> ? Aren't there 3 attributes in my content sequence 

Yes, there are.
> 
> But... how does this cope with the definition given at 
> http://www.w3.org/TR/xpath20/#dt-document-order ?

I don't understand your difficulty. There are three attributes, and they
have a well-defined document order. What are you trying to "cope with"?
> 
> Furthermore, am I not in the case where :
> 
> > If two or more of these attributes have the same node-name, 
> a dynamic error is raised [err:XQDY0025]. Note that the 
> parent property of each of these attribute nodes has been set 
> to the newly constructed element node.
> 
> ... and thus get an XQDY0025 error ?

Yes, an implementation could legitimately return this error instead of
XQTY0024. Your content sequence breaks both rules: it has an attribute after
an element, and it has two attributes of the same name. In these cases it's
clear that the system can report either error (or both, if it wishes).
> 
> PS or course explicitely ordering my sequence :
> 
> let $a :=
> <root>
>    <foo name="bar"/>
>    <name name="foo">bar</name>
>    <foo name="bar"/>
> </root>
> 
> <result>{($a//@name,$a//name)}</result>)
> 
> ...returns no error:
> 
> <result name="bar">
>     <name name="foo">bar</name>
> </result>
> 

As previously mentioned, you should get an error XQDY0025 in this case.

Michael Kay
http://www.saxonica.com/




More information about the talk mailing list