1

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
Image
Title
Date

Second record
Title
Date

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

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>
<xsl:template match="row">
  ... html without image
</xsl:template>

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
    </xsl:if>
  ... html for common end
  </xsl:for-each>
</xsl:template>
| improve this answer | |
  • 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. – Frank Martin Dec 1 '13 at 7:26
1

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

<xsl:if test="position() = '1'">
 <img src="#" alt="heyo" />
</xsl:if>
| improve this answer | |
  • 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. – Frank Martin Dec 1 '13 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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