[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Counting Nodes Based on Conditional Statements

Subject: Counting Nodes Based on Conditional Statements
From: Michael <msell@xxxxxxxxxxxxxxx>
Date: Sat, 30 Oct 2004 21:32:30 +1000
xsl counting nodes
I must have a stunted ability to search throughout the archives, because once again I can't find anything specific to solve my problem that should be common (sigh).

Anyway, I have a stylesheet that displays book titles depending on some parameters passed to it. As a result, a dynamic number of books are shown. I need to count the number of the book titles that are shown, and display the result accordingly. If no book titles are shown at all, I need to be able to display message in their absence. Only containing a cursory knowledge of variables in XSLT, i'm not yet skilled enough to handle this problem on my own. Some help would be great.

An example of the xml document follows:

 <category name="Health &amp; Fitness">
     <book status="Purchased">
       <title>Strength Training Anatomy</title>
       <sub-title>Your Illustrated Guide to Muscles at Work</sub-title>
       <author>Fridiric Delavier</author>
       <isbn>0736041850</isbn>
       <publisher>Human Kinetics Publishers</publisher>
       <date>September, 2001</date>
       <price>13.27</price>
     </book>
   </topic>
   <topic name="Nutrition">
     <book status="Purchased">
       <category>Health &amp; Fitness</category>
       <title>Nutrition For Dummies</title>
       <author>Carol Ann Rinzler</author>
       <isbn>0764540823</isbn>
       <publisher>Wiley Publishing</publisher>
       <date>November, 2003</date>
       <price>15.39</price>
     </book>
     <book status="Purchased">
       <title>Encyclopedia of Sports &amp; Fitness Nutrition</title>
       <author>Liz Applegate</author>
       <isbn>0761513787</isbn>
       <publisher>Prima Publishing</publisher>
       <date>December, 2002</date>
       <price>16.07</price>
     </book>
     <book status="Purchased">
       <title>Nancy Clark's Sports Nutrition Guidebook</title>
       <author>Nancy Clark</author>
       <isbn>073604602X</isbn>
       <publisher>Human Kinetics Publishers</publisher>
       <date>August, 2003</date>
       <price>13.27</price>
     </book>
   </topic>
 </category>

The stylesheet code follows:

 <xsl:param name="category" />
 <xsl:param name="topic" />
 <xsl:param name="status" />

 <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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.