xsl-list
[Top] [All Lists]

Re: check if a node is empty

2002-10-17 09:12:59
Thanks Jeni, I had the same nasty feeling about using the count(*)..
Thanks David and Joerg for your explanation
Vasu





From: Jeni Tennison <jeni(_at_)jenitennison(_dot_)com>
Reply-To: Jeni Tennison <jeni(_at_)jenitennison(_dot_)com>
To: "Vasu Chakkera" <vasucv(_at_)hotmail(_dot_)com>
CC: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] check if a node is empty
Date: Thu, 17 Oct 2002 16:49:00 +0100

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/


_________________________________________________________________
Internet access plans that fit your lifestyle -- join MSN. http://resourcecenter.msn.com/access/plans/default.asp


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



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