xsl-list
[Top] [All Lists]

Re: [xsl] Only child test

2013-10-10 09:21:11
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>