views:

173

answers:

1

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

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

<xsl:template match="/">
  <div style="border:1px solid red; float:left;">
    <!-- iterate the group, sorted by PictureType… -->
    <xsl:for-each select="/dsQueryResponse/Rows/Row[
      count(. | key('pictures-by-productid', @ProductId)[1]) = 1
    ]">
      <xsl:sort select="@PictureType">
      <!-- …and output only if among the fist 6 items -->
      <xsl:if test="position() &lt;= 6">
        <xsl:apply-templates 
          mode="picture"
          select="key('pictures-by-productid', @ProductId)" 
        />
      </xsl:if>
    </xsl:for-each>
  </div>
</xsl:template>

<xsl:template match="/dsQueryResponse/Rows/Row" mode="picture">
  <div style="float:left; margin:2px;">
    <img src="{@ThumbNailUrl}" width="58" /> <br />                         
    <xsl:text>Download </xsl:text>
    <xsl:number value="position()" format="1. " />
    <xsl:value-of select="." />
  </div>
</xsl:template>
Tomalak