I am displaying two records from a list on home page.
Only the first record needs to show image while second record will not show image. Here's what they will display:

First record

Second record

As you can see image needs to show only for first record. Right now it displays image for both records which I don't want. I want to use "mod" function to check if first record is coming then show image else not.
Is it possible?

2 Answers 2


See XSLT special condition for first row

You can do it by specifying a special template for the first element like this:

<xsl:template match="row[1]">
  ... html with image
<xsl:template match="row">
  ... html without image

or by using an if inside a foreach

<xsl:template match="rows">
  <xsl:for-each select="row">
  ... html for common start
    <xsl:if test="position() = 1">
  ... html for image
  ... html for common end
  • Tried the second solution you have given and it is not working in itemstyle.xsl. When I printed the value of position (to check why the condition is not working) it printed "1" for both records. Dec 1, 2013 at 7:26

Also using position() would work too, like so:

<xsl:if test="position() = '1'">
 <img src="#" alt="heyo" />
  • I tried this but it is not working in itemstyle.xsl which is used in CQWP. I mean it doesn't display any error but it shows images for both records. Dec 1, 2013 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.