XSLT: Finding last occurence in a string

前端 未结 4 1985
轮回少年
轮回少年 2020-12-18 00:55

Given a form number like:

ABC_12345_Q-10

I want to end up with:

ABC12345

So I need to find the position o

4条回答
  •  执念已碎
    2020-12-18 01:18

    Easier solution in XSLT 2.0:

    codepoints-to-string(reverse(string-to-codepoints(
        substring-before(
            codepoints-to-string(reverse(string-to-codepoints($s))), '_'))))
    

    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.

提交回复
热议问题