xslt condition to check if each row of a table has same or different data
Is there any condition in xslt that will help me to find if a table field, say Name, has different value? I have a set of different names with me in a xml file. I need to display each name in a different color on the html table. If there are 2 rows that has same Name field, then they should both be of unifor开发者_JAVA技巧m color. Is there any if condition that will help me to achieve this requirement in xslt?
Yes. You can count()
the number of nodes with the given name.
<xsl:variable name="value" select="Name/text()"/>
<xsl:variable name="count" select="count(//row[Name/text() = $value])"/>
<xsl:if test="$count > 0"> <!-- do something --> </xsl:if>
Or you can check if there is a preceding or following node with a Name:
<xsl:variable name="value" select="Name/text()"/>
<xsl:variable name="node" select="preceding::.//row[Name/text() = $value]|following::.//row[Name/text() = $value]"/>
<xsl:if test="count($node) > 0"> <!-- do something --> </xsl:if>
精彩评论