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

Re: Scope of Local Variables?

Subject: Re: Scope of Local Variables?
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 06 Jun 2002 23:02:31 +0200
scope of local variables
As David said, you can not declare a variable in one template and use it in another one. You have two possibilities:

Either access the read-element directly from the template matching on <data>:

<xsl:template match="data">
  <xsl:value-of select="../read/tagToAxis[@axisIDRef='rows']/@tag"/>
  <xsl:value-of select="../read/tagToAxis[@axisIDRef='columns']/@tag"/>
</xsl:template>

Or you declare the variable on "a higher level" and pass it as parameter to the template matching on <data>:

<xsl:template match="array">
<xsl:apply-templates select="data">
<xsl:with-param name="columnTag" select="read/tagToAxis[@axisIDRef='columns']/@tag"/>
<xsl:with-param name="rowTag" select="read/tagToAxis[@axisIDRef='rows']/@tag"/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="data">
  <xsl:param name="rowTag"/>
  <xsl:param name="columnTag"/>
  <xsl:value-of select="$rowTag"/>
  <xsl:value-of select="$columnTag"/>
</xsl:template>

Regards,

Joerg

Rajput, Ashish S wrote:
Joerg, I apologize for my typo... the latter was meant to be a <xsl:template
match="data"> not a <xsl:template match="read">  I want to call the
variables within the "data" template.  Below is the corrected
translation.......


<xsl:template match="read"> <xsl:variable name="rowTag" select="./tagToAxis[./@axisIDRef='rows']/@tag"></xsl:variable> <xsl:variable name="columnTag" select="./tagToAxis[./@axisIDRef='columns']/@tag"></xsl:variable> </xsl:template>

<xsl:template match="data">
	<xsl:value-of select='$rowTag'></xsl:value-of>
	<xsl:value-of select='$columnTag'></xsl:value-of>
</xsl:template>


Ashish


-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@xxxxxx]
Sent: Thursday, June 06, 2002 2:25 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Scope of Local Variables?


Hello Ashish,


why do you have two templates matching on "read"? Change it to:

<xsl:template match="read">
   <xsl:variable name="rowTag" select="tagToAxis[@axisIDRef='rows']/@tag"/>

<xsl:variable name="columnTag" select="tagToAxis[@axisIDRef='columns']/@tag"/>
<xsl:value-of select='$rowTag'/>
<xsl:value-of select='$columnTag'/>
</xsl:template>



Joerg


Rajput, Ashish S wrote:

Hello,

Using the MSXML 4 parser, as well as Instant Saxon 6.5.2 I'm getting an
error of "variable may be out of scope" when trying to use a variable
locally.  Listed below are my XML and XSLT files..... am I defining the
variables incorrectly?  I'm attempting to call the variables in a sibling.
Please help!

Ashish Rajput

*******************************************
XSLT
*******************************************
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="array">
<xsl:for-each select="(./ancestor::*)">></xsl:for-each>
			 <font color="red"><span style="font-size:medium;
font-weight:bold">
	<xsl:value-of select="@name" />
	                            </span></font>
<xsl:apply-templates />
</xsl:template>
	
<xsl:template match="read">
	<xsl:variable name="rowTag"
select="./tagToAxis[./@axisIDRef='rows']/@tag"></xsl:variable>	
	<xsl:variable name="columnTag"
select="./tagToAxis[./@axisIDRef='columns']/@tag"></xsl:variable>
</xsl:template>

<xsl:template match="read">
	<xsl:value-of select='$rowTag'></xsl:value-of>
	<xsl:value-of select='$columnTag'></xsl:value-of>
</xsl:template>	
</xsl:stylesheet>


*********************************************** XML *********************************************** <array name="Cross Section Factor"> <fieldAxis fieldAxisID="columns"> <field name="Reflection Type"> <units> <unitless/> </units> <dataFormat> <float/> </dataFormat> </field> <field name="Value"> <units> <unitless/> </units> <dataFormat> <float/> </dataFormat> </field> </fieldAxis> <axis axisID="rows" axisDataType="integer"> <axisUnits> <unitless/> </axisUnits> </axis> <read encoding="UTF-8"> <tagToAxis tag="d1" axisIDRef="columns"/> <tagToAxis tag="d0" axisIDRef="rows"/> </read> <data> <d0> <d1>Radar</d1> <d1>.5</d1> </d0> <d0> <d1>Sonar</d1> <d1>.4</d1> </d0> <d0> <d1>Visual</d1> <d1>.3</d1> </d0> <d0> <d1>InfraRed</d1> <d1>.2</d1> </d0> </data> </array>



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


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-2011 All Rights Reserved.