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

RE: variable binding

Subject: RE: variable binding
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 5 Nov 2003 22:46:56 -0000
xml template variable binding
> 
> I'm having trouble with variable binding - basically, I read 
> that variable 
> bindings declared in templates should be visible to descendants and 
> following siblings, but I'm getting not getting the behavior 
> I thought I 
> would with my stylesheet using Saxon 6.5.2...

You've misunderstood the rules. The scope of variables is static, not
dynamic. It doesn't depend on your source document, and it doesn't
depend on the way in which templates call each other. You're trying to
reference a variable in one template that's declared in a different
template. What you need to do is pass the value as a parameter from one
template to the other, using xsl:with-param and xsl:param.

Michael Kay


> 
> so the relevant part of my file looks like this (it's a 
> subbranch of s):
>           <ng of='proteins' role='h'>
>                 <nx head='targeting' role='h'>
>                      <W index='92'>the</W>
>                      <W role='h' index='93'>targeting</W>
>                 </nx>
>                      <W index='94'>of</W>
>                 <nx head='proteins' role='k'>
>                      <W index='95'>the</W>
>                      <W index='96'>myosin</W>
>                      <W role='h' index='97'>proteins</W>
>                 </nx>
> 	</ng>
> 
> and my stylesheet looks like this:
> 
> <xsl:template match="@* | * | comment() | processing-instruction() | 
> node()">
>  <xsl:copy>
>   <xsl:apply-templates select="@*|node()"/>
>  </xsl:copy>
> </xsl:template>
> 
> <xsl:template match="s//ng//*[1]" priority="5">
> 	<xsl:variable name="branch">right</xsl:variable>
> 	<xsl:copy>
> 	<xsl:attribute name="branch"><xsl:value-of 
> select="$branch"/></xsl:attribute>
> 	<xsl:apply-templates select="@*|node()"/>
> 	</xsl:copy>
> </xsl:template>
> 
> 
> <xsl:template match="s//ng//*" priority="4">
> 	<xsl:copy>
> 	<xsl:attribute name="branch"><xsl:value-of 
> select="$branch"/></xsl:attribute>
> 	<xsl:apply-templates select="@*|node()"/>
> 	</xsl:copy>
> </xsl:template>
> 
> but when I try to run it, it tells me that the variable 
> branch has not 
> been declared, even though it should first have processed the first 
> daughter of ng, where it has been declared. 
> 
> Best,
> shipra
> 
> 
>  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.