[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Variables within templates
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|