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

Re: Merging elements within a range using a key

Subject: Re: Merging elements within a range using a key
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 2 May 2006 12:11:57 +0100
date range test using xpath
well you could modify your template like so:

<xsl:key name="r" match="row" use="@r"/>

<xsl:template match="category">

  <xsl:variable name="row-test">
   <!-- should be improved with a key -->
   <xsl:variable name="s" select="@s"/>
   <xsl:variable name="r" select="1+ @e - $s"/>
   <xsl:for-each select="(//*)[position()&lt;=$r]">
     <xsl:copy-of select="key('r',position()+$s - 1)" />
   </xsl:for-each>
  </xsl:variable>
.
.
.


But if in your real case your row elements are already sorted in order
and each has a unique @r attribute then each of these keys is just
picking up a single row, the one after you picked up last time, so as
Mike just said, it's probably better just to make a template that
recursively walks along the row siblings checking the condition as you
go along.

I left the rest of your stylesheet the same although there seemed to be
something a bit odd about 

  <xsl:if test="string-length($row-test) > 0">
   <xsl:choose>
    <xsl:when test="category">

which is apparently testing for category children of the current
category element. If there are nested categories I'm not sure if these
keys (or your original XPath) would pick up the right thing, it depends
what the meaning of any such nesting is.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.