Subject: RE: [xsl] Grouping and numbering in XSLT 2.0, From: "Haarman, Michael" <mhaarman@xxxxxxxxx> Date: Fri, 11 Nov 2005 13:48:51 -0600 |
> -----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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping and numbering in XSL, geirr.prestholdt | Thread | RE: [xsl] Grouping and numbering in, geirr.prestholdt |
RE: [xsl] Filtering problem, Haarman, Michael | Date | [xsl] writing <xsl:value-of> to jsp, TGolshan |
Month |