0
votes

I cannot figure out how to correctly use XSLT to generate HTML with a named input dropdown box (needed for reference within a form).

This is a simplified example of what I'm trying to do, assuming the select element is to be named "foo" - my actual need is to set the name from an attribute in the incoming XML.

<xsl:template match="category">
    <form id="searchform" action="resultsPage" method="get">
        <xsl:if test="position()=1">
            <input type="submit"/>
        </xsl:if>
        <xsl:variable name="x">foo</xsl:variable>
        <select name="$x">
            <option>*</option>
            <xsl:for-each select="item">
                <option><xsl:value-of select="@code"/></option>
            </xsl:for-each>
        </select>
    </form>  
</xsl:template>

I know this isn't the correct syntax - I'm pretty new to XSLT and am just trying to illustrate what I need here, which is a dynamically-named select element. Everything I've tried just sets the name to the literal string I am trying to use as a variable. Thanks.

1
Use attribute value template. - Sean B. Durkin

1 Answers

1
votes

Use curly brackets ({}) to get the XSL variable evaluated in place of attribute value :

<select name="{$x}">
    <option>*</option>
    <xsl:for-each select="item">
        <option><xsl:value-of select="@code"/></option>
    </xsl:for-each>
</select>