2

How do I create a "single" result of one notes element as the root node, with multiple child nodes of note elements?

Here's the query in eXide:

xquery version "3.0";
    
for $note in collection('/db/tmp')/note
return <notes>{$note}</notes>

where the output is:

nicholas@mordor:~/flwor$ 
nicholas@mordor:~/flwor$ lynx http://localhost:8080/exist/rest/db/scripts/notes.xq --dump
<notes>
    <note>
bar
</note>
</notes>
<notes>
    <note>
foo
</note>
</notes>nicholas@mordor:~/flwor$ 
nicholas@mordor:~/flwor$ 

How can I get a single document, with a single root element of notes which Firefox won't choke on?

there are two files, foo.xml and bar.xml in the collection.

  • It is really helpful - actually necessary - to add an example of the data you want to query. Sometimes even the collection structure is important. Please keep that in mind for your next question here. – line-o Nov 22 '20 at 13:08

1 Answers1

2

XML must have exactly one root element. Also without knowing the structure in the data I would assume you want to get all notes regardless how deep they are nested. To achieve that use collection($col)//note

xquery version "3.1";
    
<notes>
{
  for $note in collection('/db/tmp')/note
  return $note
}
</notes>

or

xquery version "3.1";
    
<documents>
{
  for $doc in collection('/db/tmp')/document()
  return <notes>{$doc/note}</notes>
}
</documents>

Joe Wicentowski
  • 5,159
  • 16
  • 26
line-o
  • 1,885
  • 3
  • 16
  • 33