473,322 Members | 1,496 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,322 software developers and data experts.

xsl:if and string function

I'm at my wit's end with this one. Within an xsl:if test, I'm not able to
get 2 variables to properly evaluate if one of them is wrapped within a
string function.

<!-- This works -->
<xsl:if test="$var:v141=&quot;true&quot;">

<!-- This doesn't work -->
<xsl:if test="string($var:v141)=&quot;true&quot;">

I can't figure out why. The transformation is taking place within dotnet and
the var:v141 is assigned through a function call and it doesn't matter if I
return a boolean value or a string value ("true" or "false"), it always
evaluates to true and outputs the information wrapped within the if
statement. To further complicate things, this if statement is being
generated by the Biztalk Mapper (ugghhh!) and so I cannot edit the statement
and remove the string function.

I don't get it. Am I just overlooking something obvious here (I hope so...).

Eric

Here's the entire code block that doesn't work (I mean, regardless of the
value returned from the fctequal function, the if statment always evaluates
to true):

<xsl:for-each select="DexRaces/DexRace">
<xsl:variable name="var:v141"
select="fctequal(string(Code/text()),&quot;1&quot;)"/>
<xsl:if test="string($var:v141)=&quot;true&quot;">
<xsl:variable name="var:v142" select="&quot;true&quot;"/>
<RaceAIorANHMDA><xsl:value-of select="$var:v142"/></RaceAIorANHMDA>
</xsl:if>
</xsl:for-each>

neither version of the function helps:

public string fctequal(string value1, string value2)
{
if(value1.Equals(value2))
{
return "true";
}
return "false";
}

public bool fctequal(string value1, string value2)
{
return value1.Equals(value2)
}

Nov 12 '05 #1
3 3569
Eric Theil wrote:
<xsl:variable name="var:v141"
select="fctequal(string(Code/text()),&quot;1&quot;)"/>


This looks weird. Extension functions must be namespace prefixed. Such
stylesheet should throw
System.Xml.Xsl.XsltException: 'fctequal()' is an unknown XSLT function.
You need
user:fctequal(string(Code/text()),&quot;1&quot;)
Where "user" prefix is bound either to extension object or should be
registered in msxsl:script element:
<msxsl:script language="C#" implements-prefix="user">
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2
Oleg,

It is prefixed with the userJScript namespace, I just didn't include it in
the post.

Anyway, the function is called and I can see the output if I simply write
out the result variable. I can see the function writing out "false" if I
setup the xsl like this:

<xsl:value-of select="string($var:v141)=&quot;true&quot;"/>

but for whatever reason, the evaluation within the xsl:if block is true.

Eric

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:us**************@TK2MSFTNGP11.phx.gbl...
Eric Theil wrote:
<xsl:variable name="var:v141"
select="fctequal(string(Code/text()),&quot;1&quot;)"/>


This looks weird. Extension functions must be namespace prefixed. Such
stylesheet should throw
System.Xml.Xsl.XsltException: 'fctequal()' is an unknown XSLT function.
You need
user:fctequal(string(Code/text()),&quot;1&quot;)
Where "user" prefix is bound either to extension object or should be
registered in msxsl:script element:
<msxsl:script language="C#" implements-prefix="user">
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3
Eric Theil wrote:
It is prefixed with the userJScript namespace, I just didn't include it in
the post.

Anyway, the function is called and I can see the output if I simply write
out the result variable. I can see the function writing out "false" if I
setup the xsl like this:

<xsl:value-of select="string($var:v141)=&quot;true&quot;"/>

but for whatever reason, the evaluation within the xsl:if block is true.

That's really weird. Unfortunately I cannot reproduce the problem. Just
tried the following XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:var="var"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mycompany.com/mynamespace"
exclude-result-prefixes="var msxsl user">
<msxsl:script language="C#" implements-prefix="user">
public string fctequal(string value1, string value2)
{
if(value1.Equals(value2))
{
return "true";
}
return "false";
}
</msxsl:script>
<xsl:template match="/">
<xsl:for-each select="*">
<xsl:variable name="var:v141"
select="user:fctequal(string(text()),&quot;1&quot; )"/>
<xsl:if test="string($var:v141)=&quot;true&quot;">
<xsl:variable name="var:v142" select="&quot;true&quot;"/>
<RaceAIorANHMDA>
<xsl:value-of select="$var:v142"/>
</RaceAIorANHMDA>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

with xml:
<foo>1</foo>
it outputs "true", and with
<foo>0</foo>
it outputs nothing.

Try to get generated by BizTalk stylesheet and input XML so we can
reproduce.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com
Nov 12 '05 #4

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

Similar topics

3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
9
by: Andrea Maschio | last post by:
Hi, i have a terrible noobie frustration formatting an XML file like this: <Dipendente Id="1" Anno="2003" Nome="pippo" Cognome="pippi" Nato_il="10/03" Email="pippo@emailprovider.it" Esito="ok"/>...
2
by: Jørn Tommy Kinderås | last post by:
I need to get nodes in a xml file that match one out of two parameters...but how can I create a or statemement with <xsl:if>? E.G ---xml-- ... <movie> <title>T2</title> </movie> <movie>
2
by: websls | last post by:
I tried to do this : <xsl:if test="ToutCompris"> some output </xsl:if> ToutCompris is a boolean element in my XML file My problem is the output is parse even when ToutCompris is false I...
5
by: Luke Vogel | last post by:
Hi all, Probably a really basic question, but I cant find an answer ... I have an xml file of books something like: <product> <isbn>0-735-61374-5</isbn> <title>Microsoft Visual Basic Step By...
3
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion...
2
by: riceyeh | last post by:
Hi, What does <xsl:if test="not($values)"mean? What I do not understand is $values? Here, means array? And . = $value means current node is equal to the variable value? So the total meaning is...
4
by: Doulos05 | last post by:
Ok, this seems like it should be easy, but it has escaped me. Here is my xml file: <ref_sheet> <item> <date>2007/04/06</date> <product>124567</product> <description>TAB...
4
by: grbeal | last post by:
How do I test for a child element with xsl if condition? We have a vendor application that outputs an XML file containing records of School Closings due to inclement weather. That XML file gets...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.