Hi,
I have a collection of 740 XML-documents which I want to flatten. The files all have the same structure:
<handeling id="h_1"> <datum date="d_1"/> <spreekbeurt><spreker>spreker_1</spreker></spreekbeurt> <spreekbeurt><spreker>spreker_3</spreker></spreekbeurt> </handeling>
<handeling id="h_2"> <datum date="d_2"/> <spreekbeurt> <spreker>spreker_2</spreker></spreekbeurt><spreekbeurt> <spreker>spreker_1</spreker><spreekbeurt> <spreker>spreker_4</spreker></spreekbeurt> </handeling>
<handeling id="h_3"> <datum date="d_3"/> <spreekbeurt><spreker>spreker_2</spreker></spreekbeurt> <spreekbeurt><spreker>spreker_3</spreker></spreekbeurt> <spreekbeurt><spreker>spreker_2</spreker></spreekbeurt> <spreekbeurt><spreker>spreker_1</spreker></spreekbeurt> </handeling>
The following query gives this result: import module namespace functx = "http://www.functx.com";
let $Blogs := collection("Blog") let $Turns := collection("Blog")
for $Blog in collection("Blog"), $Turn in collection("Blog") where $Turn//datum/@date = $Blog//datum/@date order by $Blog//datum/@date count $Count let $Id := $Blog/handeling/@id let $Datum := $Blog//datum/@date
let $Speaker := $Turn//spreker/text()
return($Id, $Datum, $Speaker, $Count)
id="h_1" date="d_1" spreker_1 spreker_3 1 id="h_2" date="d_2" spreker_2 spreker_1 spreker_4 2 id="h_3" date="d_3" spreker_2 spreker_3 spreker_2 spreker_1 3
But what I eventually need is this (for clarity shown as a table):
1, id="h_1", date="d_1", 1, spreker_1 1, id="h_1", date="d_1", 2, spreker_3 2, id="h_2", date="d_2", 1, spreker_2 2, id="h_2", date="d_2", 2, spreker_1 2, id="h_2", date="d_2", 3, spreker_4 3, id="h_3", date="d_3", 1, spreker_2 3, id="h_3", date="d_3", 2, spreker_3 3, id="h_3", date="d_3", 3, spreker_2 3, id="h_3", date="d_3", 4, spreker_1
The first counter indicates the position in $Blog. and the second counter indicates the position in $Turn
I expected that the following query would return what I was looking for:
for $Blog in collection("Blog") order by $Blog//datum/@date let $Id := $Blog/handeling/@id let $Datum := $Blog//datum/@date count $countOuter return ( for $Turn in collection("Blog") where $Turn//datum/@date = $Blog//datum/@date let $Speaker := $Turn//spreker/text() return ($countOuter, $Id, $Datum, $Speaker))
Instead it returns 1, id="h_1", date="d_1", 1, spreker_1, spreker_3 2, id="h_2", date="d_2", 1, spreker_2, spreker_1, spreker_4 3, id="h_3", date="d_3", 1, spreker_2, spreker_3, spreker_2, spreker_1
I have 2 questions: 1: Is it possible to use separate counters for the inner and the outer loop? (How should I define the $countInner?) 2: How can I formulate the query for getting the correct output?
Ben Engbers