Siddhu
Siddhu

Reputation: 327

Splitting a string into two strings in xquery

Here is the string

a = "http://www.peoples.net/mcfnet/viewtopic.php?f=143&t=4898958&sid=2110d616dbad926"

Now, we need to split this string into two and need a single string.

expected output is:

b = "http://www.peoples.net/mcfnet/viewtopic.php?f=143&t=4898958&"

Upvotes: 2

Views: 1576

Answers (2)

John Smith
John Smith

Reputation: 1172

Try using the substring function

I think with the substring-before-match you can do what you want, or try take a look on the other substring's function.Check this link.

Upvotes: 1

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243479

You want to get all of the original string except the last query-string parameter.

Here is a single XPath 2.0 expression to produce this string from the original, which is defined in a variable named $vA:

 codepoints-to-string
        (
         reverse
           (string-to-codepoints
                (substring-after
                    (codepoints-to-string
                        (reverse(string-to-codepoints($vA))
                     ),
                   '&'
                 )
            )
          )
        )

Explanation:

  1. We turn the string into a sequence of characters using string-to-codepoints() and reverse this sequence using reverse(). Then we turn the reversed sequence of characters back to a string using `codepoints-to-string.

  2. From the reversed string (produced by 1. above) we get the substring after the first &. We do this using substring-after()

  3. This is our result, but reversed -- we reverse it back to normal, using exactly the same logic as in step 1. above.

Upvotes: 0

Related Questions