[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: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 2 May 2006 13:57:38 +0100
xsl sort merged elements
> >  the only way to improve
> >  this - to make it O(C+R) rather than O(C*R) - is to hand-code a 
> >sort-merge join.
> Since rows and categories are already sorted, this is 
> probably the best thing to do.

It occurred to me after writing that you don't need to use recursion for
this: you can do a sort on the merged node-sets and then use grouping to
find the rows in each category. In 2.0, given

<category name="A" start="10"/>
<category name="B" start="100"/>
<category name="C" start="1000"/>
<category name="D" start="10000"/>
<category name="E" start="100000"/>

<row value="842"/>
<row value="9725"/>
etc

you can do

<xsl:variable name="merged-and-sorted">
  <xsl:perform-sort select="category|row">
    <xsl:sort select="self::category/@start | self::row/@value"/>
  </
</

<xsl:for-each-group select="$merged-and-sorted"
group-starting-with="category">
  <xsl:for-each select="current-group()[self::row]">
    <xsl:copy>
      <xsl:attribute name="category" select="current-group()[1]/@name"/>
      <xsl:copy-of select="@*|node()"/>
    </xsl:copy>
  </
</

Michael Kay
http://www.saxonica.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-2011 All Rights Reserved.