Subject: RE: variable question From: "Benjamin Corliss" <benjamin@xxxxxxxxxxxxxxx> Date: Wed, 29 Dec 1999 14:09:24 -0800 |
You defined the variable inside a template and hence, it will be visible only within the context of the template. If you want a "global" variable, the variable must be defined as a child of <xsl:stylesheet> Example: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="foo">value of the variable</xsl:variable> . . . </xsl:stylesheet> -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of costempd@xxxxxxxxxx Sent: Wednesday, December 29, 1999 1:10 PM To: xsl-list@xxxxxxxxxxxxxxxx Subject: xsl:variable question Hi. I am new to XML and XSL so please forgive my ignorance. I have tried to figure this out from the w3 spec and other resources, but mainly from trial and error (mostly error), and I am still in the dark. <!-- what I want to do --> Basically, I am using LotusXSL to generate an HTML file from my XML data. What I want to do is access a value that is obtained from one "leaf" of my XML tree at multiple points in my XSLT transformation. I am able to do this via hardcoding the xpath to the specific node, ie: <xsl:value-of select="//MYROOT/BRANCH1/MYLEAF"/> However, I thought it might be better to set a variable (that I hoped would be global). I have a called named template that is generating a small table that is a simulation of a page header. I have nested tables, each "outer" table comprising a printable page, and the "page header" inner table sits in the first row of each outer table. <!-- /what I want to do --> <!-- aside --> Eventually I will probably want to learn about FO (FOP?) and generate PDF (or some kind of printable document) but at this stage I am using HTML as my printable object. Can XSLT and FO be combined within the same XSL stylesheet, or are they mutually exclusive? <!-- /aside --> <!-- The error I am getting --> "VariableReference given for variable out of context or without definition! Name = BusinessPartnerContract" <!-- /The error I am getting --> <!-- My variable definition --> <!-- note: hardcoded here but I want to set based on XML data --> <!-- contained within a child of "MYROOT" --> <xsl:template match="MYROOT"> <xsl:variable name="BusinessPartnerContract"> This is a business partner contract. </xsl:variable> ... </xsl:template> <!-- /My variable definition --> <!-- Fragment with call to named template --> <!-- note: this fragment occurs for each "page" I want to generate --> <tr> <!-- outer --> <td colspan="2"> <!-- outer --> <xsl:call-template name="pageHeader"/> </td> <!-- outer --> </tr> <!-- outer --> <!-- /Fragment with call to named template --> <!-- Fragment of my called template --> <xsl:template name="pageHeader"> <table cellpadding="5" cellspacing="0" border="0" cols="2"> <tr> <td colspan="2" align="center" class="bigBold"> Page Title Goes Here </td> </tr> <xsl:if test="boolean($BusinessPartnerContract)"> <tr> <td colspan="2" align="center"> <u><xsl:value-of select="$BusinessPartnerContract"/></u> </td> </tr> </xsl:if> ... some more stuff goes here ... </table> </xsl:template> <!-- /Fragment of my called template --> If I set my variable within the called template, it works. So it seems my problem is the scope of the variable. I thought my variable would be global if I set it within the first template (match="MYROOT"), but I end up with a null value, ie: " <u><xsl:value-of select="$BusinessPartnerContract"/></u>" becomes "<u></u>" TIA for any help. Nick Ridout XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
xsl:variable question, costempd | Thread | Re: xsl:variable question, Steve Tinney |
test post, costempd | Date | Re: xsl:variable question, Steve Tinney |
Month |