473,379 Members | 1,491 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,379 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 3573
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...
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...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.