Counting 'empty' nodes

dd

Usenet Archive
Joined
Jan 19, 2000
Messages
184
Reaction score
0
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the <xsl:template select="????"> I tried count(//quick/*) >0 which returns false...

<?xml version="1.0" encoding="UTF-8"?>
<dffob>
<destinations>
<dest>
<quick/>
</dest>
<dest>
<quick>yes</quick>
</dest>
</destinations>
</dffob>
 

Bjoern Hoehrmann

Usenet Archive
Joined
Aug 15, 2000
Messages
719
Reaction score
0
* dd wrote in comp.text.xml:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the <xsl:template select="????"> I tried count(//quick/*) >0

* only matches element nodes while "yes" is a text node. You can

count(//quick/text)

But that would also count

<quick> </quick>

So

count(//quick[.="yes"])

might be better.
 

dd

Usenet Archive
Joined
Jan 19, 2000
Messages
184
Reaction score
0
Bjoern said:
* dd wrote in comp.text.xml:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the <xsl:template select="????"> I tried count(//quick/*) >0

* only matches element nodes while "yes" is a text node. You can

count(//quick/text)

But that would also count

<quick> </quick>

So

count(//quick[.="yes"])

might be better.
Tried this also:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:apply-templates select="count(//quick[. ='yes'])"/> </xsl:template>

</xsl:stylesheet>

Oxygen returns: value is not a node set
 

dd

Usenet Archive
Joined
Jan 19, 2000
Messages
184
Reaction score
0
dd said:
Bjoern said:
* dd wrote in comp.text.xml:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the <xsl:template select="????"> I tried count(//quick/*) >0

* only matches element nodes while "yes" is a text node. You can

count(//quick/text)

But that would also count

<quick> </quick>

So

count(//quick[.="yes"])

might be better.

Tried this also:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:apply-templates select="count(//quick[. ='yes'])"/> </xsl:template>

</xsl:stylesheet>

Oxygen returns: value is not a node set

Sorry, seems that count(//quick[. = 'yes']) does work.

Many thanks.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
dd said:
Bjoern said:
* dd wrote in comp.text.xml:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the <xsl:template select="????"> I tried count(//quick/*) >0

* only matches element nodes while "yes" is a text node. You can

count(//quick/text)

But that would also count

<quick> </quick>

So

count(//quick[.="yes"])

might be better.

Tried this also:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:apply-templates select="count(//quick[. ='yes'])"/>

Well you need
<xsl:value-of select="count(//quick[. ='yes'])"/>
if you want to output the value. xsl:apply-templates tries to apply templates against the select attribute value and that has then indeed to be a nodeset.
 

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

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top