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

Re: Testing if all child nodes match (based on the val

Subject: Re: Testing if all child nodes match (based on the value of certain elements)
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 23 Apr 2007 23:02:00 +0200
Re:  Testing if all child nodes match (based on the val
Mark Anderson wrote:
Hi All

I'm stuck with trying to figure something out in an XSL style sheet. I
can't post may actual data, as it's confidential, so I've made up an
example:

<group>
	<person>
		<name>John</name>
		<age>42</age>
		<sex>M</sex>
		marital_status>S<marital_status>
<snip />

What I want to do is find out if the group contains all people of the
same sex and age (in this case it does). So in my example xml structure,
for every person in the group <age> and <sex> must be the same (but I've
no idea what their values will be at run time: i.e. I can't check if age
is '42' and sex = 'M').
The problem is usually in the '=' operator (thinking positive): in XLST, if one item in the left side sequence and one item in the right side sequence equal, the whole expression returns true. The trick is to reverse it: with the '!=' (think negative: think what you don't want and then reverse it), which means: if one item on the left side is sequence is unequal to any item in the right side sequence, the whole expression returns false:

(: returns false precisely when you want true() to return :)
group/person/sex !=group/person/sex

(: reverse the result :)
not(group/person/sex !=group/person/sex)

and *and* it together with the rest:

(: full expression :)
not(group/person/sex !=group/person/sex) and
not(group/person/age !=group/person/age)

Cheers,
-- Abel Braaksma

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.