RE: [xsl] Grouping and numbering in XSLT 2.0,

Subject: RE: [xsl] Grouping and numbering in XSLT 2.0,
From: <geirr.prestholdt@xxxxxxxxxxxxx>
Date: Mon, 14 Nov 2005 10:15:13 +0100
Thank you for the reply, I am sure this will do the job :-).

The v2.0 solution to this problem, could be nice to see. So, If someone
of you could show me, I would appreciate that.


-----Original Message-----
From: Haarman, Michael [mailto:mhaarman@xxxxxxxxx]
Sent: 11. november 2005 20:49
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE: [xsl] Grouping and numbering in XSLT 2.0,

> -----Original Message-----
> From: geirr.prestholdt

> vendor. I have no number to use as grouping key, but as you can

You cannot use position() for the *use* expression of a key, it will
always return 1, but you can use something comparable, such as the count
of preceding-sibling nodes:

  <xsl:key name="company" match="*/cell[@name = 'Company']/value"
    use="count(preceding-sibling::value) + 1"/>
  <xsl:key name="cage" match="*/cell[@name = 'Cage']/value"
    use="count(preceding-sibling::value) + 1"/>
  <xsl:key name="address" match="*/cell[@name = 'Address']/value"
    use="count(preceding-sibling::value) + 1"/>

A main template to get things going:

<xsl:template match="/">
    <xsl:call-template name="getVendors">
      <xsl:with-param name="count" select="1"/>
      <xsl:with-param name="total"
                      select="count(*/cell[@name = 'Company']/value)"/>

And a named template to call a number of times:

<xsl:template name="getVendors">
  <xsl:param name="count" select="1"/>
  <xsl:param name="total" select="1"/>

    <xsl:when test="$count &lt;= $total">
        <cell name="Company">
          <value><xsl:value-of select="key('company', $count)"/></value>
        <cell name="Cage">
          <value><xsl:value-of select="key('cage', $count)"/></value>
        <cell name="Address">
          <value><xsl:value-of select="key('address', $count)"/></value>
      <xsl:call-template name="getVendors">
        <xsl:with-param name="count" select="$count + 1"/>
        <xsl:with-param name="total" select="$total"/>


There is probably a three-line v2.0 solution to this, but I've been out
of the loop lately.



Mike Haarman,
XSL Developer,
Internet Broadcasting Systems, Inc.

Current Thread