Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.3k views
in SharePoint Server by 29 37 42

I have a SharePoint Custom Item Style, I need to get Current Row Number in ItemStyle.XSL to check if the current position is equal to the first ROW apply a different style than the provided in the second row! I have tried to create a new variable called the current position as below XSL but it's not working as expected!

<xsl:variable name="CurrentPos" select="count(preceding-sibling::*)=1" />

How can I check if the current row is the first row in XSL SharePoint ItemStyle for Content Query Web Part?


1 Answer

1 like 0 dislike
by 152 169 345
selected by
 
Best answer

How to get row number in ItemStyle.XSL in SharePoint?

To get current row number in SharePoint ItemStyle.XSL, you have to define a variable as the following:

<xsl:variable  name="CurPos">
<xsl:number></xsl:number>
</xsl:variable>

How to print current row number in ItemStyle.XSL?

To print the current row number in ItemStyle.XSL, you have to use the below line:

<xsl:value-of disable-output-escaping="yes" select="$CurPos"/>

How to check if current row is the FIRST ROW in ItemStyle.XSL?

To check if the current row is FIRST ROW in ItemStyle.XSL, you have to use the If Condition statement in XSL as the following:

<xsl:if test="$CurPos= 1">
 <!-- your style-->
</xsl:if>

How to check if the current row is NOT the FIRST ROW in ItemStyle.XSL?

To check if the current row is FIRST ROW in ItemStyle.XSL, you have to use the Choose statement in XSL as the following:

<xsl:choose>
<xsl:when test="$CurPos= 1">
  <!-- if true-->
</xsl:when>
<xsl:otherwise>
  <!-- if false-->
</xsl:otherwise>
</xsl:choose>

See also, Get Current Page URL in XSLT SharePoint ItemStyle

If you don’t ask, the answer is always NO!
...