I've some XML like:

<speech>
   <speaker>Joe</speaker>
   <line>blah blah blah</line>
   ...
   <line>this that and the other thing</line>
</speech>

I can get each speaker and then get each speech of that speaker and a count of 
lines in each speech, but I haven't been able to get the total count of all 
lines by a speaker.

In the following, the function line-count returns the count of lines in each 
speech, but I need to accumulate these counts and return that, and I haven't 
been able to figure out a way to do that. Any suggestions would be appreciated.

define function line-count($s as xs:string) as xs:integer {
   let $count := 0
   for $_speech in doc("speeches.xml")//speech
   where some $_speaker in $_speech/speeker
   satisfies ($_speaker/text() = $s)
   return count($_speech/line)    
}

<speakers>
{
  let $speech := doc("speeches.xml")//speech
  for $speaker in distinct-values($speech/speaker)
  order by $speaker
  return
     <speaker>
        <name>{$speaker}</name>
        <count>{ line-count($speaker) }</count>
     </speaker>
}
</speakers>

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to