[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Universally quantified test of child attribute pr

Subject: Re: Universally quantified test of child attribute presence/absence
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Tue, 20 Mar 2007 14:07:49 +0100
Re:  Universally quantified test of child attribute  pr
Abel,

you wrote:

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

OK, so I could (as well) use this expression for the "negative case", or stick with the easiest understandable variant, like David suggested:


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


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. [...]

Thank you very much for this hint - I actually need a test that returns true if all children carry the attribute AND if there are element children at all - maybe David's suggestion might help? (See below.)



David,


you wrote:

> 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)])

Not bad either. Could I even use this expression to return false when there are no element children at all? Or would I have to make this an additional condition?


> which is also valid xpath 1 of course. > This would make your "negative" test > exists(*[not(@my_attribute)]

Nice and neat.


> 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)]"

Like I (partially) wrote, I prefer to leave the condition equalling this third case implied in my xsl:otherwise clause, while explicitly testing for the other two cases using xsl:when.

I am grateful to both of you for your precise explanations.

Yves


P.S.: It seems that in XSLT just as well as in life, being negative often is much easier than being positive. :-)


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.