XSLT Global count of grouped items

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2009-12-14T16:06:42Z Indexed on 2010/04/21 15:03 UTC
Read the original article Hit count: 411

Filed under:
|
|

Hi there,

I have a set of items which i am grouping using the muenchian method using keys. This is working great however when i try to do things with the first x number of items it is doing it on the x number of items in each group rather than across the whole set of results. How would i get the individual position of each item accross the whole collection?

    <xsl:key name="pictures-by-productid" match="/dsQueryResponse/Rows/Row" use="@ProductId" />


<xsl:template match="/">
	<div style="border:1px solid red; float:left;">
	    <xsl:apply-templates select="/" mode="sub">

	    </xsl:apply-templates>
	</div>
</xsl:template>

and the second template

	<xsl:template match="/" mode="sub">    <xsl:for-each select="/dsQueryResponse/Rows/Row[count(. | key('pictures-by-productid', @ProductId)[1]) = 1]">
		<xsl:for-each select="key('pictures-by-productid', @ProductId)">			
			<xsl:sort select="@PictureType" />					
			<div style="float:left; margin:2px;">
			<img src="{@ThumbNailUrl}" width="58" /> <br />				
			Download			
			<xsl:number value="position()" format="1. " />
			<xsl:value-of select="." />
			</div>

		</xsl:for-each>
	</xsl:for-each>
</xsl:template>

Thanks

Chris

© Stack Overflow or respective owner

Related posts about xslt

Related posts about sorting