Re: [xsl] Getting variable yet most immediate parentNode

Subject: Re: [xsl] Getting variable yet most immediate parentNode
From: Steve <subsume@xxxxxxxxx>
Date: Fri, 28 Sep 2007 11:26:30 -0400
>Abel Braaksma <> wrote:
> which means that <xsl:template match="option" mode="q">... will never be
> triggered by this snippet:
>     <xsl:template match="questions">
>         <xsl:apply-templates mode="q" select="option" />
>         <SNIP />
>     </xsl:template>

Yep, that's my fault. Questions do have option children. My mistake.

> Steve, if you rewrite statements like that as this one above as:
>     <xsl:template match="answers[option]">
>        ....

Ahh, yes. Wise and simple, thank you. Done.

> Wendell, considering the possible intent of Steve to wrap all output
> inside one <div>, it is probably better if he does go back to using the
> // syntax, but not in the way I proposed, but more like this (assuming

I think we've gone awry. .//answer's doesn't make sense because, as
Wendell pointed out, I want to go up the tree if there is no child
<answers />. I tried his syntax, however I'm not sure how to make it
choose a child answer's node before it goes looking for the closest
ancestral answer node (without using those pesky case statements).

> <xsl:template match="option">
>     <option><xsl:value-of select="(@name | .)[1]" />
> </xsl:template>

And finally, this last shortcut doesn't function. My logic is "If it
has a @name, use it, otherwise just use the node's text." I'm honestly
not sure how to interpret this shortcut because the "|" seems to imply
union, which of course doesn't seem to fit my intentions. At any rate,
this statement never spits out question <option>s with @name.

I'm assuming much of the confusion over what I am attempting is my
fault, and particularly my pasting a slightly incomplete source XML.
Here is an actual example.

		<section key="D" name="Nutritional status">
				<option key="A" name="Does client have prescribed diet by physician?" />
				<option key="C" name="Do you have a good appetite?" />
				<option key="K" name="Daily fluid intake per cups?">
						<option p="1">1</option>
						<option p="2">2</option>
						<option p="3">3</option>
						<option p="4">4</option>
						<option p="5">5</option>
				<option key="J" name="Weight">
						<option p="1">Underweight</option>
						<option p="2">Overweight</option>
						<option p="0">Normal</option>
				<option key="L" name="Taking vitamin/mineral supplements?" />
					<option p="1">5</option>
					<option p="2">1</option>
					<option p="3">1.5</option>
					<option p="4">2</option>
					<option p="5">3</option>
					<option p="6">4 or more</option>
				<option key="D" value="POULTRY">Servings of meat, fish, eggs,
dried peas, beans and nuts</option>
				<option key="E" value="FRUIT">Servings of citrus fruit, juices and
				<option key="F" value="GREENVEG">Servings of dark green, leafy
				<option key="G" value="VEG">Servings of other fruits, vegetables
and juices</option>
				<option key="H" value="STARCH">Servings of bread, cerea, rice,
				<option key="I" value="DAIRY">Servings of dairy products</option>
				<option key="J" value="MISC">Servings of Misc. foods</option>

Current Thread