Separating positive values from 'zero' values in an XSLT for-each statement
Posted
by danielle
on Stack Overflow
See other posts from Stack Overflow
or by danielle
Published on 2010-05-12T07:50:21Z
Indexed on
2010/05/12
7:54 UTC
Read the original article
Hit count: 287
I am traversing an XML file (that contains multiple tables) using XSLT. Part of the job of the page is to get the title of each table, and present that title with along with the number of items that table contains (i.e. "Problems (5)").
I am able to get the number of items, but I now need to separate the sections with 0 (zero) items in them, and put them at the bottom of the list of table titles. I'm having trouble with this because the other items with positive numbers need to be left in their original order/not sorted.
Here is the code for the list of titles:
<ul>
<xsl:for-each select="n1:component/n1:structuredBody/n1:component/n1:section/n1:title">
<li style="list-style-type:none;">
<div style = "padding:3px"><a href="#{generate-id(.)}">
<xsl:variable name ="count" select ="count(../n1:entry)"/>
<xsl:choose>
<xsl:when test = "$count != 0">
<xsl:value-of select="."/> (<xsl:value-of select="$count"/>)
</xsl:when>
<xsl:otherwise>
<div id = "zero"><xsl:value-of select="."/> (<xsl:value-of select="$count"/>)</div>
</xsl:otherwise>
</xsl:choose>
</a>
</div>
</li>
</xsl:for-each>
</ul>
Right now, the "zero" div just marks each link as gray.
Any help regarding how to place the "zero" divs at the bottom of the list would be greatly appreciated. Thank you!
© Stack Overflow or respective owner