Property "Bind Options To" <bind>

Top  Previous  Next

This property is used to retrieve the options of the Combo Box and List Box from XML nodes in the run time.

Definition Syntax

<For Each ...>,<value>,<option>,<sort>,<xslvars>,<selected-if>

Parameters

<value> and <option> should be specified relative to the node defined in <For Each ...>.

<sort> is used to sort the option nodes returned with <For Each ...> query. The usage is the same as Repeat>Sort property of container elements except that the definition must be enclosed with "(" and ")" chars.

Example:

/products/item,ID,NAME,(NAME,a,,en)

 

<xslvars> is used to define one or more XSL variables in order to use in <value>, <option> and <selected-if> parameters.

Example:

/products/item,ID,NAME,,(pid:ID)

 

<selected-if> is only valid for ListBoxes with multiple selection and is used to define a test expression. The expression defined here will be tested for each option to determine if the option is initially selected.

Example:

/products/item,ID,NAME,,(pid:CODE),/selected-products/item[. = $pid]

 

 


Example 1: ComboBox

XML:

 

 <card-types>

  <card id="1">Visa</card>

  <card id="2">Master</card>

  <card id="3">American Express</card>

 </card-types>

 <selected-card>2</selected-card>

 

Properties:

bindoptionsto

 

bindoptionsto1

 

HTML Result:

 

 <select ...>

  <option value="1">Visa</option>

  <option value="2" selected>Master</option>

  <option value="3">American Express</option>

 </select>

 


Example 2:  Sorted ComboBox

XML:

 

 <root>

  <categories>

    <item>

      <code>1</code>

      <name>CD</name>

    </item>

    <item>

      <code>2</code>

      <name>Book</name>

    </item>

  </categories>

  <selected-category>2</selected-category>

 </root>

 

 

Properties:

bindoptionsto2

 

bindoptionsto3

 

HTML Result:

 

 <select ...>

  <option value="2" selected>Book</option>

  <option value="1">CD</option>

  </select>

 


Example 3: ListBox with Multiple Selection

XML:

 

 <root>

  <products>

    <item>

      <ID>P1</ID>

      <NAME>Desktop Computer</NAME>

    </item>

    <item>

      <ID>P2</ID>

      <NAME>Laser Printer</NAME>

    </item>

    <item>

      <ID>P3</ID>

      <NAME>Hard Disk Drive</NAME>

    </item>

    <item>

      <ID>P4</ID>

      <NAME>SDRAM 266Mhz</NAME>

    </item>

  </products>

  <selected-products>

    <item>P2</item>

    <item>P4</item>

  </selected-products>

 </root>

 

 

Properties:

bindoptionsto4

 

HTML Result:

 

 <select multiple="multiple" ...>

  <option value="P1">Desktop Computer</option>

  <option value="P2" selected>Laser Printer</option>

  <option value="P3">Hard Disk Drive</option>

  <option value="P4" selected>SDRAM 266Mhz</option>

 </select>