Dominic,
You could instead build the sequence, merge it together and then replace the
whole meta node. Un-tested code:
Let $new-fields := for .... return <xm:field type='subject-link'> <xa:link Let
$old-meta := ...
Let $old-fields := $old-meta//xm:field
Let $new-fields := ($old-fields, $new-fields)
Let $new-meta :=
<xm:meta> {
{$old-meta/@*} (: keep all old attributes :)
{$old-meta/node()[local-name(.) ne "field"] (: keep all nodes except
fields :)
{$new-fields} (: add merged fields at the bottom :)
}
</xm:meta>
If you need the xm:meta to have the fields in the middle somewhere, that can be
done, but is trickier.
Yours,
Damon
From: [email protected]
[mailto:[email protected]] On Behalf Of Dominic Beesley
Sent: Wednesday, September 19, 2012 9:08 AM
To: 'MarkLogic Developer Discussion'
Subject: [MarkLogic Dev General] Multiple inserts, maintaining order
Hello,
I'm trying to insert multiple nodes into a document, the nodes are getting
inserted ok but the order is jumbled up.
I'm guessing this is something to do with how transactions are committed after
the script has finished.
Is there an easy way round this or a way of building a set of nodes in the
correct order and inserting them in one go to the parent?
Thanks
Dom
Snippet:
for $k in (
for $kk in $keys
return
$tax2//a[@id=$kk]
)
order by xs:integer($k/@index) descending
return
(
concat(' - ACTUAL=', $k/@name, ' - ', $k/@id, ' - ', $k/@index,
' '),
xdmp:node-insert-child(
$a/xm:meta,
<xm:field type='subject-link'>
<xa:link link-type='{
concat($a/@type, "-taxonomy-subject-law") }' dest-id='{ $k/@id }' />
</xm:field>
)
)
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general