473,473 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String-compare functions?

Hi,

I'm new to XSL and I was wondering if there is a string-compare function
available. I am using the following IF statement but it does not seem to be
working:

<xsl:if test="boolean(normalize-space(name(..))='Stateflow')">
....do something...
</xsl:if>
<xsl:if test="boolean(normalize-space(name(..)) != 'Stateflow')">
....do another thing...
</xsl:if>

One of the above two cases should be true but neither of them are called. I
displayed the value-of name(..) and it comes out as expected (i.e. sometimes
it's 'Stateflow' and other times it's not!).

I also tried using the contain() function: <xsl:if
test="contains(name(..),'Stateflow') = 'true'"> but that does not work
either. Again I viewed the value-of contains(name(..),'Stateflow') and it
does come out as true.

Any ides why the none of the IF statements are run?

thanks,

-Nasos
Jul 20 '05 #1
5 7682
Could you, please, provide a complete (but minimal example) -- the
source.xml, your xslt code.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
Hi,

I'm new to XSL and I was wondering if there is a string-compare function
available. I am using the following IF statement but it does not seem to be working:

<xsl:if test="boolean(normalize-space(name(..))='Stateflow')">
...do something...
</xsl:if>
<xsl:if test="boolean(normalize-space(name(..)) != 'Stateflow')">
...do another thing...
</xsl:if>

One of the above two cases should be true but neither of them are called. I displayed the value-of name(..) and it comes out as expected (i.e. sometimes it's 'Stateflow' and other times it's not!).

I also tried using the contain() function: <xsl:if
test="contains(name(..),'Stateflow') = 'true'"> but that does not work
either. Again I viewed the value-of contains(name(..),'Stateflow') and it
does come out as true.

Any ides why the none of the IF statements are run?

thanks,

-Nasos

Jul 20 '05 #2
Sure thing. Do you have an e-mail where I can send you the files? I'm having
trouble attaching documents to the newsgroup.

I'll provide an explanation in the e-mail also.

regards,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
Could you, please, provide a complete (but minimal example) -- the
source.xml, your xslt code.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
Hi,

I'm new to XSL and I was wondering if there is a string-compare function
available. I am using the following IF statement but it does not seem to be
working:

<xsl:if test="boolean(normalize-space(name(..))='Stateflow')">
...do something...
</xsl:if>
<xsl:if test="boolean(normalize-space(name(..)) != 'Stateflow')">
...do another thing...
</xsl:if>

One of the above two cases should be true but neither of them are called. I
displayed the value-of name(..) and it comes out as expected (i.e.

sometimes
it's 'Stateflow' and other times it's not!).

I also tried using the contain() function: <xsl:if
test="contains(name(..),'Stateflow') = 'true'"> but that does not work
either. Again I viewed the value-of contains(name(..),'Stateflow') and

it does come out as true.

Any ides why the none of the IF statements are run?

thanks,

-Nasos


Jul 20 '05 #3
OK here it is (I sent you 2 files to your Yahoo address so please disregard
them):

===XML====

<?xml version="1.0" ?>
<METRICSINFORMATION>
<Stateflow>
<chartName>chart_constant</chartName>
<numTransition>DIFFTAG_rem 3 DIFFTAG_add 4</numTransition>
<transitionData>
<labelString>?</labelString>
</transitionData>
</Stateflow>
</METRICSINFORMATION>

===============
====XSL=========

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<basefont face="Arial" size="4" />
</head>
<body>
<ol>
<xsl:apply-templates select="/METRICSINFORMATION/Stateflow"/>
</ol>
</body>
</html>
</xsl:template>
<xsl:template name="Stateflow" match="/METRICSINFORMATION/Stateflow">

<xsl:for-each select="*">

<xsl:call-template name="GlobalTemplateStateflow"/>

</xsl:for-each>

<xsl:for-each select="*/*">

<xsl:call-template name="GlobalTemplateStateflow"/>

</xsl:for-each>
</xsl:template>
<xsl:template name = "GlobalTemplateStateflow" match='/METRICSINFORMATION'>
<xsl:if test="boolean(contains(name(..),'Stateflow'))">
<xsl:variable name="chartNameBB" select="../chartName"/>
<xsl:variable name="chartName"
select="normalize-space($chartNameBB)"/>
</xsl:if>
<xsl:if test="boolean(contains(name,'Stateflow'))">
<xsl:variable name="chartNameBB" select="../../chartName"/>
<xsl:variable name="chartName"
select="normalize-space($chartNameBB)"/>
<xsl:variable name="machineN" select="../../machineName"/>
<xsl:variable name="machineName"
select="normalize-space($machineN)"/>
</xsl:if>

<li><xsl:value-of select="$chartName"/></li>
</xsl:template>


</xsl:stylesheet>

========================================

thanks,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
Can't you just put them inline in your message?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
Sure thing. Do you have an e-mail where I can send you the files? I'm having
trouble attaching documents to the newsgroup.

I'll provide an explanation in the e-mail also.

regards,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
Could you, please, provide a complete (but minimal example) -- the
source.xml, your xslt code.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
> Hi,
>
> I'm new to XSL and I was wondering if there is a string-compare function > available. I am using the following IF statement but it does not seem to
be
> working:
>
> <xsl:if test="boolean(normalize-space(name(..))='Stateflow')">
> ...do something...
> </xsl:if>
> <xsl:if test="boolean(normalize-space(name(..)) != 'Stateflow')">
> ...do another thing...
> </xsl:if>
>
> One of the above two cases should be true but neither of them are

called.
I
> displayed the value-of name(..) and it comes out as expected (i.e.
sometimes
> it's 'Stateflow' and other times it's not!).
>
> I also tried using the contain() function: <xsl:if
> test="contains(name(..),'Stateflow') = 'true'"> but that does not

work > either. Again I viewed the value-of contains(name(..),'Stateflow')

and
it
> does come out as true.
>
> Any ides why the none of the IF statements are run?
>
> thanks,
>
> -Nasos
>
>



Jul 20 '05 #4
The problem has nothing to do with string comparison.

You define incorrectly your xsl:variables and they immediately go out of
scope.

Then, when you try to use the variable $chartName, it is out of scope (not
defined at all), so MSXML4 issues the following error message:

Error occurred while compiling stylesheet '(Untitled)'.

Code: 0x80004005
A reference to variable or parameter 'chartName' cannot be resolved. The
variable or parameter may not be defined, or it may not be in scope.

In fact, this is a very FAQ:

If you want to define a xsl:variable so that its value is determined based
on different conditions, the correct way to do this is:

<xsl:variable name="comeVar">
<xsl:choose>
<xsl:when test="cond1">value1</xsl:when>
<xsl:when test="cond2">value2</xsl:when>
. . . . .
<xsl:when test="condN">valueN</xsl:when>
</xsl:choose>
</xsl:variable>

Hope this helped.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
OK here it is (I sent you 2 files to your Yahoo address so please disregard them):

===XML====

<?xml version="1.0" ?>
<METRICSINFORMATION>
<Stateflow>
<chartName>chart_constant</chartName>
<numTransition>DIFFTAG_rem 3 DIFFTAG_add 4</numTransition>
<transitionData>
<labelString>?</labelString>
</transitionData>
</Stateflow>
</METRICSINFORMATION>

===============
====XSL=========

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<basefont face="Arial" size="4" />
</head>
<body>
<ol>
<xsl:apply-templates select="/METRICSINFORMATION/Stateflow"/>
</ol>
</body>
</html>
</xsl:template>
<xsl:template name="Stateflow" match="/METRICSINFORMATION/Stateflow">

<xsl:for-each select="*">

<xsl:call-template name="GlobalTemplateStateflow"/>

</xsl:for-each>

<xsl:for-each select="*/*">

<xsl:call-template name="GlobalTemplateStateflow"/>

</xsl:for-each>
</xsl:template>
<xsl:template name = "GlobalTemplateStateflow" match='/METRICSINFORMATION'>

<xsl:if test="boolean(contains(name(..),'Stateflow'))">
<xsl:variable name="chartNameBB" select="../chartName"/>
<xsl:variable name="chartName"
select="normalize-space($chartNameBB)"/>
</xsl:if>
<xsl:if test="boolean(contains(name,'Stateflow'))">
<xsl:variable name="chartNameBB" select="../../chartName"/>
<xsl:variable name="chartName"
select="normalize-space($chartNameBB)"/>
<xsl:variable name="machineN" select="../../machineName"/>
<xsl:variable name="machineName"
select="normalize-space($machineN)"/>
</xsl:if>

<li><xsl:value-of select="$chartName"/></li>
</xsl:template>


</xsl:stylesheet>

========================================

thanks,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
Can't you just put them inline in your message?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
Sure thing. Do you have an e-mail where I can send you the files? I'm

having
trouble attaching documents to the newsgroup.

I'll provide an explanation in the e-mail also.

regards,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
> Could you, please, provide a complete (but minimal example) -- the
> source.xml, your xslt code.
>
>
> =====
> Cheers,
>
> Dimitre Novatchev.
> http://fxsl.sourceforge.net/ -- the home of FXSL
>
>
>
> "Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
> news:bf**********@ginger.mathworks.com...
> > Hi,
> >
> > I'm new to XSL and I was wondering if there is a string-compare

function
> > available. I am using the following IF statement but it does not seem
to
> be
> > working:
> >
> > <xsl:if test="boolean(normalize-space(name(..))='Stateflow')">
> > ...do something...
> > </xsl:if>
> > <xsl:if test="boolean(normalize-space(name(..)) != 'Stateflow')">
> > ...do another thing...
> > </xsl:if>
> >
> > One of the above two cases should be true but neither of them are
called.
> I
> > displayed the value-of name(..) and it comes out as expected (i.e.
> sometimes
> > it's 'Stateflow' and other times it's not!).
> >
> > I also tried using the contain() function: <xsl:if
> > test="contains(name(..),'Stateflow') = 'true'"> but that does not work > > either. Again I viewed the value-of

contains(name(..),'Stateflow') and
it
> > does come out as true.
> >
> > Any ides why the none of the IF statements are run?
> >
> > thanks,
> >
> > -Nasos
> >
> >
>
>



Jul 20 '05 #5
Thanks so much for you time Dimitre! I modified my code and it seems to be
working now.

Best wishes,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
The problem has nothing to do with string comparison.

You define incorrectly your xsl:variables and they immediately go out of
scope.

Then, when you try to use the variable $chartName, it is out of scope (not
defined at all), so MSXML4 issues the following error message:

Error occurred while compiling stylesheet '(Untitled)'.

Code: 0x80004005
A reference to variable or parameter 'chartName' cannot be resolved. The
variable or parameter may not be defined, or it may not be in scope.

In fact, this is a very FAQ:

If you want to define a xsl:variable so that its value is determined based
on different conditions, the correct way to do this is:

<xsl:variable name="comeVar">
<xsl:choose>
<xsl:when test="cond1">value1</xsl:when>
<xsl:when test="cond2">value2</xsl:when>
. . . . .
<xsl:when test="condN">valueN</xsl:when>
</xsl:choose>
</xsl:variable>

Hope this helped.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
OK here it is (I sent you 2 files to your Yahoo address so please

disregard
them):

===XML====

<?xml version="1.0" ?>
<METRICSINFORMATION>
<Stateflow>
<chartName>chart_constant</chartName>
<numTransition>DIFFTAG_rem 3 DIFFTAG_add 4</numTransition>
<transitionData>
<labelString>?</labelString>
</transitionData>
</Stateflow>
</METRICSINFORMATION>

===============
====XSL=========

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<basefont face="Arial" size="4" />
</head>
<body>
<ol>
<xsl:apply-templates select="/METRICSINFORMATION/Stateflow"/>
</ol>
</body>
</html>
</xsl:template>
<xsl:template name="Stateflow" match="/METRICSINFORMATION/Stateflow">

<xsl:for-each select="*">

<xsl:call-template name="GlobalTemplateStateflow"/>

</xsl:for-each>

<xsl:for-each select="*/*">

<xsl:call-template name="GlobalTemplateStateflow"/>

</xsl:for-each>
</xsl:template>
<xsl:template name = "GlobalTemplateStateflow"

match='/METRICSINFORMATION'>


<xsl:if test="boolean(contains(name(..),'Stateflow'))">
<xsl:variable name="chartNameBB" select="../chartName"/>
<xsl:variable name="chartName"
select="normalize-space($chartNameBB)"/>
</xsl:if>
<xsl:if test="boolean(contains(name,'Stateflow'))">
<xsl:variable name="chartNameBB" select="../../chartName"/>
<xsl:variable name="chartName"
select="normalize-space($chartNameBB)"/>
<xsl:variable name="machineN" select="../../machineName"/>
<xsl:variable name="machineName"
select="normalize-space($machineN)"/>
</xsl:if>

<li><xsl:value-of select="$chartName"/></li>
</xsl:template>


</xsl:stylesheet>

========================================

thanks,

-Nasos

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bf************@ID-152440.news.uni-berlin.de...
Can't you just put them inline in your message?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
news:bf**********@ginger.mathworks.com...
> Sure thing. Do you have an e-mail where I can send you the files? I'm having
> trouble attaching documents to the newsgroup.
>
> I'll provide an explanation in the e-mail also.
>
> regards,
>
> -Nasos
>
> "Dimitre Novatchev" <dn********@yahoo.com> wrote in message
> news:bf************@ID-152440.news.uni-berlin.de...
> > Could you, please, provide a complete (but minimal example) -- the
> > source.xml, your xslt code.
> >
> >
> > =====
> > Cheers,
> >
> > Dimitre Novatchev.
> > http://fxsl.sourceforge.net/ -- the home of FXSL
> >
> >
> >
> > "Nasos Makriyiannis" <nm******@mathworks.com> wrote in message
> > news:bf**********@ginger.mathworks.com...
> > > Hi,
> > >
> > > I'm new to XSL and I was wondering if there is a string-compare
function
> > > available. I am using the following IF statement but it does not

seem
to
> > be
> > > working:
> > >
> > > <xsl:if test="boolean(normalize-space(name(..))='Stateflow')">
> > > ...do something...
> > > </xsl:if>
> > > <xsl:if test="boolean(normalize-space(name(..)) != 'Stateflow')"> > > > ...do another thing...
> > > </xsl:if>
> > >
> > > One of the above two cases should be true but neither of them are > called.
> > I
> > > displayed the value-of name(..) and it comes out as expected (i.e. > > sometimes
> > > it's 'Stateflow' and other times it's not!).
> > >
> > > I also tried using the contain() function: <xsl:if
> > > test="contains(name(..),'Stateflow') = 'true'"> but that does
not
work
> > > either. Again I viewed the value-of

contains(name(..),'Stateflow') and
> it
> > > does come out as true.
> > >
> > > Any ides why the none of the IF statements are run?
> > >
> > > thanks,
> > >
> > > -Nasos
> > >
> > >
> >
> >
>
>



Jul 20 '05 #6

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

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
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
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,...
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...
1
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...
0
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
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.