[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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::*)) > 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|