Wo soll ich meine Ergebnisse einschränken?

Ich habe eine XML-Datei mit einer Liste von mehreren tausend Suchbegriffen erstellt, die ich für ein Dokument ausführen muss. Ich habe dann diese Abfrage aus einem Beispielsatz von Suchbegriffen als Test erstellt, um ein Testdokument mit einigen Beispielen aus dem eigentlichen Dokument zu vergleichen:

let $keywords := ("best clients", "Very", "20")
for $keyword in $keywords
let $matches := doc('test')/set/entry[matches(comment, $keyword, 'i')]
return (<re>
{subsequence($matches/comment, 1, 1),
subsequence($matches/buyer, 1, 1)}</re>,
<re>
{subsequence($matches/comment, 2, 1),
subsequence($matches/buyer, 2, 1)}
</re>
)

Ich versuche zurückzukommen<re><comment /><buyer /></re><re><comment /><buyer /></re>... continuous, aber ich bekomme sie in einer groben Reihenfolge zurück.

Dies ist ein Teil des zu analysierenden Dokuments (ich habe die Käufernamen und einige Nester entfernt, um das Lesen zu vereinfachen):

<set>
<entry>
<comment>The client is only 20 years old.  Do not be surprised by his youth.</comment>
<buyer></buyer>
<id>1282</id>
<industry>International Trade; Fish and Game</industry>
</entry>
<entry>
<comment>!On leave in October.</comment>
<buyer></buyer>
<id>709</id>
<industry>Real Estate</industry>
</entry>
<entry>
<comment>Is often !out between 1 and 3 p.m.</comment>
<buyer></buyer>
<id>127</id>
<industry>Virus Software Marketting</industry>
</entry>
<entry>
<comment>Very personable.  One of our best clients.</comment>
<buyer></buyer>
<id>14851</id>
<industry>Administrative support.</industry>
</entry>
<entry>
<comment>!Very difficult to reach, but one of our top buyers.</comment>
<buyer></buyer>
<id>1458</id>
<industry>Construction</industry>
</entry>
<entry>
<comment></comment>
<buyer></buyer>
<id>276470</id>
<industry>Bulk Furniture Sales</industry>
</entry>
<entry>
<comment>A bit of an eccentric.  One of our best clients.</comment>
<buyer></buyer>
<id>1506</id>
<industry>Sports Analysis</industry>
</entry>
<entry>
<comment>Very gullible, so please !be sure she needs what you sell her.  She's one of our best clients.</comment>
<buyer></buyer>
<id>1523</id>
<industry>International Trade</industry>
</entry>
<entry>
<comment>He wants to buy everything, but !he has a tight budget.</comment>
<buyer></buyer>
<id>1524</id>
<industry>Public Relations</industry>
</entry>
</set>

Einige der Keywords, die ich verwende: "Bester Kunde *", "Handel", "20", ....

Ich war

Die Ausgabe ist eine lange Liste von Einträgen mit Kommentaren und Käuferkindern als Geschwister unter dem Eintragselement. Ich möchte die Anzahl der zurückgegebenen Einträge begrenzen2 per keyword. Ich versuche auch, Kommentare, die mit einem Ausrufezeichen (!) Beginnen, zur Priorität zu machen.

Stromausgang (immer näher):

<re><comment>Very personable.  One of our best clients.</comment>
  <buyer/>
</re><re><comment>A bit of an eccentric.  One of our best clients.</comment>
  <buyer/>
</re><re><comment>Very personable.  One of our best clients.</comment>
  <buyer/>
</re><re><comment>!Very difficult to reach, but one of our top buyers.</comment>
  <buyer/>
</re><re><comment>The client is only 20 years old.  Do not be surprised by his youth.</comment>
  <buyer/>
</re><re/>

Aktuelles Ausgabeformat:

<entry>
<comment>keyworda</comment>
<buyer></buyer>
</entry>
<entry>
<comment>keyworda</comment>
<buyer></buyer>
</entry>
<entry>
<comment>keywordb</comment>
<buyer></buyer>
</entry>
<entry>
<comment>!keywordb</comment> //Not prioritized.
<buyer></buyer>
</entry>
<entry>
<comment>keywordc</comment>
<buyer></buyer>
</entry>

Gewünschte Ausgabe:

<entry>
<comment>!keyworda</comment>
<buyer></buyer>
</entry>
<entry>
<comment>keyworda</comment>
<buyer></buyer>
</entry>
<entry>
<comment>!keywordb</comment>
<buyer></buyer>
</entry>
<entry>
<comment>!keywordb</comment>
<buyer></buyer>
</entry>

(Grundsätzlich Ausrufezeichen enthaltende Einträge priorisieren und die Ergebnisse auf 2 pro Keyword beschränken.)

Antworten auf die Frage(1)

Ihre Antwort auf die Frage