| Subject: [xsl] How to Use Current Node Value to Test to See if Option Should	be Selected From: "Andrew Kerns" <akerns@xxxxxxxxxxxx> Date: Tue, 12 Mar 2002 16:31:37 -0500 | 
I have a menu and a list of items that a user has chosen. I want to
display 
the form and test each menu item to see if it is in the chosen_list. If
it is I 
want to set the option to selected. I can not figure out how to use
the
current node value to build a expression to test to see if the value
was in 
the chosen list of not. Right now the code below assigns the literal
string I want to 
execute to the variable $chosen-item.  The variable query never gets
evaulated
and so $chosen-item always evalutates to true and so everything is set
to selected.
Any ideas.
Thanks.
—- XML File —-
<SIMPLE_MENU>
  <CHOSEN_LIST>
    <CHOSEN_ITEM>Mexico</CHOSEN_ITEM>
  </CHOSEN_LIST>
  <MENU>
    <MENU_ITEM>Canada</MENU_ITEM>
    <MENU_ITEM>Mexico</MENU_ITEM>
    <MENU_ITEM>United States</MENU_ITEM>
  </MENU>
</SIMPLE_MENU>
—-XSL Style sheet —-
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<BODY>
	<CENTER/>
	<FORM METHOD="POST" NAME="MENU" ACTION="ReportBuilder.ASP" >
	  <xsl:element name="SELECT">
	   <xsl:attribute name="NAME">VARIABLE</xsl:attribute>
	   <xsl:attribute name="MULTIPLE"/>
	   <xsl:attribute name="SIZE">3</xsl:attribute>
	   <xsl:apply-templates select="//MENU/MENU_ITEM" />
	  </xsl:element>
	  <p/>
	  
	  <input type="submit" name="btnSelect" value="Select"/>
	  <input type="button" name="btnCancel" value="Cancel"
onClick="window.location.href='ReportBuilder.asp'"/>
	</FORM>
        </BODY>
</HTML>
</xsl:template>
	
<xsl:template match="MENU/MENU_ITEM">
  <xsl:variable name="chosen-item">
    select="//CHOSEN_LIST/CHOSEN_ITEM/text()='.'"
  </xsl:variable>
  <xsl:value-of select = "$chosen-item" />
  
  <xsl:element name="OPTION">
    <xsl:if test="$chosen-item">
      <xsl:attribute name="SELECTED">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select ="." />
  </xsl:element>
</xsl:template>
</xsl:stylesheet>
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] adding variables, David N Bertoni/Camb | Thread | [xsl] Treeview with JAXP, Jhaveri, Harshal | 
| RE: [xsl] adding variables, Julian Reschke | Date | Re: [xsl] adding variables, cutlass | 
| Month |