Re: [xsl] Universally quantified test of child attribute presence/absence

Subject: Re: [xsl] Universally quantified test of child attribute presence/absence
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 20 Mar 2007 13:17:48 +0100
Yves Forkl wrote:

While the expression for the positive test obviously is


every $child in * satisfies $child/@my_attribute

I am unsure about the correct form of the negated expression to mandate that no child may have that attribute. Which variant can or must be used, and why?

every $child in * satisfies $child[not(@my_attribute)]

will return true if no child has a @my_attribute that returns false. I.e., if the value were empty, but available, it would return false.



every $child in * satisfies not($child/@my_attribute)

will return true if no child has a sequence of nodes @my_attribute (alsways one or zero attribute nodes) that when normalized returns false. That is in this scenario effectively the same as above, I believe.



not(every $child in * satisfies $child/@my_attribute)

'every' returns a boolean. You an safely negate it, so this will work. However, note also:



The expression:


empty(*/@my_attribute)

will return true() when there is no child that has an attribute @my_attribute (i.e., in other words, it will return true when the expression returns an empty sequence).

The expression:

every $child in * satisfies $child/@my_attribute

may not return the expected answer when there are no childs at all: it will return true. This is illustrated if you compare the behavior in the following XPath equivalent:

count(*/@my_attribute) = count(*)


Cheers, -- Abel Braaksma

Current Thread