[xquery-talk] string manipulation

John Snelson jsnelson at sleepycat.com
Mon Feb 6 00:17:20 PST 2006

Michael Kay wrote:
>>In order to do what you want, you will need to use "fn:subsequence()":
>>string-join(subsequence(tokenize("book/title/author", "/"), 1, last() -
> 1), "/")
> No, there's nothing here that changes the context, so the value of last() is
> unrelated to the number of tokens returned by tokenize().

:-( I knew that. I just wasn't thinking straight. The correct version is:

let $tokens := tokenize("book/title/author", "/")
   string-join(subsequence($tokens, 1, count($tokens) - 1), "/")

>>Instead of that, you could also try:
>>replace("book/title/author", "/.*?$", "")
> No, the "/" here will match the first "/" in the expression.
>>let $str := "book/title/author" return
>>substring-before($str, concat("/", substring-after($str, "/")))
> No, this will return "book".
>>I'm sure there are other good ways to acheive the result you want.
> There are indeed.

That'll teach me to post responses without trying them out...


John Snelson, Berkeley DB XML Engineer
Sleepycat Software, Inc

Contracted to Sleepycat through Parthenon Computing Ltd

More information about the talk mailing list