0

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 2

1

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], '.')
Sign up to request clarification or add additional context in comments.

Comments

0

In XSLT 2.0 or higher, you could do simply:

replace(input, '\..*\.', '.')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.