473,803 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<xsl:variable > scope

Hi,

I'm trying this code snippet below but the parser (sablotron) returns
error :

<xsl:choose>
<xsl:when test="some test case">
<xsl:variable name="test" select="0"/>
</xsl:when>
<xsl:otherwis e>
<xsl:variable name="test" select="1"/>
</xsl:otherwise>
</xsl:choose>

<xsl:value-of select="$test"/>

Sablotron whines that $test is undefined. IMHO the scope of $test is
only inside <xsl:choose>. How can I overcome this?

Note: the structure of the code is a simplified one. I could put the
<xsl:value-of> element inside the <xsl:choose> but it would increase
the complexity of the overall code, not to mention readablity.

TIA
Jul 20 '05 #1
1 4417
Hi,

No, the variable is definitely out of scope at the point you are trying to
use it.

You need to wrap the <xsl:choose> within the <xsl:variable >, e.g.

<xsl:variable name="test">
<xsl:choose>
<xsl:when test="some test case">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwis e>
<xsl:text>1</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:value-of select="$test"/>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


"Xeon" <xd*****@zworg. com> wrote in message
news:78******** *************** ***@posting.goo gle.com...
Hi,

I'm trying this code snippet below but the parser (sablotron) returns
error :

<xsl:choose>
<xsl:when test="some test case">
<xsl:variable name="test" select="0"/>
</xsl:when>
<xsl:otherwis e>
<xsl:variable name="test" select="1"/>
</xsl:otherwise>
</xsl:choose>

<xsl:value-of select="$test"/>

Sablotron whines that $test is undefined. IMHO the scope of $test is
only inside <xsl:choose>. How can I overcome this?

Note: the structure of the code is a simplified one. I could put the
<xsl:value-of> element inside the <xsl:choose> but it would increase
the complexity of the overall code, not to mention readablity.

TIA

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
31401
by: Richard | last post by:
Suppose I create a variable named "var" such as: <xsl:variable name="var">VarValue</xsl:variable> and then I want to insert its value into an attribute <Element attr=" {the value of var} "> so that it would generate <Element attr=" VarValue "> What syntax do I use to do this? If I specify <Element attr=" <xsl:value-of select='$var'/> "> then the parser complains that &lt; &gt; must be used for
10
3827
by: Tjerk Wolterink | last post by:
The following code does not work: <xsl:variable name="width" select="form:image-width"/> <xsl:if test="$width>$max_image_width"> <xsl:variable name="width" select="$max_image_width"/> </xsl:if> <img class="admin" width="{$width}" src="{form:image-url}" /> The width attribute of img is always "", the $max_image_width variable is set to 200 and $width is initially set to the width of the image.
3
3151
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function since they're not used anymore. But now, I used an <xsl:apply-templates/> and for some reason, it works in some situation but not in others. I didn't put the whole XSL file since it's quite big. Here's the part that bugs
2
7217
by: jd | last post by:
Hi, I have an xsl as below. I am trying to loop using <xsl:for-each> and in the select attribute of <xsl:for-each> i am getting the nodeset from the external javascript function in the <CDATA> section. This code works fine with MSXML4.0 parser. When I try to use .Net, it gives me error saying " The expression passed to this method should result in a NodeSet."
5
3416
by: jhurrell | last post by:
I have been having some trouble getting my XSL style sheet to parse correctly. I have some XML outputted from an SQL-Server, that I then need to turn into multiple HTML files. This I have done with moderate success using Saxon and <xsl:result-document>, but Saxon is throwing an error and I don't know how to resolve it. Maybe someone can offer some advice? This is a long question, for which I apologise... OS= Windows XP Pro, Saxon=8.8 XML...
2
2580
by: Kniffel | last post by:
Hi Is there a possibility to make an <xsl:whenon more than one Selection? Not that way: <xsl:choose> <xsl:when a=test> Do this <xsl:when a=test2>
8
5659
by: Hoi Wong | last post by:
With the XSLT 1.0 engine that I was forced to use, I have to parse old XML scripts where the number (to be parsed and saved into $EPISODE_NUMBER_RAW) that I want to parse is written with a comma seperator if it goes beyond 3 digits. i.e. the variable might be parsed as a string '1,324' or a number 56, depending on which XML file I have. I was trying to get rid of the comma seperator by breaking the string into two parts (that number will...
5
3911
by: John Gordon | last post by:
My XSLT files have many occurrences of this general pattern: <a> <xsl:attribute name="href"> <xsl:value-of select="xyz" /> </xsl:attribute> </a> When I execute an XSL transform, the resulting HTML looks like this:
4
11541
by: Hoi Wong | last post by:
I have an XSLT script collection that converts messed up XML to usuable XML. Instead of generic template matching, I want to establish a context node for some branches so that I don't have to rely on absolute path. Here's a simplified version of my work: : <xsl:include href="common.xsl"/> <xsl:template match="/">
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.