I feel like I should know how to do this (and possibly I’ve previously been told how and have forgotten), but I’m at a loss.
I am implementing a process that gathers nodes from a single document (a DITA map) and constructs a system of maps where I’m using the maps primarily to represent a tree and enable lookup of things by key.
However, the order of the elements that make up these maps is also important (DITA’s rules for how you build DITA key spaces from maps depends entirely on document order).
For example, I have a map that maps “key names” to the elements that declare those key names, i.e.:
map { “key-01” : (<topicref keys=”key-01” href=”foo.dita”/>, <topicref keys=”key-01” href=”bar.dita”/>) }
This is the initial state of the map (reflecting pass 1 over the DITA map document) but then I need to add additional elements to the sequence that is the value of entry “key-01” and I need the resulting sequence to be in document order.
So my question: given two sequences of nodes from the same document, how does one construct a new sequence where the nodes are in document order?
Thanks,
Eliot _____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.comhttps://www.servicenow.com LinkedInhttps://www.linkedin.com/company/servicenow | Twitterhttps://twitter.com/servicenow | YouTubehttps://www.youtube.com/user/servicenowinc | Facebookhttps://www.facebook.com/servicenow
Am 04.07.2022 um 17:11 schrieb Eliot Kimber:
I feel like I should know how to do this (and possibly I’ve previously been told how and have forgotten), but I’m at a loss.
I am implementing a process that gathers nodes from a single document (a DITA map) and constructs a system of maps where I’m using the maps primarily to represent a tree and enable lookup of things by key.
However, the order of the elements that make up these maps is also important (DITA’s rules for how you build DITA key spaces from maps depends entirely on document order).
For example, I have a map that maps “key names” to the elements that declare those key names, i.e.:
map { “key-01” : (<topicref keys=”key-01” href=”foo.dita”/>, <topicref keys=”key-01” href=”bar.dita”/>) }
This is the initial state of the map (reflecting pass 1 over the DITA map document) but then I need to add additional elements to the sequence that is the value of entry “key-01” and I need the resulting sequence to be in document order.
So my question: given two sequences of nodes from the same document, how does one construct a new sequence where the nodes are in document order?
$seq1 | $seq2 should do, if you want duplicates eliminated.
Am 04.07.2022 um 17:14 schrieb Martin Honnen:
Am 04.07.2022 um 17:11 schrieb Eliot Kimber:
I feel like I should know how to do this (and possibly I’ve previously been told how and have forgotten), but I’m at a loss.
I am implementing a process that gathers nodes from a single document (a DITA map) and constructs a system of maps where I’m using the maps primarily to represent a tree and enable lookup of things by key.
However, the order of the elements that make up these maps is also important (DITA’s rules for how you build DITA key spaces from maps depends entirely on document order).
For example, I have a map that maps “key names” to the elements that declare those key names, i.e.:
map { “key-01” : (<topicref keys=”key-01” href=”foo.dita”/>, <topicref keys=”key-01” href=”bar.dita”/>) }
This is the initial state of the map (reflecting pass 1 over the DITA map document) but then I need to add additional elements to the sequence that is the value of entry “key-01” and I need the resulting sequence to be in document order.
So my question: given two sequences of nodes from the same document, how does one construct a new sequence where the nodes are in document order?
$seq1 | $seq2 should do, if you want duplicates eliminated.
Otherwise perhaps
sort(($seq1, $seq2), (), function($n) { index-of(($seq1 | $seq2)!generate-id(), generate-id($n))})
Hi Eliot,
As a generalized solution (for an arbitrary number of inputs), you can attach a self::node() step (or a simple context item expression "."):
($nodes1, $nodes2, $nodes2)/self::node()
The resulting expression will be evaluated as path, and the result will be brought into distinct document order. We’ve added a function for that to make the clean/sort operation more explicit [1].
Cheers, Christian
[1] https://docs.basex.org/wiki/Utility_Module#util:ddo
On Mon, Jul 4, 2022 at 5:29 PM Martin Honnen martin.honnen@gmx.de wrote:
Am 04.07.2022 um 17:14 schrieb Martin Honnen:
Am 04.07.2022 um 17:11 schrieb Eliot Kimber:
I feel like I should know how to do this (and possibly I’ve previously been told how and have forgotten), but I’m at a loss.
I am implementing a process that gathers nodes from a single document (a DITA map) and constructs a system of maps where I’m using the maps primarily to represent a tree and enable lookup of things by key.
However, the order of the elements that make up these maps is also important (DITA’s rules for how you build DITA key spaces from maps depends entirely on document order).
For example, I have a map that maps “key names” to the elements that declare those key names, i.e.:
map { “key-01” : (<topicref keys=”key-01” href=”foo.dita”/>, <topicref keys=”key-01” href=”bar.dita”/>) }
This is the initial state of the map (reflecting pass 1 over the DITA map document) but then I need to add additional elements to the sequence that is the value of entry “key-01” and I need the resulting sequence to be in document order.
So my question: given two sequences of nodes from the same document, how does one construct a new sequence where the nodes are in document order?
$seq1 | $seq2 should do, if you want duplicates eliminated.
Otherwise perhaps
sort(($seq1, $seq2), (), function($n) { index-of(($seq1 | $seq2)!generate-id(), generate-id($n))})
Of course—I should have been able to remember that, although it is not exactly obvious.
Thanks for the function—that definitely makes it clearer what the intent is.
Cheers,
Eliot
_____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.comhttps://www.servicenow.com LinkedInhttps://www.linkedin.com/company/servicenow | Twitterhttps://twitter.com/servicenow | YouTubehttps://www.youtube.com/user/servicenowinc | Facebookhttps://www.facebook.com/servicenow
From: BaseX-Talk basex-talk-bounces@mailman.uni-konstanz.de on behalf of Christian Grün christian.gruen@gmail.com Date: Monday, July 4, 2022 at 10:35 AM To: Martin Honnen martin.honnen@gmx.de Cc: BaseX basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] How To: Sort nodes in document order? [External Email]
Hi Eliot,
As a generalized solution (for an arbitrary number of inputs), you can attach a self::node() step (or a simple context item expression "."):
($nodes1, $nodes2, $nodes2)/self::node()
The resulting expression will be evaluated as path, and the result will be brought into distinct document order. We’ve added a function for that to make the clean/sort operation more explicit [1].
Cheers, Christian
[1] https://urldefense.com/v3/__https://docs.basex.org/wiki/Utility_Module*util:...https://urldefense.com/v3/__https:/docs.basex.org/wiki/Utility_Module*util:ddo__;Iw!!N4vogdjhuJM!EpBmorLdRqwgF_sFWHiKISiLZoezQRaMuvHbjb0H5zBgTHux9qEmOLss_rHLFMCGkB5eyfVsQ4ryZG6Jhlwdsqbk09MtVVo$
On Mon, Jul 4, 2022 at 5:29 PM Martin Honnen martin.honnen@gmx.de wrote:
Am 04.07.2022 um 17:14 schrieb Martin Honnen:
Am 04.07.2022 um 17:11 schrieb Eliot Kimber:
I feel like I should know how to do this (and possibly I’ve previously been told how and have forgotten), but I’m at a loss.
I am implementing a process that gathers nodes from a single document (a DITA map) and constructs a system of maps where I’m using the maps primarily to represent a tree and enable lookup of things by key.
However, the order of the elements that make up these maps is also important (DITA’s rules for how you build DITA key spaces from maps depends entirely on document order).
For example, I have a map that maps “key names” to the elements that declare those key names, i.e.:
map { “key-01” : (<topicref keys=”key-01” href=”foo.dita”/>, <topicref keys=”key-01” href=”bar.dita”/>) }
This is the initial state of the map (reflecting pass 1 over the DITA map document) but then I need to add additional elements to the sequence that is the value of entry “key-01” and I need the resulting sequence to be in document order.
So my question: given two sequences of nodes from the same document, how does one construct a new sequence where the nodes are in document order?
$seq1 | $seq2 should do, if you want duplicates eliminated.
Otherwise perhaps
sort(($seq1, $seq2), (), function($n) { index-of(($seq1 | $seq2)!generate-id(), generate-id($n))})
basex-talk@mailman.uni-konstanz.de