xsl-list
[Top] [All Lists]

RE: selecting HTML Options

2005-01-18 02:45:51
Try this:

<xsl:variable name="skeleton">
  <option value="00">JAN</option>
  <option value="01">FEB</option>
  ...
</xsl:variable>

<xsl:template name="monthOptions">
        <xsl:param name="name"/>
        <xsl:param name="value"/>
  <select name="{$name}" 
    <xsl:apply-templates select="$skeleton/option" mode="o">
      <xsl:with-param name="value" select="$value"/>
    </
  </select>
</

<xsl:template match="option" mode="o">
 <xsl:param name="value"/>
 <xsl:copy>
   <xsl:copy-of select="@value"/>
   <xsl:if test="@value=$value">
     <xsl:attribute name="selected">selected</xsl:attribute>
   </xsl:if>
 </xsl:copy>
</xsl:template>

Not much shorter in the end, but perhaps more satisfying. Needs the
xx:node-set extension if using XSLT 1.0.

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Chris_Graham(_at_)aami(_dot_)com(_dot_)au 
[mailto:Chris_Graham(_at_)aami(_dot_)com(_dot_)au] 
Sent: 18 January 2005 04:52
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] selecting HTML Options

There has to be an easier way to select <option> elements inside a 
<select> element that this:

<!-- Generate the Month combo box -->
<xsl:template name="monthOptions">
        <xsl:param name="name"/>
        <xsl:param name="value"/>
<select name="{$name}">

    <xsl:if test="'00' = $value"><option value='00'></option></xsl:if>
    <xsl:if test="not('00' = $value)"><option value='00' selected=
"selected"></option></xsl:if>
    <xsl:if test="'01' = $value"><option 
value='01'>JAN</option></xsl:if>
    <xsl:if test="not('01' = $value)"><option value='01' selected=
"selected">JAN</option></xsl:if>
    <xsl:if test="'02' = $value"><option 
value='02'>FEB</option></xsl:if>
    <xsl:if test="not('02' = $value)"><option value='01' selected=
"selected">FEB</option></xsl:if>

    ...

</select>
</xsl:template>

Can anyone point me in the right direction? I'd rather avoid 
calling java 
directly... :-(

-Chris



**************************************************************
*********************
This email contains information confidential to AAMI Limited. 
If you are not the intended recipient, you must not disclose 
or use the information in it. If you have received this email 
in error, please notify us immediately by return email, and 
delete this email and any attached documents.
AAMI Limited is not responsible for any changes made to a 
document other than those made by AAMI Limited or for the 
effect of the changes on the document meaning.
**************************************************************
*********************


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>