[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: Variables within templates


Subject: Re: Variables within templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 14 Oct 1999 17:48:43 +0100 (BST)

> 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
Keywords
xml