How do you currently proceed?
I have two queries that add attributes to a morphology I am processing. Ideally, I would like each attribute to be added at the end of the attribute list, after any existing attributes.
The first adds an @after attribute if there is a space or punctuation after the token:
declare function local:segs($nodes) { if (head($nodes)[self::*:seg]) then concat(string(head($nodes)), local:segs(tail($nodes))) else () };
declare variable $oshb := db:open("oshb-morphology");
for $w in $oshb//*:w let $next := $w/following-sibling::*[1] where $next let $after := if ($next[self::*:w]) then " " else if ($next[self::*:seg]) then local:segs($w/following-sibling::*) else "" return insert node attribute after {$after} into $w
The second adds Book-Chapter-Verse-Word-Part numbering:
let $oshb := db:open("oshb-morphology") for $verse in $oshb//*:verse order by local:bcv($verse/@osisID) for $w at $i in $verse/*[self::*:w or self::*:c] for $p at $j in local:entities($w) let $id := local:bcvwp($verse/@osisID, $i, $j) return ( delete node $p/@n, insert node attribute n {$id} into $p )
On Thu, Feb 10, 2022 at 4:34 AM Christian Grün christian.gruen@gmail.com wrote:
Hi Jonathan,
Is there any way for me to control the order of attributes in BaseX when
I insert new attributes?
If you evaluate the following XQuery expression in BaseX …
<a b='b' c='c'/>
… you can be sure that the attributes will be placed in the original order. Please note that we cannot give a guarantee that this will stay that way forever, even though it’s unlikely to change.
If you have an existing element, you can reinsert all attributes in the order you want:
let $a := <a b='b' c='c'/> return element { node-name($a) } { $a/@*, attribute d { 'd' }, $a/node() }
How do you currently proceed?
Best, Christian