[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: dynamically setting 'selected' in option tag

Subject: Re: dynamically setting 'selected' in option tag
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 13 Apr 2000 17:16:27 +0100
html select setting selected
Okay Aaron,

At 08:58 AM 4/13/00 -0700, you wrote:
>Does anyone know what the easiest way to trigger 'selected='true''
>dynamically....

>XML:
><DATA>
><STATE>1</STATE>
></DATA>
...
>HTML:
> <SELECT name="state" size="1">
>  <OPTION value="1" selected>AK</OPTION>
>  <OPTION value="2">AZ</OPTION>
></SELECT>

...it depends on what you mean by "easiest," but try this (a complete
stylesheet):

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="states" select="'AKALAZMDNJWVWY'"/>
<!-- Put all fifty states in this list.
     Processing assumes each state has a two-letter abbreviation. -->

<xsl:variable name="statesinunion" select="7"/>
<!-- The number of states you have.
     Change this to '50' when you have all fifty states. -->

<xsl:variable name="selectedstate" select="DATA/STATE"/>
<!-- This assigns the node to the variable. -->

<xsl:template match="/">
  <SELECT name="state" size="1">
    <xsl:call-template name="USTour"/>
  </SELECT>
</xsl:template>

<xsl:template name="USTour">
  <xsl:param name="statestogo" select="$states"/>
  <xsl:if test="$statestogo">
    <xsl:variable name="thisstate"
      select="($statesinunion+1) - (string-length($statestogo) div 2)"/>
    <OPTION value="{$thisstate}">
      <xsl:if test="$thisstate = $selectedstate">
        <xsl:attribute name="selected">true</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="substring($statestogo, 1, 2)"/>
    </OPTION>
    <xsl:call-template name="USTour">
      <xsl:with-param name="statestogo"
        select="substring($statestogo, 3)"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

Regards,
Wendell (possibly outdoing himself in perverseness)


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.