RE: [xsl] Finding parent of the middle child

Subject: RE: [xsl] Finding parent of the middle child
From: "Brook Ellingwood" <belling@xxxxxxx>
Date: Wed, 22 Jun 2005 17:25:09 -0700
Recap: 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. I then want to split the
parent section elements after the parent containing the middle child.

I have this working on my local machine using MSXML, but it fails when I
convert it on the staging servers using Xalan Java 2.4.1 and I'm stumped.

Relevant XSL:
<xsl:variable name="gearMid"
select="generate-id((//rec_gear_sec/*)[round(count(//rec_gear_sec/*) div

<xsl:template name="rec_gear_list">
	<xsl:for-each select="//rec_gear_sec/*">
		<xsl:if test="generate-id(.) = $gearMid">
			<xsl:variable name="splitPoint" select="count(../preceding-sibling::*)
			<div style="width:275; float:left;padding-right:10px;">
				<xsl:apply-templates select="//*[position() &lt; $splitPoint and
				<xsl:apply-templates select="parent::*"/>
			<div style="width:285; float:right;">
				<xsl:apply-templates select="//*[position() &gt; $splitPoint and

That for-each is probably a little inefficient, but the real problem is the
output. In Xalan it gets the group in the first div right, but in the second
div it gives me *all* the rec_gear_sec elements, not just the ones with a
position() greater than $splitPoint. It seems like this is a bug, and I could
really use a workaround. I've already spent far more time on this one than it
deserves. Any ideas?

-- Brook

Sample XML:

		<rec_gear_title>Official Papers</rec_gear_title>
		<rec_gear>Valid passport and visas</rec_gear>
		<rec_gear>Airline tickets</rec_gear>
		<rec_gear>International health card with immunizations</rec_gear>
		<rec_gear>Midweight wool or fleece jacket/sweater</rec_gear>
		<rec_gear>Wool or fleece pants</rec_gear>
		<rec_gear>Midweight thermal underwear top and bottom, synthetic</rec_gear>
		<rec_gear>Expedition weight thermal underwear top and bottom,
		<rec_gear>T-shirts, mix of synthetic and cotton</rec_gear>
		<rec_gear>Long-sleeve synthetic shirts</rec_gear>
		<rec_gear>Synthetic, quick-drying hiking shorts</rec_gear>
		<rec_gear>Synthetic, quick-drying hiking pants</rec_gear>
		<rec_gear>Hiking socks - wool and/or synthetic</rec_gear>
		<rec_gear>Liner socks</rec_gear>
		<rec_gear>Waterproof, breathable jacket</rec_gear>
		<rec_gear>Waterproof, breathable pants</rec_gear>
		<rec_gear>Insulated down or synthetic filled jacket</rec_gear>
		<rec_gear>Wind jacket and/or pants (optional) </rec_gear>
		<rec_gear>Water-resistant leather hiking boots, midweight boots work
		<rec_gear>Camp shoes - sneakers or sport sandals</rec_gear>
		<rec_gear_title>Clothing Accessories</rec_gear_title>
		<rec_gear>Balaclava or neck gaiter</rec_gear>
		<rec_gear>Wool or fleece mittens/gloves</rec_gear>
		<rec_gear>Thin gloves or mitten liners</rec_gear>
		<rec_gear>Wool or fleece hat</rec_gear>
		<rec_gear>Gaiters, knee-length</rec_gear>
		<rec_gear>Sun hat </rec_gear>
		<rec_gear_title>City Clothing</rec_gear_title>
		<rec_gear>Bring a few lightweight, easily washable items for travel and when
you are not climbing</rec_gear>
		<rec_gear>Comfortable shoes</rec_gear>
		<rec_gear_title>Travel Accessories</rec_gear_title>
		<rec_gear>Water bottles (two 1-quart) or a hydration system plus one 1 qt.
water bottle</rec_gear>
		<rec_gear>Headlamp and spare lithium batteries/bulb (no
		<rec_gear>Sunglasses with dark lenses</rec_gear>
		<rec_gear>Ski goggles</rec_gear>
		<rec_gear>Toilet paper (1 roll)</rec_gear>
		<rec_gear>Hand sanitizer gel</rec_gear>
		<rec_gear>Collapsible trekking poles</rec_gear>
		<rec_gear>Favorite energy snacks and powdered drinks</rec_gear>
		<rec_gear>Sunblock and lip balm with high SPF</rec_gear>
		<rec_gear>Toiletry kit</rec_gear>
		<rec_gear>Small bath towel</rec_gear>
		<rec_gear>Bio-degradable soap/shampoo</rec_gear>
		<rec_gear>Personal first-aid kit</rec_gear>
		<rec_gear>Rain cover and two large plastic trash bags for your daypack and
duffel bag </rec_gear>
		<rec_gear_title>Field Gear</rec_gear_title>
		<rec_gear>Sleeping bag rated to 100F or less </rec_gear>
		<rec_gear_title>Optional Field Gear</rec_gear_title>
		<rec_gear>Camera, lenses and lots of film</rec_gear>
		<rec_gear>Small binoculars (highly recommended)</rec_gear>
		<rec_gear>Reading and writing materials</rec_gear>
		<rec_gear>Watch with alarm or travel clock</rec_gear>
		<rec_gear>Folding-style umbrella</rec_gear>
		<rec_gear>Water filter equipment or iodine tablets (bottled water available
for purchase)</rec_gear>
		<rec_gear>Insect repellent with DEET</rec_gear>
		<rec_gear>Spare contact lenses or prescription glasses</rec_gear>
		<rec_gear>Ziploc bags, to protect camera, binoculars, etc. from
		<rec_gear>2 duffel bags, 1 large enough for all climbing gear and clothing
and a second bag with non climbing items to be left at the hotel</rec_gear>
		<rec_gear>Luggage tags and luggage locks</rec_gear>
		<rec_gear>Passport pouch or money belt</rec_gear>
		<rec_gear>Daypack, 2000-3000 cu. in. to be used during climb</rec_gear>

Current Thread