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

RE: Grouping and numbering in XSLT 2.0,

Subject: RE: Grouping and numbering in XSLT 2.0,
From: "Haarman, Michael" <mhaarman@xxxxxxxxx>
Date: Fri, 11 Nov 2005 13:48:51 -0600
xsl count values
> -----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="/">
  <Vendors>
    <xsl:call-template name="getVendors">
      <xsl:with-param name="count" select="1"/>
      <xsl:with-param name="total" 
                      select="count(*/cell[@name = 'Company']/value)"/>
    </xsl:call-template>
  </Vendors>
</xsl:template>


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

    <xsl:otherwise/>
  </xsl:choose>
</xsl:template>



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


HTH,

Mike


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

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.