Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL Drop Down Box

Status
Not open for further replies.

Jyme

MIS
Apr 28, 2004
29
US
Im trying to compare 2 elements..if they are equal Id like to have the "selected" attribute added to the option tag for the drop down list..the tags are infoscreening and screeningid...heres what I have so far, which doesnt work...

<xsl:element name="select">
<xsl:element name="option"></xsl:element>
<xsl:for-each select="./wholist/who">
<xsl:element name="option">
<xsl:if test="infoscreening = screeningid">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:attribute name="value"><xsl:value-of select="screeningid"/></xsl:attribute>
<xsl:value-of select="name"/>
</xsl:element>
</xsl:for-each>
</xsl:element>

 
nevermind I figured it out..use an xsl:parameter element outside the template

<xsl:param name="infoscreening"><xsl:value-of select="conscreening/infoscreening" /></xsl:param>

<xsl:element name="select">
<xsl:element name="option">
<xsl:attribute name="value">0</xsl:attribute>
</xsl:element>
<xsl:for-each select="./wholist/who">
<xsl:element name="option">
<xsl:if test="screeningid = $infoscreening">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:attribute name="value"><xsl:value-of select="screeningid"/></xsl:attribute>
<xsl:value-of select="name"/>
</xsl:element>
</xsl:for-each>
</xsl:element>

 
You could do it a lot more concisely:
Code:
<select>
  <option value="0"/>
  <xsl:for-each select="wholist/who">
    <option value="{screeningid}">
      <xsl:if test="screeningid = ../../conscreening/infoscreening">
        <xsl:attribute name="selected">selected</xsl:attribute>
      </xsl:if>
    </option>
  </xsl:for-each>
</select>

Jon

"I don't regret this, but I both rue and lament it.
 
Oops:
Code:
<select>
  <option value="0"/>
  <xsl:for-each select="wholist/who">
    <option value="{screeningid}">
      <xsl:if test="screeningid = ../../conscreening/infoscreening">
        <xsl:attribute name="selected">selected</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="name"/>
    </option>
  </xsl:for-each>
</select>

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top