I have thousands of small XML files that I wanted to get some basic metrics on.  I used an intermediate document to do so.  But in the process I found something that looks like it may be a bug.  Here are the details using a simplified case.
 
a) each xml file looks like these two:
<archive ssid="258070" name="eship-20010919" size="20" >
<annotation>
anot1
</annotation>
</archive>
 
 
b) This query works ok.  the query is followed by the output

let $intdoc :=
<alist>
{
for $doc in
 collection("file:///d:/Users/asrdcnt/misc/xquery/Collections/bug?select=f*.xml;on-error=fail ")
let $ssid := $doc/archive/@ssid
let $size := $doc/archive/@size
return
 <ssid id="{$ssid}" size="{$size}" />
}
</alist>

return
<total>
{$intdoc}
</total>

<?xml version="1.0" encoding="UTF-8"?>
<total>
   <alist>
      <ssid id="258070" size="20"/>
      <ssid id="258070" size="10"/>
   </alist>
</total>
{$intdoc}
</total>

 c) This query fails (output follows):

let $intdoc :=
<alist>
{
for $doc in
 collection("file:///d:/Users/asrdcnt/misc/xquery/Collections/bug?select=f*.xml;on-error=fail ")
let $ssid := $doc/archive/@ssid
let $size := $doc/archive/@size
return
 <ssid id="{$ssid}" size="{$size}" />
}
</alist>

return
<total>
{$intdoc/alist}
</total>

 <?xml version="1.0" encoding="UTF-8"?>
<total/>
d) This also fails with same empty root <total/>.

let $intdoc :=
<alist>
{
for $doc in
 collection("file:///d:/Users/asrdcnt/misc/xquery/Collections/bug?select=f*.xml;on-error=fail ")
let $ssid := $doc/archive/@ssid
let $size := $doc/archive/@size
return
 <ssid id="{$ssid}" size="{$size}" />
}
</alist>

return
<total>
{$intdoc/alist/ssid}
</total>

 e) Finally, and surprisingly, this works:

let $intdoc :=
<alist>
{
for $doc in
 collection("file:///d:/Users/asrdcnt/misc/xquery/Collections/bug?select=f*.xml;on-error=fail ")
let $ssid := $doc/archive/@ssid
let $size := $doc/archive/@size
return
 <ssid id="{$ssid}" size="{$size}" />
}
</alist>

return
<total>
{$intdoc//ssid}
</total>

 <?xml version="1.0" encoding="UTF-8"?>
<total>
   <ssid id="258070" size="20"/>
   <ssid id="258070" size="10"/>
</total>

f) And finally, summing all sizes works using the version that works

let $intdoc :=
<alist>
{
for $doc in
 collection("file:///d:/Users/asrdcnt/misc/xquery/Collections/bug?select=f*.xml;on-error=fail ")
let $ssid := $doc/archive/@ssid
let $size := $doc/archive/@size
return
 <ssid id="{$ssid}" size="{$size}" />
}
</alist>

return
<total>
{sum($intdoc//ssid/@size)}
</total>

 <?xml version="1.0" encoding="UTF-8"?>
<total>30</total>

Regards