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

RE: variable question

Subject: RE: variable question
From: sara.mitchell@xxxxxxxxx
Date: Wed, 29 Dec 1999 17:51:14 -0500
error xsl multiple points
Well, I can answer at least the variable scoping issue. 
Global variables are defined in the stylesheet -- not inside
any template, including the template for the root node of
the document. 

Variables only exist within the scope of the template 
that they are defined in -- so your definition is 
only valid within the root node template, but not
any subsequent templates. Do something like this: 

<xsl:stylesheet ...>

<xsl:variable name="BusinessPartnerContract" select="<set the value here>"/>

<xsl:template match="MYROOT">
...
</xsl:template>

and keep your named template. The reference inside the named template
should work now without any other changes. 

Sara
> -----Original Message-----
> From: costempd@xxxxxxxxxx [mailto:costempd@xxxxxxxxxx]
> Sent: Wednesday, December 29, 1999 9: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

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.