[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to Use Current Node Value to Test to See if Option

Subject: How to Use Current Node Value to Test to See if Option Shouldbe Selected
From: "Andrew Kerns" <akerns@xxxxxxxxxxxx>
Date: Tue, 12 Mar 2002 16:31:37 -0500
xsl if test node value
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.