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

Variables within templates

Subject: Variables within templates
From: Denis.Avdonine@xxxxxxxxxxxxxxx
Date: Thu, 14 Oct 1999 15:38:35 +0100
facture template

Folks,

I have the following XML and XSL files (see below).
When I try to apply the stylesheet to XML file using XT, I receive the following
error:
file:invoices.xsl:14: variable "language" not defined

In section 11.5 of XSLT recommendation (8-Oct-1999) I read the following:
=== cut here ===
As well as being allowed at the top-level, both xsl:variable and xsl:param are
also allowed in templates. xsl:variable is allowed anywhere within a template
that an instruction is allowed. In this case, the binding is visible for all
following siblings and their descendants.
<...>
=== cut here ===

So, if a variable should be visible "for all following siblings and their
descendants." why I am getting the error?

=== begin: XML file ===
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="invoices.xsl"?>

<invoices>

   <translations>
      <invoice_no xml:lang="en">Invoice No</invoice_no>
      <invoice_no xml:lang="fr">Numero de facture</invoice_no>
   </translations>

   <invoice xml:lang="en">
      <invoice_number>1234</invoice_number>
   </invoice>

   <invoice xml:lang="fr">
      <invoice_number>4567</invoice_number>
   </invoice>

</invoices>
=== end: XML file ===

=== begin: XSL file ===
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" />

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

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

</xsl:stylesheet>
=== end: XSL file ===

By the way, maybe some can propose a better way of substituting translations?

Thank you.
Denis.



 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.