xsl-list
[Top] [All Lists]

Re: Finding parent of the middle child

2005-06-20 15:00:45
On Mon, 2005-06-20 at 13:21 -0700, Brook Ellingwood wrote:
I'm having a hard time breaking a list of nested elements into a
two-column layout in HTML output.

There are several section elements containing a variable number of
child elements. I want to return a count of all the child elements and
identify the mid point of all the child elements. At the top of my
XSL, I do this with:

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

This returns "34."

Next, I want to identify which parent element contains the child at
position 34, so I can split the list beginning with the following
sibling. However, I can't even get as far as finding the matching
child when I try a similar method to returning the count:

<xsl:variable name="gearSplit">
      <xsl:value-of select="//rec_gear_sec/*[position() = $gearMid]"/>
</xsl:variable>

That returns nothing. When I substitute numbers for the variable, I
discover that it's matching the first child element at that position
*within its parent element* not within the list of all child elements.
Even though this is behavior that I've used and expected in the past,
I'm now confused as to why the context is interpreted differently for
those two matches.

Quick pointer. version="2.0", right?

What you're looking for is:

(//rec_gear_sec/*)[$gearMid]

I also, against my better judgement, found it tempting to disbelieve the
spec about dynamic context sometimes until I realized how easy it is to
manipulate sequences.

sdc



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