Newbie XSLT question :
I have a string consisting of 3 parts separated by dots : "2120.555.11111"
How do I remove the middle part so I end up with "2120.11111" ?
(The string parts length might not be constant)
2 Answers
XPath 1.0, individual steps for posterity:
substring-before('2120.555.11111', '.') # '2120'
concat('2120', '.') # '2120.'
substring-after('2120.555.11111', '2120.') # '555.11111'
substring-after('555.11111', '.') # '11111'
concat('2120.', '11111') # '2120.11111'
combined, assuming <X> contains '2120.555.11111':
concat(
concat(substring-before(X, '.'), '.'),
substring-after(substring-after(X, concat(substring-before(X, '.'), '.')), '.')
)
XPath 2.0+ is more flexible with string processing, this is one way to do it:
string-join(tokenize(X, '\.')[position() = 1 or position() = 3], '.')