|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] recurrencyDavid Carlisle davidc at nag.co.ukWed Mar 11 09:33:16 PST 2009
Your posted input wan't well formed, if I make it so: <x> <testXML> <system> <node-name> <name>name1</name> <addInfo>t11</addInfo> <node-name> <name>name2</name> <addInfo>t22</addInfo> <node-name> <addInfo>t33</addInfo> <name>name3</name> </node-name> </node-name> </node-name> </system> </testXML> <somewhere-it-is-used> <what-the-name--of-var-is> <ref>name1</ref> <ref>name3 'sdsdsd'</ref> </what-the-name--of-var-is> <what-the-name--of-var-is> <ref>name1</ref> </what-the-name--of-var-is> </somewhere-it-is-used> </x> Then I think this returns what you want for the two references. declare function local:ref ($node as node(), $s as xs:string*) { if (empty($s)) then $node/addInfo else local:ref($node/descendant::node-name[name=$s[1]][1],$s[position()!=1]) }; for $v in /x/somewhere-it-is-used/what-the-name--of-var-is let $s := $v/ref/replace(.,' .*$','') return <var ref="{string-join($s,'/')}"> {local:ref(/,$s)} </var> as demonstrated by saxon if the above are saved in ref.xml and ref.xq respectively. $ saxon9q -s:ref.xml ref.xq <?xml version="1.0" encoding="UTF-8"?> <var ref="name1/name3"> <addInfo>t33</addInfo> </var> <var ref="name1"> <addInfo>t11</addInfo> </var> ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






