XSLT:查找字符串中的最后一次出现 [英] XSLT: Finding last occurence in a string
本文介绍了XSLT:查找字符串中的最后一次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个表单编号,例如:
Given a form number like:
ABC_12345_Q-10
我想结束:
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 解决方案没问题.
xPath 2.0 solutions are okay.
推荐答案
concat(
substring-before($s, '_'),
substring-before(substring-after($s, '_'), '_')
)
或者:
string-join(tokenize($s, '_')[position() <= 2], '')
这篇关于XSLT:查找字符串中的最后一次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文