By using xsl template, can any one tell me the way to get first number portion of a string field
For example:
'12' -> should result in -> 12
'5 ASDF' -> should result in -> 5
'34SDF56' -> should result in -> 34
By using xsl template, can any one tell me the way to get first number portion of a string field
For example:
'12' -> should result in -> 12
'5 ASDF' -> should result in -> 5
'34SDF56' -> should result in -> 34
Here is a one-liner XPath solution: :)
when this transformation is applied on the following XML document:
the wanted, correct results are produced:
you could give this a go? should work supposing that you know the maximum length of numbers!
so here you could find a number upto 6 digits long! hope it helps
The following template will emit all numeric digits of a string up to the first non-numeric (without having to know how many digits may be in the number):
(Thanks to @Alejandro for the key idea, using substring() to get the first non-number, and then passing it to substring-before().) Here it is in the context of an identity transform:
When run on the following input:
it produces the requested output:
Another way to do the
@num
template is the following, arguably more elegant but harder to read IMO:Notes: