[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

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


  XQuery and id()/idref(); Controlling the children of
	nodes in the result sequence
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
> 
> 




Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.