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)
}



0
Eric
1/13/2004 10:09:35 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
720 Views

Similar Articles

[PageSpeed] 50

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
0
Oleg
1/15/2004 8:24:28 AM
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:usJ39C02DHA.1392@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


0
Eric
1/15/2004 3:01:58 PM
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
0
Oleg
1/15/2004 3:16:43 PM
Reply:

Similar Artilces:

in C# fastest way to convert a string into a MemoryStream
in C# fastest way to convert a string into a MemoryStream new MemoryStream(Encoding.UTF8.GetBytes(yourString)); But if the string is very large you may want to call Encoding.UTF8.GetEncoder() then encoding the string in buffer chunks and write those chunks to the memory stream. "Daniel" <softwareengineer98037@yahoo.com> wrote in message news:%23r4B$S7lFHA.3584@TK2MSFTNGP10.phx.gbl... > in C# fastest way to convert a string into a MemoryStream > > ...

Countif function to show how often numbers within a range are pres
I use a sheet to track when I receive items, once per day, and I log the time in 24 HR format using numbers, no formatting. I want to be able to count how many times in a row (Month) the number is between two numbers to help me identify if I get the items in morning, afternoon, evening. I think I would use countif but I don't know how to have it count each time the number in the cell is between the hours I determine. I think it would look like: countif(range,<>1:1159) or something similar but I can't figure it out. Any help would be greatly appreciated! Than...

string concatenation #2
I wish to do it all in Excel ... Is it difficult to "write a program" in VBA or something? Can it be some kind of combination b/w macro and formulas? I've just started to learn Excel :- -- CaptainHoo ----------------------------------------------------------------------- CaptainHook's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1637 View this thread: http://www.excelforum.com/showthread.php?threadid=27754 What are you trying to concatenate? If you have text CLOWN in cell A1 and the text FISH in cell B1, you can put this formula in C1: =A1&...

XSL feed-- Metadata -Deployement Mgr
hi when we publish from deployement manager the xsl files are getting changed!!! my question is from which table(or tables) of the MSCRM, the metadata for the XSL is feeded??? Thanks in advance OrganizationUIBase Mike greaterthantwo media Printable Quotes, Orders and Invoices, with line-item details, now available for MSCRM. http://www.greaterthantwo.com "Apple" <none@nospam.com> wrote in message news:ueXyX%233%23DHA.3536@TK2MSFTNGP10.phx.gbl... > hi > when we publish from deployement manager the xsl files are getting > changed!!! > > my question is fro...

FORECASTING SALES (please let this be a worksheet function)
Hi I have recently been given the task by my boss to forecast one of ou key customers monthly usage until monthly until end of 2006, I am starting with this customers indidual branches monthly usage fo the past 3 years, Some branches will have opened and closed during thi time, And i am looking to be able to predict monthly usage for the nex 18 months Has anyone got any idea's on the best way to forcast within excel, I a currently using trend (fomulae given to me on this sight) but people ar saying this is not the best way Exponentionally has been mentioned by a few of my collegues but...

Tax on Postage function needed
I use Microsoft Excel for writing invoices. In the standard invoice, Tax (GST) on Shipping and Handling is not calculated and added to the total. I want someone to fix this, so Goods and Services Tax (GST) will be calculated and added on Postage and Handling in the total amount. At present, Shipping and Handling is set fixed. I want to be able to enter diferent amount each time without going to Customize Page and setting it there. Thank you in advance for your help. Best regards, John PS: Below I have included the xls file. It is a bit messy. Tax Invoice No. 2089 ...

XML String and Typed Dataset
Please i have an webservice that receives a XML string that i convert it to a dataset. How can i validate this XML, against a typed dataset schema? Tks in adv. Fabiano ...

Custom Functions: Order Of Execution?
I finally figured out that the reason I couldn't find the source code in a .XLA file was that .XLA's are compiled versions of .XLS'. Now I've tracked down the .XLS file, but can't figure out how to follow the coding. Check out http://tinyurl.com/3obxl I'm 99.99% sure that the entry point is the cell "ROR"...but the rest escapes me. Could somebody offer a general view of what's going on here? Not necessarily the precise logic - more the order in which things happen so I can pick it apart on my own. -- PeteCresswell ...

Creating one xml doc from mutliple strings selected from database
Hi, tried this a few weeks ago, but still need some help. I have a simple database table, fields: Customer, WorkOrder, xmlDoc. The xmlDoc fields contains a small blob of xml data, such as: <WorkOrder> <ProductID/> <OrderDate/> <ProductGroup> <SerialNo/> <SerialNo/> <SerialNo/> </ProductGroup> </WorkOrder> Based on a SQL query such as SELECT xmlDoc WHERE Customer = "xyz", I need to: 1) Create a new xmlDocument with only a root element such as <NewQuery>. 2) Bring each xmlDoc blob into th...

xsl:with-param fails in XSL that accepts arguments from XML control
Hi, why does with-param fail to send parameters to any templates in a stylesheet that also accepts arguments from the ASP.NET XML control? The argument from the XML control seems to be available to any template in the stylesheet, even if a parameter for the argument is NOT coded for a template call. On the other hand, any parameters coded for a template call don't seem to pass their values (the stylesheet doesn't crash - everything is still rendered). ASP.NET C# code that loads the xml control xmlCtrl.TransformSource="template.xsl"; XsltArgumentList args1 = new XsltArgum...

How to use a cell value as Table Array in VLOOKUP worksheet function
I need to use VLOOKUP for a spreadsheet I'm running and need to use the value in a cell as the name of the table array for VLOOKUP. Is this possible ? -- willydlish ------------------------------------------------------------------------ willydlish's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=19985 View this thread: http://www.excelforum.com/showthread.php?threadid=345737 With the name in A1: =VLOOKUP(---,INDIRECT(A1),---,---) HTH Jason Atlanta, GA >-----Original Message----- > >I need to use VLOOKUP for a spreadsheet I'm running and ...

VBA ln function
I have this code that I have put together and it works fine as long as none of my numbers are "0's" or blank cells. 'Inserts A Header and formula Range("AU2").Select ActiveCell.FormulaR1C1 = "A" Range("AU3").Select ActiveCell.FormulaR1C1 = _ "=EXP(INDEX(LINEST(LN(RC[-25]:RC[-15]),R1C22:R1C32),1,2))" 'Inserts B Header and formula Range("AV2").Select ActiveCell.FormulaR1C1 = "B" Range("AV3").Select ActiveCell.FormulaR1C1 = "=I...

Is there a maximum number of FIND functions?
I am using this function successfully =IF(NOT(ISERROR(FIND(" FLR",AC11))),FIND(" FLR",AC11),IF(NOT(ISERROR(FIND("FLOOR",AC11))),FIND("FLOOR",AC11), IF(NOT(ISERROR(FIND(" RM ",AC11))),FIND(" RM ",AC11), IF(NOT(ISERROR(FIND(" ROOM ",AC11))),FIND(" ROOM ",AC11), IF(NOT(ISERROR(FIND("SUITE",AC11))),FIND("SUITE",AC11)))))) However, if I add another row, Excel tells me I have an error and highlights the very next FIND IF(NOT(ISERROR(FIND("BLDG",AC11))),FIND("BLDG",AC11) I did n...

copy value of LPCTSTR to string or CString
Hello- I can't figure out for the life of me how to copy the value of a LPCTSTR to a string or CString. I am trying to get the text from a TV_ITEM and put in a a constant. I am getting the value and doing a SetDlgItemText() with it successfully, but I need to be able to manipulate the string first. Thanks! I'm using VS.NET 2003 on XP. "99miles" <pub@magusdesigns.com> wrote in message news:f951419a.0311141518.24acaf5c@posting.google.com... > Hello- > I can't figure out for the life of me how to copy the value of a > LPCTSTR to a string or CString. CStr...

decimal precision on a string field
Hello, I hope my issue isn't to difficult. I would like to truncate the number of decimals shown in a value (Value A) based on a value contained within another field (Value B). (i.e. if (Value A) = 1234.567 and (Value B) = 2, I would like to only return 1234.56 if (Value B) = 1, I would like to return 1234.5 The problem is that field A is a string field, and DOES contain non-numeric values. I keep ketting errors when I try to use variations of the follwing syntax within a formula field. if isnumeric ({WB_REPORT_DATA.RESULT}) = true then (tonumber({WB_REPORT_DATA.RESULT})) ...

Gloabal Functions
There are many times that a "global" function would be nice instead of writing the code over and over on each "OnChange" event. Something as simple as setting Proper Case has to be added to so many places and any time a small change is needed it is an ordeal implementing due to the number of place this change has to be made. Using the Global.js is not a good solution because most of my users have the Laptop installation...I would have to find a way to push this out to the users every time a change is made. Currently this would have to be manually. --------------...

which function is used when drag & drop to explorer, to create a legal filename ?
Hy to everybody ... and thx for your help. I have written a small tool to save my outlook E-mails to .msg files The filename of the .msg file is build on the SUBJECT of the mail But a lot of forbiden characters (for windows/DOS) could exist in this subject ! Then I need to replace them by ... for exemple '_' I'm using the <replace> command in VB but ... sometimes ... a bad characters continue to worry me. ;-)) When you drag & drop a mail from Outlook in the explorer, the "save" is done with a good filename based on the subject of the mail but WITHOUT the for...

counting text strings
This is probably really simple - but how can i count how many cells in colum contain a certian text varible ? =countif(a:a,"sometext") will count the number of cells in column A that are equal to "sometext" =countif(a:a,"*sometext*") will count the number of cells in column A that contain "sometext" Keith Rathband wrote: > > This is probably really simple - but how can i count how many cells in colum > contain a certian text varible ? -- Dave Peterson ...

Problem when Loading XSL file using XslCompiledTransform
Hi, I am testing the scenario to migrate from MSMXL4 to .NET2.0 system.xml. I experienced xsl file loading problem whenever the xsl file have a user defined script in it. The error message is as follow: "Objects of type 'Script2' do not have such a member" The above error only happens when I set the XsltSettings.TrustedXslt ans use the following statement to load xsl file: objxslcompiledtransform.Load(input, XsltSettings.TrustedXslt , new XmlUrlResolver()); Can anyone tell me what is happening here? Sample Xsl script: <msxsl:script language="javascript" ...

table
with a vba macro I populated a table, the size of this table is variable in each execute this macro. and with this table I create pivot table, Database functions, but How to use all resources with all data? suggestions and examples thanks Marina Hi Marina Create a dynamic named range for your data. Insert>Name>Define>Mydata Refers to =OFFSET($A$1,0,0,COUNTA(A:A),10) The above example would create a range which contained as many rows as are present in column A, and the would be 10 columns wide. Change the formula as appropriate to your data location. Then in the Pivot Tab...

Horrible looking IF function....
I using the IF function to enter a certain value from another workbook into a cell, but if that value happens to be 0, to enter "" (blank). My reference is quite a long winded expression using VLOOKUP, and I find that I have to enter the expression twice within the formula, once in the first argument for IF followed by <>0, and again in the second argument for IF, to show what I want in the cell if the first condition is true. Basically, something like this, itself has an IF function and VLOOKUP function amongst others... =IF([expression]<>0,[expression],"&qu...

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&quo...

Help with query string
here my string: querystring = "SELECT DISTINCT item_id FROM p21_view_invoice_hdr_salesrep as b,p21_view_invoice_line As a " querystring = querystring & "WHERE invoice_no = invoice_number AND a.date_created> " & DateStart & " " querystring = querystring & "and a.date_created<" & DateEnd & " " querystring = querystring & " AND b.salesrep_id= " & SalesRep & " " querystring = querystring & "AND (cogs_amount<>$0) this is my query string and it's not returning a...

Networkdays function help
Hi all, After your prompt success helping me before, I'm back for more help. I want to include all the public holidays in the function, I tried selecting a few cells with the dates in, but that didn't work. It moved the cell array on for each row, bugger. So I want a list of dates in the function: =NETWORKDAYS(B3,H3,2/1/6) This works, so how do I add further details in? I imagine it's just a matter of syntax, I've tried comma, semicolon, colon, quotes and no quotes, but this hasn't worked. Anyone shed some light on this? -- MattG Perhaps I'm confused, but if you...

is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data?
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? i mean xls not xsl "Daniel" <softwareengineer98037@yahoo.com> wrote in message news:eDjijGEeFHA.2584@tk2msftngp13.phx.gbl... > is it possible to execute write to the fields in another .xsl form a macro > in another .xsl? e.g. some way to load another .xsl into an .xsl macro and > write to its data? > > Both workbooks are open? workbooks("book1.xls").worksheets("sheet1")...