Subject: Re: dynamically setting 'selected' in option tag From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 13 Apr 2000 17:16:27 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
dynamically setting 'selected' in o, Aaron Pekrul | Thread | RE: dynamically setting 'selected' , Michael Chu |
RE: RE: Attribute test problem solv, Wendell Piez | Date | Re: Attribute test problem solved, David Carlisle |
Month |