How can I test if value of element is a number / is castable to number?
What I need to do is to copy value if it is a number, and substitute it wi开发者_开发问答th 99 if it is a string
string(number($x)) = 'NaN' tests whether $x is castable to a number.
You could use the 'number' function -
http://www.zvon.org/xxl/XSLTreference/Output/function_number.html
In addition to the correct answer by @Michael Kay:
number($x) = number($x)
this expression is true() exactly when $x is castable to a number
Here we use the fact that:
- If - $xisn't a number, then- number($x)by definition is- NaN
- NaNisn't equal to any value, even to- NaN
Now, your final question:
What I need to do is to copy value if it is a number, and substitute it with 99 if it is a string
Use:
  $x * (number($x) = number($x))
+
  99 * not(number($x) = number($x))
Explanation:  A boolean is converted to number (true()  --> 1, false() --> 0) when part of a numeric expression. In the above expression one of the arguments of + will be 0 and one will be 1 depending on whether $x isn't/is a number.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论