xsl-list
[Top] [All Lists]

Re: Counting Nodes Based on Conditional Statements

2004-10-30 08:36:35
Hi Michael,

 <xsl:template match="/">
   <div class="line"></div>

   <xsl:for-each select="catalog/category/topic/book">
     <xsl:sort select="title" data-type="text" order="ascending" />
<xsl:if test="$status = 'All' or ($status = 'Purchased' and @status = 'Purchased')"> <xsl:if test="$category = 'All' or ($category = ../../@name and ($topic = ../@name or $topic = 'All'))">
         <div><xsl:value-of select="title" /></div>
         <div class="line"></div>
       </xsl:if>
     </xsl:if>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet>

You could _first_ determine the list catching it in a variable and _then_ get the count and loop over them.

<xsl:variable
    name="books"
    select="catalog/category/topic/book
                [$status = 'All'
                  or ($status = 'Purchased' and @status = 'Purchased')]
                [$category = 'All'
                  or ($category = ../../@name and ($topic = ../@name or $topic = 
'All'))]" />

(sorry for the silly indentation)

<xsl:choose>
  <xsl:when test="count($books) = 0">
    <!-- sorry no books -->
  </xsl:when>
  <xsl:otherwise>
    <!-- count($books) shown! -->
    <xsl:for-each select="$books">
      <!-- presentation of books -->
    </xsl:for-each>
  </xsl:otherwise>
</xsl:choose>

Grtz,
Geert


<Prev in Thread] Current Thread [Next in Thread>