Search code examples
xmlxquerydistinctmarklogic

Xquery How to extract the distinctive-terms from a set of xml nodes within a set of xml records?


Assume we have a set of xml records. Each record has a <paragraph> pla pla pla </paragraph>. How to extract the distinctive-terms from all paragraphs of all records? Not from each paragraph separately. The following code extracts distinctive-terms from each paragraph separately.

 for $record in /rec:Record 


 for $record in /rec:Record 
 let $distinct-terms:= cts:distinctive-terms(<info>{$record/rec:paragraph } </info> ,<options xmlns="cts:distinctive-terms"><max-terms>10</max-terms></options>)//cts:text/string()
 return 
 $distinct-terms

The output that I want is the distinctive-terms that represents all paragraphs within all records Not for each record individually.


Solution

  • Move the loop to inside the function call:

    cts:distinctive-terms(/rec:Record/<info>{./rec:paragraph}</info>)