[xquery-talk] items as nodes or atomic values

Smith, Donald T. DonaldT.Smith at aa.com
Mon May 7 18:16:04 PDT 2007


Michael,

 

Thanks. I want to make sure I understand your first example completely.
Given the source XML:

 

<sample x="banana cherry" /> and *no* schema to validate against, the
result of the expression "if (@x = ('apple', 'pear', 'orange')) then
<e/> else <f/>" is atomized into an untyped atomic sequence that
consists of one value, "banana cherry". 

 

If, however, there is a schema to validate against, and it defines the
type of "x" as NMTOKENS, then the result is a sequence of two atomic
NMTOKEN values, "banana" and "cherry".

 

Do I understand this correctly?

 

I do see from the example how nodes and (atomic) values interact, but it
seems to confirm my prior understanding of node trees since, in the
example given, the result of the @x expression is (first) a node whose
value is (then) atomized. So I'm still thinking initially of the node
tree and then about how a given node value is or is not atomized. What
I'm not tracking with is thinking of atomic values without, or apart
from, nodes.  

 

In your second example, do you refer to this as a heterogeneous sequence
because in one case evaluating the expression results in an atomic value
(perhaps "final"), while in another it results in nothing (if there is
no "status" attribute)?

 

Thanks again,

 

Don

 

 

________________________________

From: Michael Kay [mailto:mike at saxonica.com] 
Sent: Monday, May 07, 2007 4:11 PM
To: Smith, Donald T.; talk at x-query.com
Subject: RE: [xquery-talk] items as nodes or atomic values

 

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

http://www.saxonica.com/

	 

	
________________________________


	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
values
<http://www.w3.org/TR/2007/REC-xpath-datamodel-20070123/#dt-atomic-value
#dt-atomic-value> , 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

	817-967-0310

	 

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


More information about the talk mailing list