String-compare functions?

N

Nasos Makriyiannis

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
 
N

Nasos Makriyiannis

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
 
N

Nasos Makriyiannis

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
 
D

Dimitre Novatchev

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
 
N

Nasos Makriyiannis

Thanks so much for you time Dimitre! I modified my code and it seems to be
working now.

Best wishes,

-Nasos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top