Subject:Two level grouping Author:Julio de la Vega Date:19 Dec 2007 08:46 AM Originally Posted: 19 Dec 2007 08:47 AM
Hi *,
In my actual development I am grouping a first level using this code:
let $doc := doc(...)
return
<root>
{
for $REG_10 at $REG_10-startPos in $doc/root/REG_10
return
<REG_10>
{$REG_10}
{
for $REG_20 at $REG_20-pos in $doc/root/REG_20
where $REG_20 >> $REG_10 and (empty($REG_10/following-sibling::REG_10) or ($REG_20 << $REG_10/following-sibling::REG_10[1]))
return
$REG_20
}
</REG_10>
}
</root>
Now I need to do a secong grouping inside the first grouping. I need to group the records type 20 acording one of its children (the criteria for secod grouping is one of the children of 20)
BTW, please note that this is the Stylus Studio development network; we usually don't provide detailed help for language specific problems/questions; we provide help/guidance for our XML products. Future generic XQuery questions should be asked on a different kind of forum, like for example xquery-talk (http://x-query.com/mailman/listinfo/talk). Thanks.
...
let $all_REG_20s := for $REG_20 at $REG_20-pos in $doc/root/REG_20
where $REG_20 >> $REG_10 and (empty($REG_10/following-sibling::REG_10) or ($REG_20 << $REG_10/following-sibling::REG_10[1]))
return $REG_20
for $unique_REG_20 in distinct-values($all_REG_20s/TIPRE6)
return
element {concat("REG_20_", $unique_REG_20)} {
for $REG_20 in $all_REG_20s[TIPRE6 = $unique_REG_20]
return
<Datos>
{$REG_20}
</Datos>
}
}
...