Union and descendants: count(.//name1|name2) ? Doesn't perform Union?

Subject: Union and descendants: count(.//name1|name2) ? Doesn't perform Union?
From: Joshua Gough <exv@xxxxxxxxxxx>
Date: Mon, 12 Jul 1999 19:13:12 -0400 (EDT)
Hi, 
  I've run into a problem using LotusXSL 0.17.3 as well as the 7/08
release of XT with the use of .// or // in conjunction with the |
operator.

For example:

count(.//entry|e) 

Returns only the number of "entry" elements without adding the number of e
matches to the result. 

Similarly,

count(.//e|entry) 

returns the number of e.

However:

count(./e|entry) 

Works fine, counting both, when in fact the context node contains those
children.  I figured that the former would work the same way with the |
operator. 

I can achieve the desired result using this long-winded syntax:

count(//*[qname() = 'entry' or qname() = 'e'])

But, I still figure the | operator should work. Can someone explain why
this is not so?

Here is some quick copy and paste sample code to see the results:

XML:

<?xml version="1.0"?>
<!DOCTYPE Section >
<Section>
  <SubSection>
   <entry>Blah</entry>
   <e>Blah as well</e>
   <entry>BLar blah</entry>
   <entry>Blahsdfdsafs </entry>
  </SubSection>
</Section>


XSL:

<?xml version="1.0"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
       xmlns:lxslt="http://xsl.lotus.com/";
       xmlns="http://www.w3.org/TR/REC-html40";			
       result-ns=""
>

<xsl:template match="/">
<h2>| operator and .// ?</h2>
<p>

The total number of e and entry (e|entry) in this document is:
<xsl:value-of select="count(//e|entry)" /><br />
The total number of entry and e (entry|e) in this document is:
<xsl:value-of select="count(//entry|e)" /><br />
Using //*[qname() = 'entry' or qname() = 'e'], the total is: <xsl:value-of
select="count(//*[qname() = 'entry' or qname() = 'e'])" /><br />

<br />

<xsl:for-each select="//*[not (qname() = 'entry') and not (qname() = 'e')
]">
	Name: <xsl:value-of select="qname(.)" /><br />
	Descendants <b>count(.//e|entry)</b>: <xsl:value-of
select="count(.//e|entry)" /><br />
	Descendants <b style="background: beige">count(.//entry|e)</b>:
<xsl:value-of select="count(.//entry|e)" /><br />
	Children <xsl:value-of select="count(./e|entry)" /><br />
	<br />
</xsl:for-each>

</p>

</xsl:template>

</xsl:stylesheet>


Text Output:

| operator and .// ?

The total number of e and entry (e|entry) in this document is: 1
The total number of entry and e (entry|e) in this document is: 3
Using //*[qname() = 'entry' or qname() = 'e'], the total is: 4

Name: Section
Descendants count(.//e|entry): 1
Descendants count(.//entry|e): 3
Children 0

Name: SubSection
Descendants count(.//e|entry): 4
Descendants count(.//entry|e): 4
Children 4


(I don't understand why the .// actually works once it got into SubSection
either)

Thanks,

Josh Gough



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


Current Thread