Created
May 6, 2015 17:53
-
-
Save joewiz/138d06bf97cbe1e7b52f to your computer and use it in GitHub Desktop.
Turn a whitespace-delimited string of text into an XQuery-style sequence string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
(: Sometimes you need to turn a list of words into a sequence-style string :) | |
declare function local:string-to-sequence($string as xs:string) as xs:string { | |
let $string := normalize-space($string) | |
let $items := tokenize($string, '\s') | |
let $quoted := $items ! concat("'", ., "'") | |
return | |
concat( | |
'(', | |
string-join($quoted, ', '), | |
')' | |
) | |
}; | |
local:string-to-sequence(' frus1948v04 frus1948v06 frus1948v09 | |
frus1949v09 | |
frus1950v04 frus1950v05 frus1950v06 frus1950v07 | |
frus1951v02 frus1951v03p1 frus1951v03p2 frus1951v04p1 frus1951v04p2 frus1951v07p1 frus1951v07p2 ') | |
(: | |
will return: | |
('frus1948v04', 'frus1948v06', 'frus1948v09', 'frus1949v09', 'frus1950v04', 'frus1950v05', 'frus1950v06', 'frus1950v07', 'frus1951v02', 'frus1951v03p1', 'frus1951v03p2', 'frus1951v04p1', 'frus1951v04p2', 'frus1951v07p1', 'frus1951v07p2') | |
:) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment