[xquery-talk] items as nodes or atomic values

Michael Kay mike at saxonica.com
Mon May 7 23:10:45 PDT 2007

When you write the expression
if (@x = ('apple', 'pear', 'orange')) then <e/> else <f/>
this is what happens.
1. The expression @x is evaluated. The result of this expression is a
sequence containing a single attribute node.
2. The result of (1) is atomized. If there is no schema, the result is a
sequence containing a single atomic value of type xs:untypedAtomic. If there
is a schema, however, that describes the type of @x as xs:NMTOKENS and the
actual value of @x is "banana cherry", then the result of atomization is a
sequence of two (atomic) xs:NMTOKEN values.
3. The result of (2) is compared with the sequence-of-strings ('apple',
'pear', 'orange')
4. The result of the comparison in (3) is a sequence containing a single
xs:boolean value
I hope this shows how values consisting of nodes and values consisting of
atomic values interact, and how atomic values can exist independently of
nodes. In fact, XPath 1.0 allowed either sets of nodes, or singleton atomic
values. XPath 2.0 has generalized this to also allow sets/sequences of
atomic values, and singleton nodes.
In this example there are no heterogeneous sequences, but they can arise and
they can be very useful. Here's a handy example:
<e status="{(@status, 'n/a')[1]}"/>
which sets the value of the status attribute on the new element to a copy of
the status attribute of the context node if it exists, or to the string
'n/a' otherwise. This involves a filter expression in which the sequence
being filtered contains an attribute node and a string.
Hope this helps!
Michael Kay


From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf
Of Smith, Donald T.
Sent: 07 May 2007 21:29
To: talk at x-query.com
Subject: [xquery-talk] items as nodes or atomic values

This may be a well-worn question. If so, please point me to the location of
the discussion. Otherwise. . .


I'm thinking through the XQuery/XPath data model. The last paragraph in
section 3.0 has me puzzling: "The data model also supports values that are
not nodes. Examples of these are sequences of atomic
atomic-value> values, or sequences mixing nodes and atomic values. These are
necessary to be able to represent the results of intermediate expressions in
the data model during expression processing."


I'm accustomed, from XPath 1.0,  to thinking of trees of nodes, so I'm not
quite getting what it means to have items in sequences that are either nodes
or atomic values. Since an atomic value is a string that conforms to an
atomic type, atomic types are schema-defined, and nodes may or may not have
schema-defined datatypes, I don't understand the case where an atomic type
would not be associated with - and so represented by -- a node. In other
words, I can't image a XQuery/XPath sequence as anything other than a node
tree, which clearly shows I'm still in XPath 1.0 land.


The last line I quoted above indicates that this whole issue arises from
something that goes on during expression processing, so perhaps this is an
issue that only matters to those who write XQuery/XPath engines. At any
rate, if anyone can clarify this issue for me, I'd appreciate it.


Don Smith

Information Architect

American Airlines



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20070507/96d3f38d/attachment.htm

More information about the talk mailing list