I was looking for a solution so that I could use one table in my ItemStyle. I have created my custom item style and I don't want to create a table with each item, so I need the current row and the last row. If I use <xsl:value-of select="position()" /> each value is 1, so that will not do the trick. What should I do? Well here's the answer, first edit the 'ContentQueryMain.xsl' (in the Style Library). Search for the next template:
<xsl:template name="OuterTemplate.CallItemTemplate">
Then replace the complete template with the next code:
<xsl:template name="OuterTemplate.CallItemTemplate">
<xsl:param name="CurPosition" />
<!--
The LastRow parameter is used in style "MyStyle".
-->
<xsl:param name="LastRow" />
<xsl:choose>
<xsl:when test="@Style='NewsRollUpItem'">
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="EditMode" select="$cbq_iseditmode" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@Style='NewsBigItem'">
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@Style='NewsCategoryItem'">
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
</xsl:when>
<!--
Pass current position and lastrow to the MyStyle itemstyle.xsl template
-->
<xsl:when test="@Style='MyStyle'">
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="CurPos" select="$CurPosition" />
<xsl:with-param name="Last" select="$LastRow" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="itemstyle">
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Then look for the <xsl:template name="OuterTemplate.Body"> code in the ContentQueryMain.xsl and insert the lastrow parameter:
<xsl:call-template name="OuterTemplate.CallItemTemplate">
<xsl:with-param name="CurPosition" select="$CurPosition" />
<!-- Insert the LastRow parameter. -->
<xsl:with-param name="LastRow" select="$LastRow"/>
</xsl:call-template>
When this is done, you can use the parameters:
<xsl:param name="CurPos" />
<xsl:param name="Last" />
in you custom ItemStyle template. These can be used to show the table start (if $CurPos=1) and table end tag (if $CurPos=$Last) in your item list.
Hope this helps you as much as it did me ;)
Thanks to the post of Paul Galvin!