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
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.")
Hi Christian --
*> The document order can only be restored if the result of an expression is a sequence of nodes.*
Thank you! That does help, in as much as I was thinking that the order came from the left side, not the right side. I feel much less confused now.
(I used an if in the original of the real code from which the example was derived and my brain kept insisting it was inaesthetic, presumably from too much xsl:apply-templates.)
Much appreciated! Graydon
On Fri, Jul 7, 2023 at 3:17 AM Christian Grün christian.gruen@gmail.com wrote:
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.")
basex-talk@mailman.uni-konstanz.de