Counting Empty nodes - xsl

A

anonymous

Given a sample like the one below, how can I count the number of
elements <quick> with the value 'yes'. When processing the //quick
nodes I can easily find out if they are 'empty' but I need to write a
select pattern to see if any of them is not 'empty'. In the below
example the result should be '1' for the <quick>yes</quick> element
and '2' for the total count of <quick> elements. I tried various
implementations of
<xsl:value-of select="count(//sub[quick='yes'])"/> and the like,
including node() stuff (not allowed in patterns), but the, probably
simple, solution simply eludes me.

<?xml version="1.0" encoding="UTF-8"?>
<anything>
<sub>
<quick/>
</sub>
<sub>
<quick>yes</quick>
</sub>
</anything>
 
F

fpmurphy

anonymous said:
*Given a sample like the one below, how can I count the number of
elements <quick> with the value 'yes'. When processing the //quick
nodes I can easily find out if they are 'empty' but I need to writ
a
select pattern to see if any of them is not 'empty'. In the below
example the result should be '1' for the <quick>yes</quick> element
and '2' for the total count of <quick> elements. I tried various
implementations of
<xsl:value-of select="count(//sub[quick='yes'])"/> and the like,
including node() stuff (not allowed in patterns), but the, probably
simple, solution simply eludes me.

<?xml version="1.0" encoding="UTF-8"?>
<anything>
<sub>
<quick/>
</sub>
<sub>
<quick>yes</quick>
</sub>
</anything>
-
fpmurph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top