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

Re: Counting non-empty elements

Subject: Re: Counting non-empty elements
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 13 Mar 2002 16:59:01 +0000
xsl count empty elements
Hi Sergej,

> I'd like to write a number near non-empty descriptions as shown in
> the following code:
>
> <xsl:template match="itemSet">
>   <tr>
>     <td>
>       <xsl:if test="normalize-space(itemDesc)">
>         <xsl:number level="multiple" format="1. "/>
>         <xsl:value-of select="itemDesc"/>
>       </xsl:if>
>     </td>
>     <td>....</td>
>   </tr>
>   ....
> </xsl:template>
>
> The problem is that also the empty elements are taken into account
> even if the number does not appear.

When you use xsl:number with an element as the current node, by
default it counts all the elements that have the same name as the
current element. You can tell the processor to only count certain
elements by creating a pattern for those elements within the count
attribute of xsl:number. If you want it to only count itemSet elements
that have a non-empty itemDesc element child, then you can use the
pattern:

  itemSet[normalize-space(itemDesc)]

So you can number them with:

  <xsl:number level="multiple" format="1. "
              count="itemSet[normalize-space(itemDesc)]" />

By the way, I'm assuming that you do want to use level="multiple" and
that itemSet elements that you're interested in at every level should
have text within their itemDesc children.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.