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

Modify Value of a Parameter Globally Within a Template

Subject: Modify Value of a Parameter Globally Within a Template
From: Lisa Jiang <ljiang@xxxxxxxxx>
Date: Mon, 12 Nov 2012 12:07:11 -0500
 Modify Value of a Parameter Globally Within a Template
Dear All,

Is there a specific way to change the value of a parameter within a
call to another template and then use the resulting value for tests in
the original template? Or just change the value of a parameter within
a template that then reflects globally? I've included some simple,
example code on what I would like to do.

So say the default parameter of 'flavor' is set globally outside all
the templates. The main template then calls the 'order' template,
which is where I'm trying to change 'flavor'. Then after 'order' is
called, I then want to check whether or not the 'flavor' was changed.
I tried to do it using 'with-param' in the 'order' template (shown in
the example), but for some reason it does not work. It throws errors
in other 'when' loops around it. I don't think the problem is with
other parts of the code, because the code runs perfectly fine without
the with-param change added. Is there something special I have to do
to change the parameter or is there a better way to do what I want?
I'm restricted to XSLT version 1.0.

Thanks in advance!
Lisa

<xsl:stylesheet>

<xsl:param name="flavor"  select=" 'vanilla' "/>
<xsl:param name="dessert"  select=" 'brownie' "/>
<xsl:param name="hungry"  select=" 'true' "/>

<xsl:template match="/">
     <xsl:element name="{$wrapper}" namespace="http://www.namespace.com">

          <xsl:call-template name="order"/>

          <xsl:choose>
                    <xsl:when test=" $flavor = 'chocolate' ">
                         <! ... do something ... ->
                    </xsl:when>

                    <xsl:otherwise>
                         <! ... do something else ... ->
                    </xsl:otherwise>
          </xsl:choose>

     </xsl:element>
</xsl:template>

<xsl:template name="order">
     <xsl:variable name="action">
          <xsl:choose>

               <xsl:when test=" $hungry = 'true' ">
                    <xsl:choose>

                         <xsl:when test=" $dessert = 'brownie' ">
                              <xsl:value-of select=" 'order_brownie' "/>
                         </xsl:when>

                         <xsl:otherwise>
                              <xsl:value-of select=" 'order_ice_cream' "/>
                              <xsl:with-param name="$ice_cream"
select=" 'chocolate' "/>
                         </xsl:otherwise>

                    </xsl:choose>
               </xsl:when>
          </xsl:choose>
     </xsl:variable>
</xsl:template>

</xsl:stylesheet>

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.