|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] recurrencyMichalmas michalmas at gmail.comWed Mar 11 22:51:19 PST 2009
Hello David, Thank you very much for help. Later i realized i tried to do it in loop (no recursion), and then the variable state was lost. About your solution - i had to use Altova XML Spy for that, and i had some problems. The definition of function: declare function local:ref ($node as node()***, $s as xs:string*) { required putting star, as we pass many nodes. I also simplified the example too much, so i had to change some more things. But it perfectly works! Thanks, Michal On Wed, Mar 11, 2009 at 10:33 AM, David Carlisle <http://x-query.com/mailman/listinfo/talk> wrote: > > > 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. > ________________________________________________________________________ > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://x-query.com/pipermail/talk/attachments/20090311/9ccb55f6/attachment.htm
|
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
|






