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

Maik Stührenberg maik.stuehrenberg at uni-bielefeld.de
Thu Apr 24 14:57:03 PDT 2008


Michael Kay schrieb:
>>   So if I am right, you want to not include an element if one 
>> of its ancestors is included too?  If you want so, use the 
>> following instead of the for:
>>
>>     let $e := $d/a:collection/a:entry/a:data
>>                 // *[@a:span = $s/@xml:id]
>>       return
>>         $e[not(ancestor::* = $e)]
>>
> 
> That's not quite right, because the "=" tests for equality rather than
> identity.
> 
> You could do
> 
>       let $e := $d/a:collection/a:entry/a:data
>                  //*[@a:span = $s/@xml:id]
>       return
>          $e[not(ancestor::* intersect $e)]

Again, thanks for another suggestion, however, the version on top will 
still result in the 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">
              <c:word a:span="to1" id="w36"/>
              <c:word a:span="to2" id="w37"/>
              <!-- ... -->
       </c:sentence>
    </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>
> 
> or you could do a recursive function which stops searching any deeper when
> it finds a match:
> 
> declare function local:s($e as element(), $id as xs:string) as element()* {
>   $e/(if (@a:span eq $id)
>       then .
>       else */local:s(., $id))
> }
> 

Well, that is the point: the function should not stop searching any 
deeper when it finds a match -- it should stop searching any deeper when 
it finds a match and the child element of that match has a different 
value for the a:span attribute.
If I find an element which satisfies @a:span=@xml:id, then I have to 
look at least one level down further if its child satisfies the 
condition as well (if not, I'm fine, if it does the same has to be done 
recursively).

Best regards,

Maik Stührenberg




More information about the talk mailing list