xpathxqueryxpath-3.0

XPath expression to access each element of a string


This question may sound very basic; however, I have been trying to find some resources related to it.

Let's say there is a sequence of characters or strings:

let $abc := ('a', 'b', 'c', 'd', 'e', 'f')
return (for $i in $abc return $i)

Above query will give me individual elements of a sequence.

However, if I have only a single string, how to retrieve each element of it?

e.g. let $abc = "abc"

How to fetch 'a' from $abc, is there any $abc[0] as such to do so?


Solution

  • You can also use

    for $char in string-to-codepoints($abc)!codepoints-to-string(.)
    return ...