473,786 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Holding and changing a variable in XSLT

Hi,

This is a snippet of my XSLT

<xsl:for-each select = "SAFS_LOG/LOG_MESSAGE">
<xsl:choose>
<xsl:when test="@type = 'FAILED'">
<xsl:variable name="isFailed" select="@type" />
<BR> "FAILED" </BR>
</xsl:when>

<xsl:when test="@type = 'END DATATABLE'">
<xsl:if test = "not('FAILED'=$ isFailed)">
<BR> "PASSED" </BR>
</xsl:if>
</xsl:when>

</xsl:choose>
</xsl:for-each>

I am looping an XML file. If I get an attribute named 'type' with a
value of 'FAILED',
I would like to assign that value to a variable, then in the next
conditional statement
if that variable does not contain the value 'FAILED', I would like to
create a pass.

However, when I run the tansform, I receive a variable not resolved or
defined error.

Could you please help?

Aidy

Apr 26 '06 #1
6 3017
A variable is "visible for all following siblings and their
descendants." That basically means you can't return it to a higher level
of the stylesheet, even within a single template.

The simplest fix is to invert the problem. Do your testing to calculate
the value of the variable rather than using the test to control how it
gets set, so the variable definition is a top-level child of the
template and thus is visible to everything following it in the template.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 26 '06 #2
Thanks for your response, but from what I can see I have defined and
assigned the value to the variable, before I compare it.

<xsl:variable name="isFailed" select="@type" />
.......
......

<xsl:when test="@type = 'END DATATABLE'">
<xsl:if test = "not('FAILED'=$ isFailed)">

Am I mis-understanding what you mean?

Cheers

Aidy

Apr 26 '06 #3
aidy wrote:
Thanks for your response, but from what I can see I have defined and
assigned the value to the variable, before I compare it.


You assigned it before, but deeper (within the conditional). That means
it goes out of scope before you can test it.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 26 '06 #4
Hi Joe
You assigned it before, but deeper (within the conditional). That means
it goes out of scope before you can test it.


Thanks. Now if I put this line above the template at global level

<xsl:variable name="isFailed" select="''" />
then within the template and conditional statement I can override it

<xsl:variable name="isFailed" select="@type" />
Will this overridden value be kept within the next conditional
statement (i.e. do we still have a global scope?)

<xsl:if test = "not('FAILED'=$ isFailed)">
I have tried to log a msg to find this out

<xsl:message>te st whether this appears</xsl:message>

in the command prompt I type

C:\ TESTLOG.xml SAFS.xsl test.htm

The test.htm is created, but I do not seem to recieve a mesage.

Cheers

Aidy

Apr 26 '06 #5
aidy wrote:
Will this overridden value be kept within the next conditional
statement (i.e. do we still have a global scope?)


No. XML variables are not mutable. When you try to override the value,
you're creating a new variable with its own scope.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 26 '06 #6
Joe,

I am really unsure on how to 'invert the problem'. This is a sample of
the XML

LOG_MESSAGE type="START DATATABLE" date="03-04-2006" time="16:46:18" >

<MESSAGE_TEXT>< ![CDATA[\\gbahes75\Proj ects\AddressSer vice\Datapool\C loseWindow.sdd]]></MESSAGE_TEXT>
</LOG_MESSAGE>
<LOG_MESSAGE type="WARNING" date="03-04-2006" time="16:46:30" >
<MESSAGE_TEXT>< ![CDATA[RobotJ Hook Not Installed or
Available.]]></MESSAGE_TEXT>
</LOG_MESSAGE>
<LOG_MESSAGE type="FAILED" date="03-04-2006" time="16:46:30" >
<MESSAGE_TEXT>< ![CDATA[WINDOW:ResultWi ndow could not be found on
screen. \\gbahes75\Proj ects\AddressSer vice\Datapool\C loseWindow.sdd at
Line 3]]></MESSAGE_TEXT>
<MESSAGE_DETAIL S><![CDATA["Type=Window;Ca ption={AddressS ervice Web
Client*}"]]></MESSAGE_DETAILS >
</LOG_MESSAGE>
<LOG_MESSAGE type="END DATATABLE" date="03-04-2006" time="16:46:30" >

What I want to do is that if there isn't an attribute type="FAILED"
between the attributes type="START DATATABLE" and type="END DATATABLE"
log a pass otherwise log a fail. I can't see any other way of doing
this except looping through the hierarchy. Could you please give me a
pseudo code example?

Aidy

Apr 26 '06 #7

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

Similar topics

3
7359
by: Son KwonNam | last post by:
The title is quite ambiguos. Any way let me explain. In java, the following is possible. ---- String str = ""; for (int i=0; i < 10; i++) { str = str + i; } ----
4
21210
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
4
3247
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable name="Banner_error_2"> errormessage 2 for banner </xsl:variable>
1
4338
by: ms_chika | last post by:
Please help! I just want to know how can i pass the return value of a javascript function to a xsl variable. I have an xsl file and from that file i will call a javascript function then the result will be stored in to the <xsl:variable> how will i do that? Or is it really possible to do that or is there other way of doing it? Your help will be very much appreciated.
2
1843
by: Jon Martin Solaas | last post by:
Hi, I have a general document somewhat like this: -------------------------------------- <root> <level1> <level2> <interestingstuff number="2"/> <interestingstuff number="3"/> <interestingstuff number="1"/>
6
14220
by: Jody Gelowitz | last post by:
I have run into an issue with variable scope within an XSLT document that is translated in VS.NET 2.0. Under VS.NET 1.1 (XslTransform), this code works fine. However, when using VS.NET 2.0 (XslCompiledTransform), the exact same XSLT transformation fails with the error: System.Xml.Xsl.XslLoadException: The variable or parameter 'lastrecordwaskit' was duplicated within the same scope. An error occurred at (174,12). at...
2
2099
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name xml:lang="zh">原æ料(包括采矿业) </name>
4
2080
by: Steven Davies | last post by:
Hi, My problem is this: I have an XML file I'm transforming to XHTML by using XSLT, and the XML file contains some values as Unix timestamps (integer value of seconds since 00:00 1970-01-01) and the only way I can think of displaying those values as human-readable is by using Javascript. Converting the times isn't the problem, what I'm stuck with is actually writing the new value into the document, since document.write(newValue); just...
8
5655
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...
0
9647
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
9492
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
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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
8988
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...
0
6744
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
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.