I have the following XML structure
<containers>
<container type="1"></container>
<container type="2"></container>
<container type="2"></container>
<container type="1"></container>
<container type="2"></container>
<container type="2"></container>
<container type="2"></container>
</containers>
I want to find the count of immediate preceding-sibling of the same type. How can check in XSLT e.g.
- for 1st container count of preceding-sibling of same type = 0
- for 2st container count of preceding-sibling of same type = 0
- for 3rd container count of preceding-sibling of same type = 1
- for 4th container count of preceding-sibling of same type = 0
- for 5th container count of preceding-sibling of same type = 0
- for 6th container count of preceding-sibling of same type = 1
- for 7th container count of preceding-sibling of same type = 2
my XSLT condition
<xsl:choose>
<xsl:when test="count(preceding-sibling::*[type = 2]) mod 2 = 0">
<xsl:attribute name="class">classX</xsl:attribute>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>