RE: [xsl] Dropdown

Subject: RE: [xsl] Dropdown
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 22 Oct 2002 13:58:30 -0400
[ Juan Carlos Gonzalez]
> I'm trying to create a drop down list box dynamically,
> but I'm getting an error message cause the "select"
> tag is not being closed within the "if" tag. I have
> tried replacing the < and > sign with the &lt; and
> &gt; but it's still not working. Any ideas? 
> <xsl:if test="some condition">
>   <select name="cat">
> </xsl:if>
> ...the folowing template will create the options tag
> amoung other things ...
> <xsl:apply-templates select="cat"/>
> <xsl:if test="some condition">
>   </select>
> </xsl:if>

You must complete and close the select element within the xsl:if
element. Remember that the stylesheet has to be well-formed xml.   If
you think that you need to do something else, you have not understood
your problem thoroughly enough yet.  If you explain what you really wish
to accomplish, we will be able to help you with it.

For example, if you want to create a select element, then you surely
will want to create options inside it.  If you want to create the select
list only if there are any cat elements, and have one option per cat,
then you could write (assuming that the "cat" element contains the name
of the cat as character data)

<xsl:if test='cat'> <!-- executed if there are any "cat" child elements
	<select name='cat'>
		<xsl:for-each select='cat'>
			<option value='{.}'><xsl:value-of

If you specify an xsl:output method of 'html', the output will be in
ordinary html (rather than in xml), and the options will come out
looking like normal html options:

<option value='Mary'>Mary

You could also use apply-templates instead of the for-each, which might
be better if you have more complex processing to do in constructing the
options.  In this case, you would build the options in the template for
"cat" rather than as shown here.


Tom P

 XSL-List info and archive:

Current Thread