Skip to content

Instantly share code, notes, and snippets.

@joewiz
Created May 6, 2015 17:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joewiz/138d06bf97cbe1e7b52f to your computer and use it in GitHub Desktop.
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
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