473,569 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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&quo t;">

<!-- This doesn't work -->
<xsl:if test="string($v ar: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="DexRace s/DexRace">
<xsl:variable name="var:v141"
select="fctequa l(string(Code/text()),&quot;1 &quot;)"/>
<xsl:if test="string($v ar:v141)=&quot; true&quot;">
<xsl:variable name="var:v142" select="&quot;t rue&quot;"/>
<RaceAIorANHMDA ><xsl:value-of select="$var:v1 42"/></RaceAIorANHMDA>
</xsl:if>
</xsl:for-each>

neither version of the function helps:

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

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

Nov 12 '05 #1
3 3590
Eric Theil wrote:
<xsl:variable name="var:v141"
select="fctequa l(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(s tring(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)=&quo t;true&quot;"/>

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

Eric

"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:us******** ******@TK2MSFTN GP11.phx.gbl...
Eric Theil wrote:
<xsl:variable name="var:v141"
select="fctequa l(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(s tring(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)=&quo t;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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" xmlns:var="var"
xmlns:msxsl="ur n:schemas-microsoft-com:xslt"
xmlns:user="htt p://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.Equal s(value2))
{
return "true";
}
return "false";
}
</msxsl:script>
<xsl:template match="/">
<xsl:for-each select="*">
<xsl:variable name="var:v141"
select="user:fc tequal(string(t ext()),&quot;1& quot;)"/>
<xsl:if test="string($v ar:v141)=&quot; true&quot;">
<xsl:variable name="var:v142" select="&quot;t rue&quot;"/>
<RaceAIorANHMDA >
<xsl:value-of select="$var:v1 42"/>
</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
3889
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> <xsl:number count="LoanRecord" format="1"/><br/> Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/> Calculated CLTV:<xsl:value-of...
9
8313
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"/> On the XSLt file relayed to this XML, i wrote in green the attribute value if Attribute "Esito" is "Ok". I mean, something, like this:
2
10796
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
1731
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 tried <xsl:if test="ToutCompris = true"> and it does'nt work either
5
2325
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 Step</title> <author>Michael Halvorsen</author> <subject>Programming</subject>
3
14271
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 with a conversion or correct syntax? I would like to test the current page number and see if it is even or odd - and if it is odd I would like to...
2
13682
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 "if not exists of value in array of values" ? But the result of '. = $value' is a boolean value, so '$values' should not mean "the value in values"....
4
2964
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 DIVIDERS</description> <note>Description of problem here</note>
4
4403
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 FTP'd to my web host when the Access database is changed. I'm using Dreamweaver to create an XSLT fragment to read the XML file and include the HTML...
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
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.