[xquery-talk] XQuery and id()/idref(); Controlling the children of nodes in the result sequence

Maik Stührenberg maik.stuehrenberg at uni-bielefeld.de
Wed Apr 23 18:51:06 PDT 2008


Hi again,

for the following query (thanks for your hints):


declare namespace a="http://www.example.org/a";
declare namespace b="http://www.example.org/b";
declare namespace c="http://www.example.org/c";
<resultset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://www.example.org/a"
xmlns:a="http://www.example.org/a" xmlns:b="http://www.example.org/b" 
xmlns:c="http://www.example.org/c">
{
let $d := doc('demo_instance.xml')
for $s in $d/a:collection/a:entry/a:spans/a:span
return
   <result span="{$s/@xml:id}" start="{$s/@start}" end="{$s/@end}">
     {
		for $e in $d/a:collection/a:entry/a:data//*[@a:span = $s/@xml:id]
        return element { node-name($e) }{ $e/@* }
}
   </result>
}
</resultset>


I get this output:


<resultset xmlns:c="http://www.example.org/c" 
xmlns:b="http://www.example.org/b"
            xmlns:a="http://www.example.org/a"
            xmlns="http://www.example.org/a"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <result start="0" end="40" span="seg1">
       <b:text a:span="seg1"/>
       <b:para a:span="seg1"/>
    </result>
    <result start="0" end="20" span="seg2">
       <c:sentence id="w35" a:span="seg2"/>
    </result>
    <result start="0" end="4" span="to1">
       <c:word a:span="to1" id="w36"/>
    </result>
    <result start="5" end="8" span="to2">
       <c:word a:span="to2" id="w37"/>
    </result>
</resultset>


The only difference I'd like to achieve is the following resulting output:


<resultset xmlns:c="http://www.example.org/c" 
xmlns:b="http://www.example.org/b"
            xmlns:a="http://www.example.org/a"
            xmlns="http://www.example.org/a"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <result start="0" end="40" span="seg1">
       <b:text a:span="seg1">
         <b:para a:span="seg1"/>
       </b:text>
    </result>
    <result start="0" end="20" span="seg2">
       <c:sentence id="w35" a:span="seg2"/>
    </result>
    <result start="0" end="4" span="to1">
       <c:word a:span="to1" id="w36"/>
    </result>
    <result start="5" end="8" span="to2">
       <c:word a:span="to2" id="w37"/>
    </result>
</resultset>

The b:para element is realized as a child of the b:text element, i.e. 
the hierarchy of the elements remains intact (only if both elements have 
the same value of their a:span attribute).

I hope this helps a little bit.

Thanks for your effort.

Kind regards,

Maik Stührenberg

Florent Georges schrieb:
> Maik Stührenberg wrote:
> 
>   Hi
> 
>> @Florent: Thanks for the hint, but in that case, the hierarchical 
>> relationship between b:text and b:para would get lost.
> 
>   I don't understand what you want then.  Maybe you could try to show
> the result you expect with the example you gave us.
> 
>   Regards,
> 
> --drkm
> 
> 




More information about the talk mailing list