xsl-list
[Top] [All Lists]

Re: [xsl] Merging elements within a range using a key

2006-05-02 04:16:11

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
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--