Re: [xsl] matching input value to a node

Subject: Re: [xsl] matching input value to a node
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 29 Apr 2001 13:59:49 +0100
Hi Tanz,

> e.g. <td bgcolor="#FFFFFF">
>            <div>
>             <input size="55" name="orgname" type="text" maxlength="200"
> value=<xsl:value-of select="organisation"/>> </input> <!-- here is the
problem-->>
>              </div>
> This obviously does not work.

Whenever you find yourself wanting to put an xsl:value-of as the value
of an attribute, use an attribute value template instead.  If you wrap
an expression within {}s in an attribute value, then that expression
is evaluated, and the result is inserted into the attribute value.  So
use:

  <input size="55" name="orgname" type="text" maxlength="200"
         value="{organisation}" />

You can use xsl:attribute instead, but there's no point unless you
like typing a lot:

  <input size="55" name="orgname" type="text" maxlength="200">
     <xsl:attribute name="value">
        <xsl:value-of select="organisation" />
     </xsl:attribute>
  </input>

[Note: If you find the latter works and the former doesn't, then
you're using an old version of MSXML.]

> 2. From a drop down list /menu - I want to ensure that the top value
> displayed is equal to the node.
> e.g.
>  <select name="droptypeoforg">
>                               <option value="org 1"> Org 1</option>
>                               <option value="org 2">Org 2</option>
>                              --------------
>                              <option value="other">Other (specify)</option>
> </select>
>
> So that the <xsl:value-of select="orgType"/> e.g Org 2 in xml, would be
> highlighted (or top of the list)

You can make that be the selected option if you add a selected
attribute with a value of 'selected'.  So if you generate the XHTML:

  <option value="org 2" selected="selected">Org 2</option>

Which is equivalent to the HTML:

  <option value="org 2" selected>Org 2</option>

I don't know where you're getting your various option values from, but
you probably want to test whether orgType is equal to the option value
and then add the attribute if it is:

  <option value="org 2">
     <xsl:if test="orgType = 'Org 2'">
        <xsl:attribute name="selected">selected</xsl:attribute>
     </xsl:if>
     <xsl:text>Org 2</xsl:text>
  </option>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread