[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: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 20 Mar 2007 15:51:30 +0100
Re:  Universally quantified test of child attribute  pr
Yves Forkl wrote:

1) There are element children, and they all have the attribute.


2) Each of the element children, if any, does not have the attribute.

3) Some element children do have the attribute, some don't.

The solution I have found (thanks again to you and David) is to explicitly couple the existence of children with attribute presence for case 1, then proceed to case 2 where I just test for attribute absence before passing on to the "otherwise" clause representing case 3:

<xsl:choose>
  <xsl:when
    test="* and (every $child in * satisfies $child[@my_attribute])">
  </xsl:when>
  <xsl:when
    test="every $child in * satisfies $child[not(@my_attribute)]">
  </xsl:when>
  <xsl:otherwise>
  </xsl:otherwise>
<xsl:choose>

Relying on the evaluation order of the instructions within xsl:choose spares me from having to use more complicated (or less familiar :-)) test expressions.

Note that for case 2, testing revealed that I can't test for

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


Your second test can be simplified if you make the third test to be your second:


<xsl:when test="*[@my_attribute]">

which will leave your <xsl:otherwise /> to catch what's now in "every $child in ... not(@my..." (you can remove that altogether). Of course, it is a matter of taste. I dislike the 'every' and 'some' expressions, because they tend to be very confusing, even on second read, and especially when used with negation:

<xsl:choose>
 <xsl:when
   test="* and (every $child in * satisfies $child[@my_attribute])">
    <!-- all children have @my_attribute -->
 </xsl:when>
 <xsl:when test="*[@my_attribute]">
     <!-- some children have @my_attribute -->
 </xsl:when>
 <xsl:otherwise>
     <!-- zero children, or none have @my_attribute -->
 </xsl:otherwise>
<xsl:choose>


Cheers, -- Abel Braaksma http://www.nuntia.nl

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.