You can only use CAML query inside a Content Query Web Part by using the Clientside Object Model, but that will call the CAML Query for each and every item displayed. Not a good thing.
XSLT is only used to diplay the results of the Content Query Web Parts queries. Nothing more.
You can at any time create your own XSLT Template within the ItemStyle.xslt which you find in the Style Library on the root web.
You must know that the Content Query Web Part uses 3 different XSLT sheets;
- ItemStyle.xslt
- ContentQueryMain.xslt
- Header.xslt
Which all resides withing the Style Library.
The ContentQueryMain.xslt is the one which has all the templates which does the "pre" work if you can call it that. That's the file which does the filtering, extracting of column URLs etc etc etc.
If you want to have the 5 latest items displayed, that's easily done by configuring the CQWP to sort the items descending, displaying the latest items first. This is default though.
The "tricky" part is to apply a different or slighty different transform on each item depending on the order.
To help you fix this, you must do as follows:
In your ContentQueryMain.xslt find the template OuterTemplate.CallItemTemplate. It has a <xsl:choose> going on in it. In the <xsl:otherwise> clauss add the following:
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
Go to your ItemStyle.xslt and in that either create a new or modify a current template and add this:
<xsl:param name="CurPos"/>
right under
<xsl:template name="MyTemplate" match="Row[@Style='MyTemplate']" mode="itemstyle">
So you should have something like this:
<xsl:template name="MyTemplate" match="Row[@Style='MyTemplate']" mode="itemstyle">
<xsl:param name="CurPos"/>
// Rest of your template structure here
</xsl:template>
This makes you able to choose which item you would like the template to brand differently than others.
Example:
<xsl:template name="MyTemplate" match="Row[@Style='MyTemplate']" mode="itemstyle">
<xsl:param name="CurPos"/> // Gives you the current item position.
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/> // Used for variable below.
<xsl:variable name="RowCount" select="count($Rows)"/> // Gives you the last item position.
<xsl:if test="$CurPos = 1">
This is the first item the Content Query shows.
</xls:if>
<xsl:if test="$CurPos = $RowCount">
This is the last item the Content Query shows.
</xls:if>
// etc etc etc
</xsl:template>
Hope this helps :)