When using the ContentByQuery webpart (CQWP) you may come across a situation where you want to display the row number when displaying each row.
This is very simple to achieve and involves modifying two files; ContentByQueryMain.xsl and ItemStyle.xsl
NOTE: It is best practice to never alter the standard itemStyle.xsl or ContentQueryMain.xsl files themselves. Make a copy of them and have your webpart reference the copies instead.
I will assune for this that you already know how to modify ItemStyle.xsl to create custom item styles for the CQWP.
Let imagine that you have created a new item style in ItemStyle.xsl called "simpleRowAndTitle" which will simply output the rows number and title.
<xsl:template name="simpleRowAndTitle" match="Row[@Style='simpleRowAndTitle']" mode="itemstyle">
<xsl:param name="CurPos" />
<div class="item">
<span><xsl:value-of select="$CurPos" /></span>
<xsl:value-of select="@Title"/>
</div>
</xsl:template>
As you can see the template takes and displays the param "CurPos". Now all we have to do is modify the ContentByQueryMain.xsl and pass through this value.
In ContentByQueryMain.xsl search for the template "OuterTemplate.CallItemTemplate". This should contain an xsl choose statement. Find the "otherwise" part that looks limilar to the below block:
Modify that otherwise block so that it passes the current position to the item template as in the code block below.
<xsl:otherwise>
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
</xsl:otherwise>
Save your xsl files and reapply to your webpart on using your list and you will have your list showing your row numbers.