[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: 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="/"> <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 <= $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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|