Hi Graydon,
The document order can only be restored if the result of an expression is a sequence of nodes. In the given case, …
analyze-string($test,'\p{Lu}')/( fn:match/concat('[',.,']'), fn:non-match/string() )
…two string sequences are generated (for matches and non-matches) which have no inherent relationship to the original nodes:
• matches: ”[A]”, ”[O]”, ”[L]” • non-matches: ”nd”, “ ”, “ord the …”
You have already presented a version that works. Here’s another one-liner that creates a new result for each (non-)match element in the original order:
let $syntax2 := string-join(analyze-string($test,'\p{Lu}')/* ! (if(self::fn:match) then '[' || . || ']' else .))
Hope his helps, Christian
On Fri, Jul 7, 2023 at 3:32 AM Graydon Saunders graydonish@gmail.com wrote:
Hello --
Using BaseX 10.6, the test query
let $test as xs:string := "And O Lord the pride of man, broken in the dust again"
let $syntax1 as xs:string := analyze-string($test,'\p{Lu}')/(fn:match/concat('[',.,']'),fn:non-match/string()) => string-join('')
let $syntax2 as xs:string := analyze-string($test,'\p{Lu}')/*/(self::fn:match/concat('[',.,']'),self::fn:non-match/string()) => string-join('')
return ($syntax1,$syntax2)
produces
[A][O][L]nd ord the pride of man, broken in the dust again [A]nd [O] [L]ord the pride of man, broken in the dust again
I'm surprised by this, because I expected document order to apply to the result of analyze-string and for syntax1 to work in the sense of having the results emerging in the same order as the input.
Have I miscomprehended something? Anyone care to have a go at explaining why syntax1 doesn't maintain the order of the input? (I'm possibly mistakenly confident that I understand why syntax2 does.)
Thanks! Graydon
-- Graydon Saunders | graydonish@fastmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")