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

Re: Only child test

Subject: Re: Only child test
From: Liam R E Quin <liam@xxxxxx>
Date: Thu, 10 Oct 2013 10:20:42 -0400
Re:  Only child test
On Wed, 2013-10-09 at 21:38 -0700, Karl Stubsjoen wrote:
> Just curious how other's might approach a test to determine if the
> current node is *not* an only child. This works fine but it feels a
> little heavy to me.  Thoughts?
> 
>                 <xsl:if test="(count(preceding-sibling::*) +
> count(following-sibling::*)) &gt; 1">
>                     <hr/>
>                 </xsl:if>

I'd write, preceding-sibling::* or following-sibling::*, probably,
because (for me) it's closest to conveying the idea.

I'd avoid "cleverness" like ../*[2] unless there were performance
problems, because I'd come back to that a year later and stare at it
wondering about that two. So rather than that I'd write a function like
has-siblings(.) as xs:boolean that could use count($input/../*[2]) > 1.

But my approach to programming is like a science experiment: try to make
as clear as possible what is done and why, on the grounds that it will
need not be changed later. This is not a mathematician's approach, who
will prove it correct (for the stated requirements and conditions at the
time) and move on with life :-)

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

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.