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

two at a time, using a sequence expression

Subject: two at a time, using a sequence expression
From: "John Cavalieri" <john.cavalieri@xxxxxxxxx>
Date: Thu, 5 Jun 2008 11:13:22 -0500
 two at a time
Hi XSLers,

I'm curious if there is a more elegant way to use a sequence
expression to process two adjacent elements at a time.  With XSLT 1.0
I would have used recursion, but with XSLT/XPath 2.0 I'm wondering if
I can exploit sequences.  Below is something I've come up with so far.

An interesting side note, I thought the sequence expression would
error because of divide by zero, but it appears to be side effect
free, at least with Saxon.

INPUT

<?xml version="1.0" encoding="UTF-8"?>
<pairs>
  <Abbott />
  <Costello />
  <Amos />
  <Andy />
  <George />
  <Gracie />
  <Einstein />
</pairs>


XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:output indent="yes" />

  <xsl:template match="/pairs">
    <xsl:copy>
      <xsl:for-each select="for $i in 1 to (count(*) idiv 2 +
(count(*) mod 2)) return *[($i*2)-1]">
        <pair>
          <xsl:copy-of select="." />
          <xsl:copy-of select="./following-sibling::*[1]" />
        </pair>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


--
John Cavalieri
john.cavalieri@xxxxxxxxx

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.