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

Re: Variables within templates

Subject: Re: Variables within templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 14 Oct 1999 17:48:43 +0100 (BST)
nostradamus templates
> So, if a variable should be visible "for all following siblings and their
> descendants." why I am getting the error?

because that refers siblings and descendants of the <xsl:variable>
element in the XML tree of the stylesheet.

so in here

   <xsl:for-each select="invoices/invoice">
      <xsl:variable name="language" select="@xml:lang" />
      <xsl:apply-templates />
   </xsl:for-each>

the variable scope applies only to the <xsl:apply-templates element
(so you could have used $langauge in a select expression on that
element)

but that is all. The other templates are not in this scope.

If you want to pass information down the recursive apply-templates call,
then you need to make it a parameter to the templates

 <xsl:for-each select="invoices/invoice">
      <xsl:apply-templates>
        <xsl:with-param name="language" select="@xml:lang" />
      </xsl:apply-templates>
   </xsl:for-each>

and declare language to be a param of any templates that need to use it.

However it is probably simpler in this case not to pass this information
down via a parameter, and just go back up the tree to get the
information when you need it. that is 

 <xsl:for-each select="invoices/invoice">
      <xsl:apply-templates />
   </xsl:for-each>

and then


<xsl:template match="invoice_number">
<xsl:value-of select="/invoices/translations/invoice_no
                          [@xml:lang= current()/../@xml:lang]" />
 : <xsl:value-of select="." />
</xsl:template>

David


 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.