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

Subject: Re: [xsl] Universally quantified test of child attribute presence/absence
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 20 Mar 2007 12:19:47 GMT
the simplest way of negating an expression is to put not around it so if 

every $child in * satisfies $child[@my_attribute]

is the positive test

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

is the negative test, and if that's the simplest for you to grock later
than that's what I'd use.

Personally I'd have probably written the "positive test" in negative
form, rather than saying every chiuld has teh attribute, say no child
doesn't have the attribute
not(*[not(@my_attribute)])
which is also valid xpath 1 of course.
This would make your "negative" test
exists(*[not(@my_attribute)]

Your other two expressions are valid but mean something else.

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


are true if every element does not have the attribute.





However none of the tests seem to capture what you say in english

>  all of its element children carry a specific attribute or if they don't. A 
> mixed situation is to be considered as a fatal error, caught in an 
> xsl:otherwise clause.

the tests you show test that all the elements have or dont have the
attribute, but only test for one or the other, they don't test for the
mixed case.
The most direct test for the mixed test is just to test
test="*[@my_attribute] and *[not(@my_attribute)]"


David

Current Thread