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

Re: How does one merge sequences?

Subject: Re: How does one merge sequences?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 11 Oct 2004 10:03:24 +0100
merge sequence
Hi Kenneth,

> ....indicating that the "merged" sequence is still recognized as two
> sequences instead of a single merged one. How can one do a proper
> merge?

It's not that the sequences are still separate, as such. In your code,
you create a sequence of five elements, two from one document and
three from another. Just because the sequence contains all those
elements doesn't mean that they've been moved into another document.
Importantly, they still have their original siblings. So if you do:

  count(preceding-sibling::item) = 0

then it's true for two elements: the first element in the first
document and the first element in the second document.

If you want to create a new document that contains all the elements
from both documents, then you can do something like:

  <xsl:variable name="merged">
    <xsl:sequence select="$seq1/* | $seq2/*" />
  </xsl:variable>

Note that the elements in the new document are *copies* of the
elements from the original documents.

If you want to create the sequence of the original elements, as in:

  <xsl:variable name="merged" select="$seq1/* | $seq2/*" />

and test whether you're on the first one in that sequence, then use
the position() function:

  <xsl:for-each select="$merged">
    <xsl:value-of select="." />
    <xsl:if test="position() = 1"> = first</xsl:if>
    <xsl:text>&#xA;</xsl:text>
  </xsl:for-each>

By the way, note that if you merge sequences with the union operator
then there's no guarantee that the elements from the first document
you create will actually be before the elements from the second
document you create in the sequence. (Per the spec, the order has to
be consistent throughout the transformation but it's implementation
dependent what the ordering of nodes from different documents actually
is.) So if you care about the order of the elements in the merged
sequence, it's better to use the "," operator to merge the sequences,
as in:

  $seq1/*, $seq2/*
  
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.