Subject: Re: [xsl] Testing if all child nodes match (based on the value of certain elements) From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 23 Apr 2007 16:53:06 -0400 |
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: ... 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').
I've puzzled over this for some hours with no luck.
t:\ftemp>type anderson.xml <group> <person> <name>John</name> <age>42</age> <sex>M</sex> <marital_status>S</marital_status> </person> <person> <name>Fred</name> <age>42</age> <sex>M</sex> <marital_status>W</marital_status> </person> <person> <name>Harry</name> <age>42</age> <sex>M</sex> <marital_status>M</marital_status> </person> <person> <name>Brian</name> <age>42</age> <sex>M</sex> <marital_status>S</marital_status> </person> </group>
t:\ftemp>type anderson2.xml <group> <person> <name>John</name> <age>42</age> <sex>M</sex> <marital_status>S</marital_status> </person> <person> <name>Fred</name> <age>42</age> <sex>M</sex> <marital_status>W</marital_status> </person> <person> <name>Harry</name> <age>42</age> <sex>M</sex> <marital_status>M</marital_status> </person> <person> <name>Brian</name> <age>41</age> <sex>M</sex> <marital_status>S</marital_status> </person> </group>
t:\ftemp>type report.txt All the same! t:\ftemp>call xslt anderson2.xml anderson.xsl report.txt
t:\ftemp>type report.txt Not all the same! t:\ftemp>type anderson.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:choose> <xsl:when test="not( group/person/age != group/person/age ) and not( group/person/sex != group/person/sex )"> <xsl:text>All the same!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>Not all the same!</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template>
</xsl:stylesheet> t:\ftemp>rem Done!
-- World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Testing if all child nodes ma, Mark Anderson | Thread | RE: [xsl] Testing if all child node, Michael Kay |
[xsl] Testing if all child nodes ma, Mark Anderson | Date | Re: [xsl] Testing if all child node, David Carlisle |
Month |