From: Oystein R. <oys...@ak...> - 2006-10-23 10:31:32
|
laurent exsteens wrote: > Hello, > > I tried to insert a node with an attribute specified by a variable, > like this: > > ###############[code] > > for $archives in doc("/db/rtbf/archives.xml")/archives > > let $year := 2004 > > let $annee := $archives/annee[@value = $year] > > return > if ($annee) > then ("no change") > else (update insert <annee value="$year"></annee> into $archives, > "added") > > ###############[/code] > > I also tried with > <annee value = {data($year)}></annee> > but no result anyway > > If year 2004 doesn't exist, it add me: > <annee value=$year></annee> > and no: > <annee value=2004></annee> From a non-expert: It seems $year in your <annee value="$year"> is interpreted as a literal string and not a variable since it occurs within quotes. But there _are_ languages where this syntax would have worked. I know of one - php. For all I know a small change is all that is needed to get your query to work. But I prefer to use a different syntax for specifying elements and attributes. I think this is called "computed element constructors" and "computed attribute constructors": else (update insert element annee { attribute value { $year } } into $archives, "added") Hope this helps. - Øystein - > > > And if year 2004 already exist, xquery sandbox give me an error message: > FORG0001: cannot construct xs:double from 'xdt:untypedAtomic("$year")' > [at line 5, column 38] In call to function: > sandbox:exec-query(xs:string) [126:10] > > > What's the good way to make that? > > Thanks, > > Laurent. > >------------------------------------------------------------------------ > >------------------------------------------------------------------------- >Using Tomcat but need to do more? Need to support web services, security? >Get stuff done quickly with pre-integrated technology to make your job easier >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > >------------------------------------------------------------------------ > >_______________________________________________ >Exist-open mailing list >Exi...@li... >https://lists.sourceforge.net/lists/listinfo/exist-open > > -- Øystein Reigem, The department of culture, language and information technology (Aksis), Allegt 27, N-5007 Bergen, Norway. Tel: +47 55 58 32 42. Fax: +47 55 58 94 70. E-mail: <oys...@ak...>. Home tel: +47 56 14 06 11. Mobile: +47 97 16 96 64. Home e-mail: <or...@br...>. Aksis home page: <www.aksis.uib.no>. |