Are you simply counting the wrong items?
It seems to me you wanted to count:
for $Beurt at $CountInner in $Debat//spreekbeurt
Daniel
-----Ursprüngliche Nachricht----- Von: BaseX-Talk basex-talk-bounces@mailman.uni-konstanz.de Im Auftrag von Ben Engbers Gesendet: Mittwoch, 9. März 2022 13:11 An: Basex Mail-lijst basex-talk@mailman.uni-konstanz.de Betreff: [basex-talk] How to return/use the value of a nested counter?
Hi,
I have a collection of 740 documents with the following structure:
<?xml version="1.0" encoding="utf-8"?> <officiele-publicatie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://technische-documentatie.oep.overheid.nl/schema/op-xsd-2012-1"> <metadata> <meta name="OVERHEIDop.externMetadataRecord" scheme="" content="https://zoek.officielebekendmakingen.nl/h-tk-20202021-102-2/metadata.xml" /> </metadata> <handelingen> <agendapunt> <spreekbeurt nieuw="nee"> <tekst status="goed"> <al-groep> <al>Allereerst hebben we het traditionele mondelinge vragenuur. </al> </al-groep> </tekst> </spreekbeurt> <spreekbeurt nieuw="ja"> <tekst status="goed"> <al-groep> <al>Voorzitter. Het was altijd al een eer om hier te staan.</al> </al-groep> <al-groep> <al>De vragen die ik ga stellen, gaan over stikstof.</al> </al-groep> <al-groep> <al>We zijn allemaal 100 kilometer per uur gaan rijden, maar er is nog geen gram ammoniak uit de veehouderij minder uitgestoten.</al> </al-groep> </tekst> </spreekbeurt> </spreekbeurt> <spreekbeurt nieuw="nee"> <tekst status="goed"> <al-groep> <al>U heeft helaas maar één vraag, meneer Ephraim, als Groep Van Haga.</al> </al-groep> <al-groep> <al>Ik wil de minister bedanken voor haar beantwoording.</al> </al-groep> </tekst> </spreekbeurt> </agendapunt> </handelingen> </officiele-publicatie>
I am trying to concatenate all the //<al> childs from <spreekbeurt> elements. Together with an ID that I construct from //meta/@content and a counter for <spreekbeurt>, I want this output:
20202021-102-2, 1, Allereerst ... 20202021-102-2, 2, Voorzitter... + De vragen ... + We zijn ... 20202021-102-2, 3, U heeft ... + Ik wil..
I expected that the following XQuery-statemnt would do it.
import module namespace functx = "http://www.functx.com";
for $Debat at $CountOuter in collection("Parliament") (: where $CountOuter <= 3:) let $debate-id := fn:analyze-string( $Debat/officiele-publicatie/metadata/meta/@content, "(\d{8}-\d*-\d*)")//fn:match/*:group[@nr="1"]/text() order by $debate-id for $Beurt at $CountInner in $Debat let $tekst := $Beurt//spreekbeurt//al/text() return($debate-id, $CountInner, $tekst)
Instead it returns: 20202021-102-2, 1, Allereerst ...+ Voorzitter... + De vragen ... + We zijn ... + U heeft ... + Ik wil..
How can I use the value of $CountInner?
Ben