Re: [xsl] how to populate drop down list

Subject: Re: [xsl] how to populate drop down list
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Fri, 22 Mar 2002 15:34:59 -0500
[Uslu, Cihan Y (MED)]

> I want that list 5 times(there are 5 answers in XML snippet) to repeat,
> so that I can choose the correct match attribute from drop down list for
> each answer. That's why I was trying to use <xsl:for-each> to wrap the
> <select> element. With the current code I get it only once.
>
> This is how I want:
>
> ----------------------------------------------------------------
> Drop-Down List( has all the match attributes in it) A. This is
> Answer 1
> Drop-Down List( has all the match attributes in it) B. This is
> Answer 2
> Drop-Down List( has all the match attributes in it) C. This is
> Answer 3
> Drop-Down List( has all the match attributes in it) D. This is
> Answer 4
> Drop-Down List( has all the match attributes in it) E. This is
> Answer 5
> ---------------------------------------------------------------

I think you could stand some redesign in the structure of your xml source.
However here's how you can do it with your current source(you still need to
come up with some way name the select elements so you know which one applies
to which question):

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method='html' encoding='iso-8859-1'/>

<xsl:template match="/">
   <!-- Process each question -->
    <xsl:apply-templates select='question'/>
</xsl:template>

<!-- Handle each question -->
<xsl:template match='question'>

    <!--Create the list of options to be used for each answer -->
    <xsl:variable name='answers'>
    <xsl:for-each select='answer/@match'>
        <option value='{.}'><xsl:value-of select='.'/></option>
    </xsl:for-each>
 </xsl:variable>

    <!-- Create the select element for each answer -->
    <xsl:for-each select='answer'>
        <xsl:value-of select='para'/><br/>
        <select><xsl:copy-of select='$answers'/></select><br/><br/>
    </xsl:for-each>

</xsl:template>
</xsl:stylesheet>

Tom P


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread