xsl-list
[Top] [All Lists]

Re: Finding parent of the middle child

2005-06-20 15:52:55

  (//rec_gear_sec/*)[$gearMid] is returning the very first child, even
  though $gearMid returns 34. I wasn't even sure if that syntax would be
  allowed in 1.0.

This is a FAQ.

The expression is equivalent to //rec_gear_sec/* and selects _all_ such
elements not just the first (as you would see if you used xsl:copy-of
xsl:value-of always discards all but the first node.

The predicate [$gearMid] is the same as [true()] so doesn't filter
anything as a result tree fragment acts teh same way in a predicate as
a node set, that is  a node set counts as true if it is non-empty and
false if it is empty. Result tree fragments always correspnd to node
sets with exactly one node (a root node) so always count as true in a
boolean context.


<xsl:variable name="gearMid">
        <xsl:value-of select="round(count(//rec_gear_sec/*) div 2)"/>
</xsl:variable>

is a result tree fragment with a root node and a text node with string
vakue the decimal represntation of the number. You don't want that, you
want the number, which is


<xsl:variable name="gearMid">
 select="round(count(//rec_gear_sec/*) div 2)"/>

If $gearMid is a number defined like this [] will be a numeric predicate
rather than a boolean one.

David



________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
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>
--~--