Friday, September 20, 2013

Using the following-sibling to compare node-sets in a SharePoint list


In a table I need to display items from a SharePoint custom list grouped by a column. For styling purposes, I need to identify the last row of each grouping. Using the following-sibling axis, I can look ahead to see if the group value will change. If so, I apply a class to the current table row.

<xsl:template match='Row'>
<tr>
<xsl:if test="@Group != following-sibling::Row[1]/@Group or position() = last()">
     <xsl:attribute name="class">lastItem</xsl:attribute>
 </xsl:if>
....
</tr>
...
</xsl:template>

In my stylesheet, I can then apply rules to the lastItem class:

table  tr { border-bottom: 2px #707070 dotted; }
table tr.lastItem { border-bottom: none; }