Given a form number like:
ABC_12345_Q-10
I want to end up with:
ABC12345
So I need to find the position of the second underscore
Note that there is no standard pattern or length to any of the "sections" between the underscores (so I cannot use substring to simply eliminate the last section).
xPath 2.0 solutions are okay.
Alternatively:
Easier solution in XSLT 2.0:
With 'substring-before' you will get everything after the last occurrence of your delimiter (the underscore). If you use 'substring-after' instead, you will get everything before the last occurrence of your deliminator.
@Pavel_Minaev has provided XPath 1.0 amd XPath 2.0 solutions that work if it is known in advance that the number of underscores is 2.
Here are solutions for the more difficult problem, where the number of undrscores isn't statically known (may be any number):
XPath 2.0:
XSLT 1.0:
when this transformation is applied to any XML document (not used), the desired, correct result is produced:
Generalized one -
Idea is to get the index of last occurrence by splitting string.
Index of last occurrence = string-length($string) - length of last string after split