xsl-list
[Top] [All Lists]

Re: [xsl] Getting variable yet most immediate parentNode

2007-09-28 08:27:02
Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl> 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.

<root>
                <section key="D" name="Nutritional status">
                        <questions>
                                <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?">
                                        <answers>
                                                <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>
                                        </answers>
                                </option>
                                <option key="J" name="Weight">
                                        <answers>
                                                <option 
p="1">Underweight</option>
                                                <option 
p="2">Overweight</option>
                                                <option p="0">Normal</option>
                                        </answers>
                                </option>
                                <option key="L" name="Taking vitamin/mineral 
supplements?" />
                        </questions>
                        <questions>
                                <answers>
                                        <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>
                                </answers>
                                <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
tomatoes</option>
                                <option key="F" value="GREENVEG">Servings of 
dark green, leafy
vegetables</option>
                                <option key="G" value="VEG">Servings of other 
fruits, vegetables
and juices</option>
                                <option key="H" value="STARCH">Servings of 
bread, cerea, rice,
pasta</option>
                                <option key="I" value="DAIRY">Servings of dairy 
products</option>
                                <option key="J" value="MISC">Servings of Misc. 
foods</option>
                        </questions>
                </section>
</root>

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