473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2990
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>test 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\Projects\AddressService\Datapool\CloseW indow.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:ResultWindow could not be found on
screen. \\gbahes75\Projects\AddressService\Datapool\CloseW indow.sdd at
Line 3]]></MESSAGE_TEXT>
<MESSAGE_DETAILS><![CDATA["Type=Window;Caption={AddressService 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
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
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...
4
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...
1
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...
2
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"/>...
6
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...
2
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...
4
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...
8
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.