Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > String-compare functions?

Reply
Thread Tools

String-compare functions?

 
 
Nasos Makriyiannis
Guest
Posts: n/a
 
      07-24-2003
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


 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-24-2003
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" <(E-Mail Removed)> wrote in message
news:bfp4u6$c1m$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Nasos Makriyiannis
Guest
Posts: n/a
 
      07-24-2003
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" <(E-Mail Removed)> wrote in message
news:bfp7mi$grhs0$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> news:bfp4u6$c1m$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Nasos Makriyiannis
Guest
Posts: n/a
 
      07-24-2003
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"
xmlnssl="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" <(E-Mail Removed)> wrote in message
news:bfpc6r$hduii$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> news:bfp9he$l7q$(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:bfp7mi$grhs0$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> > > news:bfp4u6$c1m$(E-Mail Removed)...
> > > > 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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-24-2003
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" <(E-Mail Removed)> wrote in message
news:bfpcok$sul$(E-Mail Removed)...
> 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"
> xmlnssl="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" <(E-Mail Removed)> wrote in message
> news:bfpc6r$hduii$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> > news:bfp9he$l7q$(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:bfp7mi$grhs0$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> > > > news:bfp4u6$c1m$(E-Mail Removed)...
> > > > > 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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Nasos Makriyiannis
Guest
Posts: n/a
 
      07-24-2003
Thanks so much for you time Dimitre! I modified my code and it seems to be
working now.

Best wishes,

-Nasos

"Dimitre Novatchev" <(E-Mail Removed)> wrote in message
news:bfpfn8$hhfci$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> news:bfpcok$sul$(E-Mail Removed)...
> > 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"
> > xmlnssl="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" <(E-Mail Removed)> wrote in message
> > news:bfpc6r$hduii$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> > > news:bfp9he$l7q$(E-Mail Removed)...
> > > > 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" <(E-Mail Removed)> wrote in message
> > > > news:bfp7mi$grhs0$(E-Mail Removed)-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" <(E-Mail Removed)> wrote in message
> > > > > news:bfp4u6$c1m$(E-Mail Removed)...
> > > > > > 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
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments