0

I have this xml document: " : " is the separator.

xml = """
<a>
    <b> 1,2,3 : 4,5,6 : 7,8,9 : 10,11,12 </b>
</a>
"""

How can I get the middle number in the last pair (i.e., 11) by using Xpath 1.0

I used the combination of substring-before and substring-after, but the result didn't work out as I wanted.

Update: Sometimes, it's not always only 4 pairs, sometimes only 1 pair, or 2 pairs, but maximum it can be up to 10 pairs. So all I want is to always get the middle number of the last pair out. How can I extract it?

Thank you for any ideas.

1 Answer 1

0

In 1.0 you would need a larger xpath like this:

substring-before(
    substring-after(
        substring-after(
            substring-after(
                substring-after(/a/b,':')
                ,':')
            ,':')
        ,',')
    ,',')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Siebe Sometimes, it's not always only 4 pairs, sometimes only 1 pair, or 2 pairs, but maximum it can be up to 10 pairs. So all I want is to always get the middle number of the last pair out. How can I extract it?

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.