Counting 'empty' nodes

D

dd

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>
 
B

Bjoern Hoehrmann

* 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.
 
D

dd

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
 
D

dd

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.
 
M

Martin Honnen

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
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top