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

Re: Content constructors and sequences

Subject: Re: Content constructors and sequences
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Jan 2002 13:25:29 +0000
Re:  Content constructors and sequences
Hi Mike,

>> Given a node, you can therefore find other nodes in the same
>> document, but you can't find other items in the same sequence.
> Which reminds me, that one of the reasons I have resisted allowing
> documentless nodes in XSLT is that people are going to assume that a
> sequence of such nodes are siblings of each other, which of course
> they aren't.

I agree that's what people will assume, but I think that being able to
pass around documentless nodes has its advantages - construct a set of
attributes within a function and then copy them onto an element, for

Also, I think that people are going to assume you can get access to
other items in other sequences too - it already happens with node sets
in XSLT, and with more sequence processing going on it's going to get
a lot worse.

For example, $coordinates holds a sequence of integers, conceptually
pairs of x,y coordinates:

  <xsl:for-each select="$coordinates">
    <xsl:if test="position() mod 2 = 1">
      <xsl:variable name="x" select="." />
      <xsl:variable name="y" select="..." />

How do I get the value for $y?

Possibly solutions are:

  <xsl:for-each select="$coordinates[position() mod 2 = 1]">
    <xsl:variable name="i" select="position()" />
    <xsl:variable name="x" select="." />
    <xsl:variable name="y" select="$coordinates[$i * 2]" />


  <xsl:for-each select="(1 to count($coordinates) div 2)">
    <xsl:variable name="x" select="$coordinates[($i * 2) - 1]" />
    <xsl:variable name="y" select="$coordinates[$i * 2]" />

Neither is particularly inspiring (both involve visiting items in the
same sequence multiple times), and the latter is the only approach if
you're processing the sequence in XPath with a for expression, I

One possibility would be to offer next() and previous() functions that
returned the sequence following and before the current item in the
sequence being processed. For example:

  <xsl:for-each select="$coordinates">
    <xsl:if test="position() mod 2 = 1">
      <xsl:variable name="x" select="." />
      <xsl:variable name="y" select="next()[1]" />

But I haven't thought it through and this would probably cause its own


Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.