开发者

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 &gt; 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) &gt; 0"> <!-- do something --> </xsl:if>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜