[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: dynamically setting 'selected' in option tag


Subject: RE: dynamically setting 'selected' in option tag
From: Kevin Williams <Kevin.Williams@xxxxxxxxxxxxxx>
Date: Thu, 13 Apr 2000 13:59:38 -0400

> -----Original Message-----
> From: Aaron Pekrul [mailto:apekrul@xxxxxxxxxxx]
> Sent: Thursday, April 13, 2000 11:59 AM
> To: XSL-List@xxxxxxxxxxxxxxxx
> Subject: dynamically setting 'selected' in option tag
> 
> Does anyone know what the easiest way to trigger 'selected='true''
> dynamically.  The XML has a code from one to fifty to 
> represent one of the
> US states and I simply want to set 'select='true'' for this 
> value.  There
> must be an easier way than the code I have below for just two states.
> thanks.

Aaron,

You could use xsl:element and xsl:attribute to "build" the OPTION element,
rather than expressing it directly as a string. In other words, you could do
something like this:

<xsl:element name="OPTION">
  <xsl:attribute name="value">1</xsl:attribute>
  <xsl:if test="DATA/STATE='1'">
    <xsl:attribute name="selected">true</xsl:attribute>
  </xsl:if>
  <xsl:text>AK</xsl:text>
</xsl:element>

(repeat for next 49 states)

Still not great, but maybe a little better than what you've got at the
moment. Plus, if you're using XSLT, you could add another document that maps
numbers to state abbreviations, and then you could do something fancy using
xsl:document that wouldn't require a brute-force element block repeated 50
times...

- Kevin

Kevin Williams
XML Architect
Ultraprise Corporation
kwilliams@xxxxxxxxxxxxxx


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



Current Thread
Keywords