Reputation: 177
I am looking for customization in sorting for the items coming from the MarkLogic database. While sorting double or single quote, dollar sign and all other punctuation should be ignored.
Below is the sample script:
xquery version "1.0-ml";
declare default collation "http://marklogic.com/collation/";
let $seq := ("a", "b", "1", "2", "$3", '"object"')
for $x in $seq
order by $x ascending
return $x
Upvotes: 2
Views: 213
Reputation: 66851
By setting the default collation, or specifying a collation in the order by
to http://marklogic.com/collation/en/S1/T00BB/AS
will handle the majority of your requirements (quote and punctuation insensitive).
However, $
is not an ignored character. You can remove $
, and any other character that you do not want to affect the sort order, by using the fn:translate()
function:
xquery version "1.0-ml";
let $seq := ("a", "b", "c", "1", "2", "$3", '"object"')
for $x in $seq
order by fn:translate($x, "$", "") ascending collation "http://marklogic.com/collation/en/S1/T00BB/AS"
return $x
Upvotes: 2
Reputation: 4241
You can use fn:replace(...)
to delete all non-word characters (and $
, which seems to be considered a Word
character, at least by BaseX) from each string:
let $seq := ("a", "b", "1", "2", "$3", '"object"')
for $x in $seq
order by replace($x, '[\W\$]', '') ascending
return $x
Upvotes: 1