I am wondering if it is possible to use XPath or XSL to determine if a XML node value is numerical or alpha/numerical. (It is user entered data.. so it could be either..)
I was searching for some sort of function in XPath to do this.. but I couldn't find any.
for example:
<example>
<test1 attribute="123">12dfffg23</test1>
&开发者_开发知识库lt;test2 attribute="a34">123456</test2>
</example>
I need to test node content and attibutes:
/example/test1
/example/test1/@attribute
/example/test2
/example/test2/@attribute
And I would expect the following to be numerical:
/example/test1/@attribute
/example/test2
And I would expect the following to be alpha/numerical:
/example/test1
/example/test2/@attribute
Is it possible to do this with a function in XPath or XSL?
Thanks! :D
In XPath 1.0 use this to test whether a given string contains a number:
number(someString) = number(someString)
Use this to test whether a given string consists only of alphanumeric characters (letters or digits):
not(translate(someString, $alphabetLowerAndUpperAndDigits, ''))
where $alphabetLowerAndUpperAndDigitscan be substituted with all lowercase and uppercase letters and the digits (0-9) from the alphabet (for the latin alphabet this is:
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
In XPath 2.0: (all of the above plus)
matches(someString, '^[\c|\d]+$')
精彩评论