Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Michael Kay" <mike@------------>
To:
Date: 5/2/2006 12:58:00 PM
> >  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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent