Click here to Skip to main content
15,886,088 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
Hello,

I do not understand why I get the following error from XPath:

XML
1.
   <xsl:choose>
           <xsl:when test="$rownr = 0">
                   <xsl:attribute name="FontSize" select=" '24 px' "/>
                   <xsl:attribute name="Foreground" select=" 'MidnightBlue' "/>
           </xsl:when>
   </xsl:choose>

   <!-- Warning: Required item type of first operand of '=' is numeric; supplied value has item type xs:string -->


All I understand from it, is that the variable $rownr is supposed to be given a numeric value as right operand. I do not understand that, because $rownr is of an undefined type (I think) and the right operand is already numeric, i.e. 0 and not '0' (I think).

How do I fix this and what is really going on in my code?
I am using EditX Xml Editor free version.

Thank you

//Edit: I have fixed it by writing this:
<xsl:param name="rownr">0</xsl:param>

I do not know why the error was fixed this way.
Can someone please tell me?

Thank you
Posted
Updated 8-Jul-11 5:31am
v6
Comments
#realJSOP 8-Jul-11 10:45am    
DO NOT REPOST YOUR QUESTION.
Doc Lobster 8-Jul-11 12:05pm    
Have you experimented with xpath 2.0 functions? There are some allowing to convert item types, e.g. fn:string(0) or fn:number($rownr).

1 solution

The XSLT specification[^] for variables says,

If the variable-binding element has empty content and does not have a select attribute, then the value of the variable is an empty string.


Because it's defined as an empty string (not undefined) this is why it doesn't compare to a number without warning.
 
Share this answer
 
Comments
Neo10101 13-Jul-11 5:05am    
Thank you for the solution. I find it quite misleading though. <!-- Warning: Required item type of first operand of '=' is numeric; supplied value has item type xs:string --> that is like saying that the left operand I supplied is numeric (as opposed to the truth, which is: "the left operand has to be numeric and the one you supplied is not"). Quite ambiguous.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900