[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Union of XPath sequences and the meaning of the u

Subject: Re: Union of XPath sequences and the meaning of the uniqueness constraint
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 10 Oct 2004 21:50:39 +0100
xpath sequences
Hi Kenneth,

> The union operator in XPath 2.0 is described as eliminating
> duplicates from the two sequences that it is combining. What is the
> criterion used for determining if two nodes in the resulting
> sequence are unique?

Duplicates are removed based on node identity.

When you set a variable using the content of <xsl:variable>, and don't
use an 'as' attribute, as in:

  <xsl:variable name="a">
    <xsl:sequence select="2" />
  </xsl:variable>

the XSLT processor automatically creates a document node and adds the
result of the sequence constructor inside the <xsl:variable> element
to that document node. When you add an atomic value to a document
node, the atomic value is converted to a text node and that text node
is added.

So, in your code, the variable $a is set to a document node with a
single text node child whose string value is "2". Similarly, $b is set
to a *different* document node with a single text node child whose
string value is "2". These are different document nodes, so "$a | $b"
is a sequence of two document nodes. But "$a | $a" results in a
sequence containing the single document node held by the variable $a.

If you want the variable $a to hold the atomic value "2", then you
should either use the select attribute on <xsl:variable>, as in:

  <xsl:variable name="a" select="2" />

or use the 'as' attribute to say that the variable should hold an
integer, as in:

  <xsl:variable name="a" as="xs:integer">
    <xsl:sequence select="2" />
  </xsl:variable>

If you do this, then you will find that the expressions "$a | $a" and
"$a | $b" will give you an error, since the union operator can only
operate over sequences of nodes.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.