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

Re: check if a node is empty

Subject: Re: check if a node is empty
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 17 Oct 2002 16:49:00 +0100
Re:  check if a node is empty
Hi Vasu,

> would the following statement
> <xsl:template match="node">
> ....
> <xsl:when test="count(*)=0"> ( to check for empty child elements)
> ----
> </xsl:template>
> be any inefficient ?( was just thinking of other ways to do it
> besides the standard ones you have suggested )

It would be more inefficient (at least with a naive processor) because
the processor would have to visit every child element of the current
node in order to count them. Node visits take time, so avoiding them
is a good idea. On the other hand, that's also the case with a naive
implementation of:

  test="*"

However, most processors will rewrite this test to:

  test="*[1]"

which only involves one node visit. I believe that Saxon rewrites
count(*) = 0 to boolean(*[1]) as well, actually, so perhaps there's
not much in it...

So try it and see with your favourite processor :)

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.