Use of For loop in transforming a node without changing the database
Thursday, 24 February 2011 · 7 messages · last reply 25 Feb 2011
CG
Christian Grün24 Feb 2011 21:27 #
Sony,
each FLWOR expression needs to be completed with a RETURN statement. Please insert the following snippet (haven't tried it live):
for $childentry in $c//childentry
return replace value of $childentry with
concat('New Child: ', $c//childentry/text())Hope this helps,
Christian
___________________________
Christian Grün
Uni KN, Box 188
78457 Konstanz, Germany
http://www.inf.uni-konstanz.de/~gruen
Quoted text · Sony Vijay · 178 lines
On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > Christian, > Thank you very much for helping me with the query. However, I am not quite > sure how the transform operation works if I have to use a for loop. Say, I > twist around yesterday's question a bit like so: > copy $c := > <entry> > <id>1</id> > <title>How to use a transform expression</title> > <updated>2011-02-23</updated> > <author> > <name>BaseX Team</name> > <uri>http://basex.org</uri> > </author> > <childentry> 1 </childentry> > <childentry> 2 </childentry> > <childentry> 3 </childentry> > <content type="html">Transform expression example created by BaseX > Team</content> > </entry> > modify ( > replace value of node $c//name with 'BaseX', > replace value of node $c//content with concat('Copy of: ', $c//content), > insert node <member>Joey</member> into $c//author > for $childentry in $c//childentry > replace value of $childentry with concat('New Child: ', > $c//childentry/text()) > ) > return $c > > The expected output is: > <entry> > <id>1</id> > <title>How to use a transform expression</title> > <updated>2011-02-23</updated> > <author> > <name>BaseX</name> > <uri>http://basex.org</uri> > <member>Joey</member> > </author> > <childentry> New Child: 1 </childentry> > <childentry> New Child: 2 </childentry> > <childentry> New Child: 3 </childentry> > <content type="html">Copy of: Transform expression example created by > BaseX Team</content> > </entry> > The following exception is thrown when I tried my sample transformation > query with the for loop: > [XPST0003] Expecting 'where', 'order' or 'return' expression. > Thanks, > Sony > PS: @Lukas: I did notice the update in the documentation. Thank you ! > > > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher > <lukaskircher1 at googlemail.com> wrote: >> >> Hi Sony, >> >> to help others with the same question, I allowed myself to >> add a modified version of your example to our >> documentation [1]. >> >> Regards, >> Lukas >> >> >> [1] http://docs.basex.org/wiki/Update#transform >> >> >> >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> wrote: >>> >>> Christian, >>> Thank you for the quick and helpful reply. >>> - Sony >>> >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün >>> <christian.gruen at gmail.com> wrote: >>>> >>>> Sony, >>>> >>>> the following query might do what you want: >>>> >>>> copy $c := >>>> <entry xmlns="http://www.w3.org/2005/Atom" >>>> xmlns:libx="http://libx.org/xml/libx2"> >>>> <id>1</id> >>>> <title>Link Amazon By ISBN</title> >>>> <updated>2010-09-29T18:37:48.592Z</updated> >>>> <author> >>>> <name>LibX Team</name> >>>> <uri>http://libx.org</uri> >>>> <email>libx.org at gmail.com</email> >>>> </author> >>>> <content type="html">Content created by LibX Libapp Builder</content> >>>> </entry> >>>> modify ( >>>> replace value of node $c//*:name with 'Sony', >>>> replace value of node $c//*:content with >>>> concat('Copy of: ', $c//*:content) >>>> ) >>>> return $c >>>> >>>> >>>> Best, >>>> Christian >>>> ___________________________ >>>> >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay <sony.vibh at gmail.com> >>>> wrote: >>>> > Hi, >>>> > I am using BaseX 6.5. I am trying to transform a given node using an >>>> > XQuery. >>>> > >>>> > Say, I have an node like so: >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>> > <id>1</id> >>>> > <title>Link Amazon By ISBN</title> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>> > <author> >>>> > <name>LibX Team</name> >>>> > <uri>http://libx.org</uri> >>>> > <email>libx.org at gmail.com</email> >>>> > </author> >>>> > <content type="html">Content created by LibX Libapp >>>> > Builder</content> >>>> > </entry> >>>> > I am trying to send this node to an xquery which is expected to do the >>>> > following actions: >>>> > >>>> > create a copy of this node (so that the actual node in the database >>>> > does not >>>> > change), >>>> > transform/modify the duplicate copy of the given node >>>> > return the modified duplicate copy of the given node >>>> > >>>> > I would expect the output to be like so: >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>> > <id>1</id> >>>> > <title>Link Amazon By ISBN</title> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>> > <author> >>>> > <name>Sony</name> >>>> > <uri>http://libx.org</uri> >>>> > <email>libx.org at gmail.com</email> >>>> > </author> >>>> > <content type="html">Copy of: Content created by LibX Libapp >>>> > Builder</content> >>>> > </entry> >>>> > I tried to perform the non-updating functions using transform and also >>>> > tried >>>> > to use a pending update list >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None of this >>>> > works >>>> > as expected. Could you refer me to a more detailed documentation for >>>> > performing such transform operations on nodes ? >>>> > Thanks, >>>> > Sony >>>> > >>>> > _______________________________________________ >>>> > BaseX-Talk mailing list >>>> > BaseX-Talk at mailman.uni-konstanz.de >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>> > >>>> > >>> >>> >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >> > >
SV
Sony Vijay24 Feb 2011 23:50 #
Christian,
Yes. I did realize that I must use a RETURN statement. I tried that with a slight change in the requirement. Say, my child entries look like so :
<childentry id="1" />I tried:
for $childentry in $c//childentry
return replace value of $childentry/@id with
concat('New Child: ', $c//childentry/text())Does replace work differently for attributes ?
Thanks,
Sony
On Thu, Feb 24, 2011 at 3:27 PM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 205 lines
> Sony, > > each FLWOR expression needs to be completed with a RETURN statement. > Please insert the following snippet (haven't tried it live): > > for $childentry in $c//childentry > return replace value of $childentry with > concat('New Child: ', $c//childentry/text()) > > Hope this helps, > Christian > ___________________________ > > Christian Grün > Uni KN, Box 188 > 78457 Konstanz, Germany > http://www.inf.uni-konstanz.de/~gruen > > > > On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > > Christian, > > Thank you very much for helping me with the query. However, I am not > quite > > sure how the transform operation works if I have to use a for loop. Say, > I > > twist around yesterday's question a bit like so: > > copy $c := > > <entry> > > <id>1</id> > > <title>How to use a transform expression</title> > > <updated>2011-02-23</updated> > > <author> > > <name>BaseX Team</name> > > <uri>http://basex.org</uri> > > </author> > > <childentry> 1 </childentry> > > <childentry> 2 </childentry> > > <childentry> 3 </childentry> > > <content type="html">Transform expression example created by BaseX > > Team</content> > > </entry> > > modify ( > > replace value of node $c//name with 'BaseX', > > replace value of node $c//content with concat('Copy of: ', $c//content), > > insert node <member>Joey</member> into $c//author > > for $childentry in $c//childentry > > replace value of $childentry with concat('New Child: ', > > $c//childentry/text()) > > ) > > return $c > > > > The expected output is: > > <entry> > > <id>1</id> > > <title>How to use a transform expression</title> > > <updated>2011-02-23</updated> > > <author> > > <name>BaseX</name> > > <uri>http://basex.org</uri> > > <member>Joey</member> > > </author> > > <childentry> New Child: 1 </childentry> > > <childentry> New Child: 2 </childentry> > > <childentry> New Child: 3 </childentry> > > <content type="html">Copy of: Transform expression example created by > > BaseX Team</content> > > </entry> > > The following exception is thrown when I tried my sample transformation > > query with the for loop: > > [XPST0003] Expecting 'where', 'order' or 'return' expression. > > Thanks, > > Sony > > PS: @Lukas: I did notice the update in the documentation. Thank you ! > > > > > > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher > > <lukaskircher1 at googlemail.com> wrote: > >> > >> Hi Sony, > >> > >> to help others with the same question, I allowed myself to > >> add a modified version of your example to our > >> documentation [1]. > >> > >> Regards, > >> Lukas > >> > >> > >> [1] http://docs.basex.org/wiki/Update#transform > >> > >> > >> > >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> > wrote: > >>> > >>> Christian, > >>> Thank you for the quick and helpful reply. > >>> - Sony > >>> > >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün > >>> <christian.gruen at gmail.com> wrote: > >>>> > >>>> Sony, > >>>> > >>>> the following query might do what you want: > >>>> > >>>> copy $c := > >>>> <entry xmlns="http://www.w3.org/2005/Atom" > >>>> xmlns:libx="http://libx.org/xml/libx2"> > >>>> <id>1</id> > >>>> <title>Link Amazon By ISBN</title> > >>>> <updated>2010-09-29T18:37:48.592Z</updated> > >>>> <author> > >>>> <name>LibX Team</name> > >>>> <uri>http://libx.org</uri> > >>>> <email>libx.org at gmail.com</email> > >>>> </author> > >>>> <content type="html">Content created by LibX Libapp Builder</content> > >>>> </entry> > >>>> modify ( > >>>> replace value of node $c//*:name with 'Sony', > >>>> replace value of node $c//*:content with > >>>> concat('Copy of: ', $c//*:content) > >>>> ) > >>>> return $c > >>>> > >>>> > >>>> Best, > >>>> Christian > >>>> ___________________________ > >>>> > >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay <sony.vibh at gmail.com> > >>>> wrote: > >>>> > Hi, > >>>> > I am using BaseX 6.5. I am trying to transform a given node using an > >>>> > XQuery. > >>>> > > >>>> > Say, I have an node like so: > >>>> > <entry xmlns="http://www.w3.org/2005/Atom" > >>>> > xmlns:libx="http://libx.org/xml/libx2"> > >>>> > <id>1</id> > >>>> > <title>Link Amazon By ISBN</title> > >>>> > <updated>2010-09-29T18:37:48.592Z</updated> > >>>> > <author> > >>>> > <name>LibX Team</name> > >>>> > <uri>http://libx.org</uri> > >>>> > <email>libx.org at gmail.com</email> > >>>> > </author> > >>>> > <content type="html">Content created by LibX Libapp > >>>> > Builder</content> > >>>> > </entry> > >>>> > I am trying to send this node to an xquery which is expected to do > the > >>>> > following actions: > >>>> > > >>>> > create a copy of this node (so that the actual node in the database > >>>> > does not > >>>> > change), > >>>> > transform/modify the duplicate copy of the given node > >>>> > return the modified duplicate copy of the given node > >>>> > > >>>> > I would expect the output to be like so: > >>>> > <entry xmlns="http://www.w3.org/2005/Atom" > >>>> > xmlns:libx="http://libx.org/xml/libx2"> > >>>> > <id>1</id> > >>>> > <title>Link Amazon By ISBN</title> > >>>> > <updated>2010-09-29T18:37:48.592Z</updated> > >>>> > <author> > >>>> > <name>Sony</name> > >>>> > <uri>http://libx.org</uri> > >>>> > <email>libx.org at gmail.com</email> > >>>> > </author> > >>>> > <content type="html">Copy of: Content created by LibX Libapp > >>>> > Builder</content> > >>>> > </entry> > >>>> > I tried to perform the non-updating functions using transform and > also > >>>> > tried > >>>> > to use a pending update list > >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None of > this > >>>> > works > >>>> > as expected. Could you refer me to a more detailed documentation for > >>>> > performing such transform operations on nodes ? > >>>> > Thanks, > >>>> > Sony > >>>> > > >>>> > _______________________________________________ > >>>> > BaseX-Talk mailing list > >>>> > BaseX-Talk at mailman.uni-konstanz.de > >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >>>> > > >>>> > > >>> > >>> > >>> _______________________________________________ > >>> BaseX-Talk mailing list > >>> BaseX-Talk at mailman.uni-konstanz.de > >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >>> > >> > > > > >
SV
Sony Vijay25 Feb 2011 00:01 #
Please ignore the typo. My sample xquery looks something like this:
for $childentry in $c//childentry
return replace value of $childentry/@id with
concat('New Child: ', data($c//childentry/@id))To modify the child entries like so:
<childentry id="1"> ----- > <childentry id="New Child: 1">Quoted text · Sony Vijay · 236 lines
On Thu, Feb 24, 2011 at 4:50 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > Christian, > > Yes. I did realize that I must use a RETURN statement. I tried that with a > slight change in the requirement. Say, my child entries look like so : > > > <childentry id="1" /> > > I tried: > > for $childentry in $c//childentry > return replace value of $childentry/@id with > > concat('New Child: ', $c//childentry/text()) > > Does replace work differently for attributes ? > > Thanks, > Sony > > > > On Thu, Feb 24, 2011 at 3:27 PM, Christian Grün <christian.gruen at gmail.com > > wrote: > >> Sony, >> >> each FLWOR expression needs to be completed with a RETURN statement. >> Please insert the following snippet (haven't tried it live): >> >> for $childentry in $c//childentry >> return replace value of $childentry with >> concat('New Child: ', $c//childentry/text()) >> >> Hope this helps, >> Christian >> ___________________________ >> >> Christian Grün >> Uni KN, Box 188 >> 78457 Konstanz, Germany >> http://www.inf.uni-konstanz.de/~gruen >> >> >> >> On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >> > Christian, >> > Thank you very much for helping me with the query. However, I am not >> quite >> > sure how the transform operation works if I have to use a for loop. Say, >> I >> > twist around yesterday's question a bit like so: >> > copy $c := >> > <entry> >> > <id>1</id> >> > <title>How to use a transform expression</title> >> > <updated>2011-02-23</updated> >> > <author> >> > <name>BaseX Team</name> >> > <uri>http://basex.org</uri> >> > </author> >> > <childentry> 1 </childentry> >> > <childentry> 2 </childentry> >> > <childentry> 3 </childentry> >> > <content type="html">Transform expression example created by BaseX >> > Team</content> >> > </entry> >> > modify ( >> > replace value of node $c//name with 'BaseX', >> > replace value of node $c//content with concat('Copy of: ', $c//content), >> > insert node <member>Joey</member> into $c//author >> > for $childentry in $c//childentry >> > replace value of $childentry with concat('New Child: ', >> > $c//childentry/text()) >> > ) >> > return $c >> > >> > The expected output is: >> > <entry> >> > <id>1</id> >> > <title>How to use a transform expression</title> >> > <updated>2011-02-23</updated> >> > <author> >> > <name>BaseX</name> >> > <uri>http://basex.org</uri> >> > <member>Joey</member> >> > </author> >> > <childentry> New Child: 1 </childentry> >> > <childentry> New Child: 2 </childentry> >> > <childentry> New Child: 3 </childentry> >> > <content type="html">Copy of: Transform expression example created by >> > BaseX Team</content> >> > </entry> >> > The following exception is thrown when I tried my sample transformation >> > query with the for loop: >> > [XPST0003] Expecting 'where', 'order' or 'return' expression. >> > Thanks, >> > Sony >> > PS: @Lukas: I did notice the update in the documentation. Thank you ! >> > >> > >> > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher >> > <lukaskircher1 at googlemail.com> wrote: >> >> >> >> Hi Sony, >> >> >> >> to help others with the same question, I allowed myself to >> >> add a modified version of your example to our >> >> documentation [1]. >> >> >> >> Regards, >> >> Lukas >> >> >> >> >> >> [1] http://docs.basex.org/wiki/Update#transform >> >> >> >> >> >> >> >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> >> wrote: >> >>> >> >>> Christian, >> >>> Thank you for the quick and helpful reply. >> >>> - Sony >> >>> >> >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün >> >>> <christian.gruen at gmail.com> wrote: >> >>>> >> >>>> Sony, >> >>>> >> >>>> the following query might do what you want: >> >>>> >> >>>> copy $c := >> >>>> <entry xmlns="http://www.w3.org/2005/Atom" >> >>>> xmlns:libx="http://libx.org/xml/libx2"> >> >>>> <id>1</id> >> >>>> <title>Link Amazon By ISBN</title> >> >>>> <updated>2010-09-29T18:37:48.592Z</updated> >> >>>> <author> >> >>>> <name>LibX Team</name> >> >>>> <uri>http://libx.org</uri> >> >>>> <email>libx.org at gmail.com</email> >> >>>> </author> >> >>>> <content type="html">Content created by LibX Libapp >> Builder</content> >> >>>> </entry> >> >>>> modify ( >> >>>> replace value of node $c//*:name with 'Sony', >> >>>> replace value of node $c//*:content with >> >>>> concat('Copy of: ', $c//*:content) >> >>>> ) >> >>>> return $c >> >>>> >> >>>> >> >>>> Best, >> >>>> Christian >> >>>> ___________________________ >> >>>> >> >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay <sony.vibh at gmail.com> >> >>>> wrote: >> >>>> > Hi, >> >>>> > I am using BaseX 6.5. I am trying to transform a given node using >> an >> >>>> > XQuery. >> >>>> > >> >>>> > Say, I have an node like so: >> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >> >>>> > <id>1</id> >> >>>> > <title>Link Amazon By ISBN</title> >> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >> >>>> > <author> >> >>>> > <name>LibX Team</name> >> >>>> > <uri>http://libx.org</uri> >> >>>> > <email>libx.org at gmail.com</email> >> >>>> > </author> >> >>>> > <content type="html">Content created by LibX Libapp >> >>>> > Builder</content> >> >>>> > </entry> >> >>>> > I am trying to send this node to an xquery which is expected to do >> the >> >>>> > following actions: >> >>>> > >> >>>> > create a copy of this node (so that the actual node in the database >> >>>> > does not >> >>>> > change), >> >>>> > transform/modify the duplicate copy of the given node >> >>>> > return the modified duplicate copy of the given node >> >>>> > >> >>>> > I would expect the output to be like so: >> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >> >>>> > <id>1</id> >> >>>> > <title>Link Amazon By ISBN</title> >> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >> >>>> > <author> >> >>>> > <name>Sony</name> >> >>>> > <uri>http://libx.org</uri> >> >>>> > <email>libx.org at gmail.com</email> >> >>>> > </author> >> >>>> > <content type="html">Copy of: Content created by LibX Libapp >> >>>> > Builder</content> >> >>>> > </entry> >> >>>> > I tried to perform the non-updating functions using transform and >> also >> >>>> > tried >> >>>> > to use a pending update list >> >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None of >> this >> >>>> > works >> >>>> > as expected. Could you refer me to a more detailed documentation >> for >> >>>> > performing such transform operations on nodes ? >> >>>> > Thanks, >> >>>> > Sony >> >>>> > >> >>>> > _______________________________________________ >> >>>> > BaseX-Talk mailing list >> >>>> > BaseX-Talk at mailman.uni-konstanz.de >> >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >>>> > >> >>>> > >> >>> >> >>> >> >>> _______________________________________________ >> >>> BaseX-Talk mailing list >> >>> BaseX-Talk at mailman.uni-konstanz.de >> >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >>> >> >> >> > >> > >> > >
SV
Sony Vijay25 Feb 2011 00:03 #
... Replacing the values of attribute nodes doesn't seem to work as expected when I use modify. Please see my previous post with correction in the typo.
Quoted text · Sony Vijay · 253 lines
On Thu, Feb 24, 2011 at 5:00 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > Please ignore the typo. My sample xquery looks something like this: > > for $childentry in $c//childentry > return replace value of $childentry/@id with > concat('New Child: ', data($c//childentry/@id)) > > To modify the child entries like so: > > <childentry id="1"> ----- > <childentry id="New Child: 1"> > > > > On Thu, Feb 24, 2011 at 4:50 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > >> Christian, >> >> Yes. I did realize that I must use a RETURN statement. I tried that with a >> slight change in the requirement. Say, my child entries look like so : >> >> >> <childentry id="1" /> >> >> I tried: >> >> for $childentry in $c//childentry >> return replace value of $childentry/@id with >> >> concat('New Child: ', $c//childentry/text()) >> >> Does replace work differently for attributes ? >> >> Thanks, >> Sony >> >> >> >> On Thu, Feb 24, 2011 at 3:27 PM, Christian Grün < >> christian.gruen at gmail.com> wrote: >> >>> Sony, >>> >>> each FLWOR expression needs to be completed with a RETURN statement. >>> Please insert the following snippet (haven't tried it live): >>> >>> for $childentry in $c//childentry >>> return replace value of $childentry with >>> concat('New Child: ', $c//childentry/text()) >>> >>> Hope this helps, >>> Christian >>> ___________________________ >>> >>> Christian Grün >>> Uni KN, Box 188 >>> 78457 Konstanz, Germany >>> http://www.inf.uni-konstanz.de/~gruen >>> >>> >>> >>> On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >>> > Christian, >>> > Thank you very much for helping me with the query. However, I am not >>> quite >>> > sure how the transform operation works if I have to use a for loop. >>> Say, I >>> > twist around yesterday's question a bit like so: >>> > copy $c := >>> > <entry> >>> > <id>1</id> >>> > <title>How to use a transform expression</title> >>> > <updated>2011-02-23</updated> >>> > <author> >>> > <name>BaseX Team</name> >>> > <uri>http://basex.org</uri> >>> > </author> >>> > <childentry> 1 </childentry> >>> > <childentry> 2 </childentry> >>> > <childentry> 3 </childentry> >>> > <content type="html">Transform expression example created by BaseX >>> > Team</content> >>> > </entry> >>> > modify ( >>> > replace value of node $c//name with 'BaseX', >>> > replace value of node $c//content with concat('Copy of: ', >>> $c//content), >>> > insert node <member>Joey</member> into $c//author >>> > for $childentry in $c//childentry >>> > replace value of $childentry with concat('New Child: ', >>> > $c//childentry/text()) >>> > ) >>> > return $c >>> > >>> > The expected output is: >>> > <entry> >>> > <id>1</id> >>> > <title>How to use a transform expression</title> >>> > <updated>2011-02-23</updated> >>> > <author> >>> > <name>BaseX</name> >>> > <uri>http://basex.org</uri> >>> > <member>Joey</member> >>> > </author> >>> > <childentry> New Child: 1 </childentry> >>> > <childentry> New Child: 2 </childentry> >>> > <childentry> New Child: 3 </childentry> >>> > <content type="html">Copy of: Transform expression example created by >>> > BaseX Team</content> >>> > </entry> >>> > The following exception is thrown when I tried my sample transformation >>> > query with the for loop: >>> > [XPST0003] Expecting 'where', 'order' or 'return' expression. >>> > Thanks, >>> > Sony >>> > PS: @Lukas: I did notice the update in the documentation. Thank you ! >>> > >>> > >>> > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher >>> > <lukaskircher1 at googlemail.com> wrote: >>> >> >>> >> Hi Sony, >>> >> >>> >> to help others with the same question, I allowed myself to >>> >> add a modified version of your example to our >>> >> documentation [1]. >>> >> >>> >> Regards, >>> >> Lukas >>> >> >>> >> >>> >> [1] http://docs.basex.org/wiki/Update#transform >>> >> >>> >> >>> >> >>> >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> >>> wrote: >>> >>> >>> >>> Christian, >>> >>> Thank you for the quick and helpful reply. >>> >>> - Sony >>> >>> >>> >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün >>> >>> <christian.gruen at gmail.com> wrote: >>> >>>> >>> >>>> Sony, >>> >>>> >>> >>>> the following query might do what you want: >>> >>>> >>> >>>> copy $c := >>> >>>> <entry xmlns="http://www.w3.org/2005/Atom" >>> >>>> xmlns:libx="http://libx.org/xml/libx2"> >>> >>>> <id>1</id> >>> >>>> <title>Link Amazon By ISBN</title> >>> >>>> <updated>2010-09-29T18:37:48.592Z</updated> >>> >>>> <author> >>> >>>> <name>LibX Team</name> >>> >>>> <uri>http://libx.org</uri> >>> >>>> <email>libx.org at gmail.com</email> >>> >>>> </author> >>> >>>> <content type="html">Content created by LibX Libapp >>> Builder</content> >>> >>>> </entry> >>> >>>> modify ( >>> >>>> replace value of node $c//*:name with 'Sony', >>> >>>> replace value of node $c//*:content with >>> >>>> concat('Copy of: ', $c//*:content) >>> >>>> ) >>> >>>> return $c >>> >>>> >>> >>>> >>> >>>> Best, >>> >>>> Christian >>> >>>> ___________________________ >>> >>>> >>> >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay <sony.vibh at gmail.com> >>> >>>> wrote: >>> >>>> > Hi, >>> >>>> > I am using BaseX 6.5. I am trying to transform a given node using >>> an >>> >>>> > XQuery. >>> >>>> > >>> >>>> > Say, I have an node like so: >>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>> >>>> > <id>1</id> >>> >>>> > <title>Link Amazon By ISBN</title> >>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>> >>>> > <author> >>> >>>> > <name>LibX Team</name> >>> >>>> > <uri>http://libx.org</uri> >>> >>>> > <email>libx.org at gmail.com</email> >>> >>>> > </author> >>> >>>> > <content type="html">Content created by LibX Libapp >>> >>>> > Builder</content> >>> >>>> > </entry> >>> >>>> > I am trying to send this node to an xquery which is expected to do >>> the >>> >>>> > following actions: >>> >>>> > >>> >>>> > create a copy of this node (so that the actual node in the >>> database >>> >>>> > does not >>> >>>> > change), >>> >>>> > transform/modify the duplicate copy of the given node >>> >>>> > return the modified duplicate copy of the given node >>> >>>> > >>> >>>> > I would expect the output to be like so: >>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>> >>>> > <id>1</id> >>> >>>> > <title>Link Amazon By ISBN</title> >>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>> >>>> > <author> >>> >>>> > <name>Sony</name> >>> >>>> > <uri>http://libx.org</uri> >>> >>>> > <email>libx.org at gmail.com</email> >>> >>>> > </author> >>> >>>> > <content type="html">Copy of: Content created by LibX Libapp >>> >>>> > Builder</content> >>> >>>> > </entry> >>> >>>> > I tried to perform the non-updating functions using transform and >>> also >>> >>>> > tried >>> >>>> > to use a pending update list >>> >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None of >>> this >>> >>>> > works >>> >>>> > as expected. Could you refer me to a more detailed documentation >>> for >>> >>>> > performing such transform operations on nodes ? >>> >>>> > Thanks, >>> >>>> > Sony >>> >>>> > >>> >>>> > _______________________________________________ >>> >>>> > BaseX-Talk mailing list >>> >>>> > BaseX-Talk at mailman.uni-konstanz.de >>> >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >>>> > >>> >>>> > >>> >>> >>> >>> >>> >>> _______________________________________________ >>> >>> BaseX-Talk mailing list >>> >>> BaseX-Talk at mailman.uni-konstanz.de >>> >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >>> >>> >> >>> > >>> > >>> >> >> >
SV
Sony Vijay25 Feb 2011 00:10 #
.. I* see the syntax error : *
*[XPST0003] Expecting ")", found "v".*
when I try :
for $childentry in $c//childentry
return replace value of $childentry/@id with
concat('New Child: ', data($c//childentry/@id))To modify the child entries like so:
<childentry id="1"> ----- > <childentry id="New Child: 1">Quoted text · Sony Vijay · 264 lines
On Thu, Feb 24, 2011 at 5:03 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > ... Replacing the values of attribute nodes doesn't seem to work as > expected when I use modify. Please see my previous post with correction in > the typo. > > > On Thu, Feb 24, 2011 at 5:00 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > >> Please ignore the typo. My sample xquery looks something like this: >> >> for $childentry in $c//childentry >> return replace value of $childentry/@id with >> concat('New Child: ', data($c//childentry/@id)) >> >> To modify the child entries like so: >> >> <childentry id="1"> ----- > <childentry id="New Child: 1"> >> >> >> >> On Thu, Feb 24, 2011 at 4:50 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >> >>> Christian, >>> >>> Yes. I did realize that I must use a RETURN statement. I tried that with >>> a slight change in the requirement. Say, my child entries look like so : >>> >>> >>> <childentry id="1" /> >>> >>> I tried: >>> >>> for $childentry in $c//childentry >>> return replace value of $childentry/@id with >>> >>> concat('New Child: ', $c//childentry/text()) >>> >>> Does replace work differently for attributes ? >>> >>> Thanks, >>> Sony >>> >>> >>> >>> On Thu, Feb 24, 2011 at 3:27 PM, Christian Grün < >>> christian.gruen at gmail.com> wrote: >>> >>>> Sony, >>>> >>>> each FLWOR expression needs to be completed with a RETURN statement. >>>> Please insert the following snippet (haven't tried it live): >>>> >>>> for $childentry in $c//childentry >>>> return replace value of $childentry with >>>> concat('New Child: ', $c//childentry/text()) >>>> >>>> Hope this helps, >>>> Christian >>>> ___________________________ >>>> >>>> Christian Grün >>>> Uni KN, Box 188 >>>> 78457 Konstanz, Germany >>>> http://www.inf.uni-konstanz.de/~gruen >>>> >>>> >>>> >>>> On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> >>>> wrote: >>>> > Christian, >>>> > Thank you very much for helping me with the query. However, I am not >>>> quite >>>> > sure how the transform operation works if I have to use a for loop. >>>> Say, I >>>> > twist around yesterday's question a bit like so: >>>> > copy $c := >>>> > <entry> >>>> > <id>1</id> >>>> > <title>How to use a transform expression</title> >>>> > <updated>2011-02-23</updated> >>>> > <author> >>>> > <name>BaseX Team</name> >>>> > <uri>http://basex.org</uri> >>>> > </author> >>>> > <childentry> 1 </childentry> >>>> > <childentry> 2 </childentry> >>>> > <childentry> 3 </childentry> >>>> > <content type="html">Transform expression example created by BaseX >>>> > Team</content> >>>> > </entry> >>>> > modify ( >>>> > replace value of node $c//name with 'BaseX', >>>> > replace value of node $c//content with concat('Copy of: ', >>>> $c//content), >>>> > insert node <member>Joey</member> into $c//author >>>> > for $childentry in $c//childentry >>>> > replace value of $childentry with concat('New Child: ', >>>> > $c//childentry/text()) >>>> > ) >>>> > return $c >>>> > >>>> > The expected output is: >>>> > <entry> >>>> > <id>1</id> >>>> > <title>How to use a transform expression</title> >>>> > <updated>2011-02-23</updated> >>>> > <author> >>>> > <name>BaseX</name> >>>> > <uri>http://basex.org</uri> >>>> > <member>Joey</member> >>>> > </author> >>>> > <childentry> New Child: 1 </childentry> >>>> > <childentry> New Child: 2 </childentry> >>>> > <childentry> New Child: 3 </childentry> >>>> > <content type="html">Copy of: Transform expression example created >>>> by >>>> > BaseX Team</content> >>>> > </entry> >>>> > The following exception is thrown when I tried my sample >>>> transformation >>>> > query with the for loop: >>>> > [XPST0003] Expecting 'where', 'order' or 'return' expression. >>>> > Thanks, >>>> > Sony >>>> > PS: @Lukas: I did notice the update in the documentation. Thank you ! >>>> > >>>> > >>>> > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher >>>> > <lukaskircher1 at googlemail.com> wrote: >>>> >> >>>> >> Hi Sony, >>>> >> >>>> >> to help others with the same question, I allowed myself to >>>> >> add a modified version of your example to our >>>> >> documentation [1]. >>>> >> >>>> >> Regards, >>>> >> Lukas >>>> >> >>>> >> >>>> >> [1] http://docs.basex.org/wiki/Update#transform >>>> >> >>>> >> >>>> >> >>>> >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> >>>> wrote: >>>> >>> >>>> >>> Christian, >>>> >>> Thank you for the quick and helpful reply. >>>> >>> - Sony >>>> >>> >>>> >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün >>>> >>> <christian.gruen at gmail.com> wrote: >>>> >>>> >>>> >>>> Sony, >>>> >>>> >>>> >>>> the following query might do what you want: >>>> >>>> >>>> >>>> copy $c := >>>> >>>> <entry xmlns="http://www.w3.org/2005/Atom" >>>> >>>> xmlns:libx="http://libx.org/xml/libx2"> >>>> >>>> <id>1</id> >>>> >>>> <title>Link Amazon By ISBN</title> >>>> >>>> <updated>2010-09-29T18:37:48.592Z</updated> >>>> >>>> <author> >>>> >>>> <name>LibX Team</name> >>>> >>>> <uri>http://libx.org</uri> >>>> >>>> <email>libx.org at gmail.com</email> >>>> >>>> </author> >>>> >>>> <content type="html">Content created by LibX Libapp >>>> Builder</content> >>>> >>>> </entry> >>>> >>>> modify ( >>>> >>>> replace value of node $c//*:name with 'Sony', >>>> >>>> replace value of node $c//*:content with >>>> >>>> concat('Copy of: ', $c//*:content) >>>> >>>> ) >>>> >>>> return $c >>>> >>>> >>>> >>>> >>>> >>>> Best, >>>> >>>> Christian >>>> >>>> ___________________________ >>>> >>>> >>>> >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay <sony.vibh at gmail.com> >>>> >>>> wrote: >>>> >>>> > Hi, >>>> >>>> > I am using BaseX 6.5. I am trying to transform a given node using >>>> an >>>> >>>> > XQuery. >>>> >>>> > >>>> >>>> > Say, I have an node like so: >>>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>> >>>> > <id>1</id> >>>> >>>> > <title>Link Amazon By ISBN</title> >>>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>> >>>> > <author> >>>> >>>> > <name>LibX Team</name> >>>> >>>> > <uri>http://libx.org</uri> >>>> >>>> > <email>libx.org at gmail.com</email> >>>> >>>> > </author> >>>> >>>> > <content type="html">Content created by LibX Libapp >>>> >>>> > Builder</content> >>>> >>>> > </entry> >>>> >>>> > I am trying to send this node to an xquery which is expected to >>>> do the >>>> >>>> > following actions: >>>> >>>> > >>>> >>>> > create a copy of this node (so that the actual node in the >>>> database >>>> >>>> > does not >>>> >>>> > change), >>>> >>>> > transform/modify the duplicate copy of the given node >>>> >>>> > return the modified duplicate copy of the given node >>>> >>>> > >>>> >>>> > I would expect the output to be like so: >>>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>> >>>> > <id>1</id> >>>> >>>> > <title>Link Amazon By ISBN</title> >>>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>> >>>> > <author> >>>> >>>> > <name>Sony</name> >>>> >>>> > <uri>http://libx.org</uri> >>>> >>>> > <email>libx.org at gmail.com</email> >>>> >>>> > </author> >>>> >>>> > <content type="html">Copy of: Content created by LibX Libapp >>>> >>>> > Builder</content> >>>> >>>> > </entry> >>>> >>>> > I tried to perform the non-updating functions using transform and >>>> also >>>> >>>> > tried >>>> >>>> > to use a pending update list >>>> >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None >>>> of this >>>> >>>> > works >>>> >>>> > as expected. Could you refer me to a more detailed documentation >>>> for >>>> >>>> > performing such transform operations on nodes ? >>>> >>>> > Thanks, >>>> >>>> > Sony >>>> >>>> > >>>> >>>> > _______________________________________________ >>>> >>>> > BaseX-Talk mailing list >>>> >>>> > BaseX-Talk at mailman.uni-konstanz.de >>>> >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>> >>>> > >>>> >>>> > >>>> >>> >>>> >>> >>>> >>> _______________________________________________ >>>> >>> BaseX-Talk mailing list >>>> >>> BaseX-Talk at mailman.uni-konstanz.de >>>> >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>> >>> >>>> >> >>>> > >>>> > >>>> >>> >>> >> >
LK
Lukas Kircher25 Feb 2011 07:46 #
Hey Sony,
I found another small typo in your query - the keyword 'node' is missing in your replace statement. So if you execute the
query below you should be fine.
for $childentry in $c//childentry
return replace value of *node* $childentry/@id with
concat('New Child: ', data($c//childentry/@id))I'm sure the somewhat unrelated syntax error message didn't
help you to find this ... sorry for that.
Regards,
Lukas
Quoted text · Sony Vijay · 282 lines
On Thu, Feb 24, 2011 at 11:08 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > .. I* see the syntax error : * > *[XPST0003] Expecting ")", found "v".* > > when I try : > > for $childentry in $c//childentry > return replace value of $childentry/@id with > concat('New Child: ', data($c//childentry/@id)) > > To modify the child entries like so: > > <childentry id="1"> ----- > <childentry id="New Child: 1"> > > > On Thu, Feb 24, 2011 at 5:03 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > >> ... Replacing the values of attribute nodes doesn't seem to work as >> expected when I use modify. Please see my previous post with correction in >> the typo. >> >> >> On Thu, Feb 24, 2011 at 5:00 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >> >>> Please ignore the typo. My sample xquery looks something like this: >>> >>> for $childentry in $c//childentry >>> return replace value of $childentry/@id with >>> concat('New Child: ', data($c//childentry/@id)) >>> >>> To modify the child entries like so: >>> >>> <childentry id="1"> ----- > <childentry id="New Child: 1"> >>> >>> >>> >>> On Thu, Feb 24, 2011 at 4:50 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >>> >>>> Christian, >>>> >>>> Yes. I did realize that I must use a RETURN statement. I tried that with >>>> a slight change in the requirement. Say, my child entries look like so : >>>> >>>> >>>> <childentry id="1" /> >>>> >>>> I tried: >>>> >>>> for $childentry in $c//childentry >>>> return replace value of $childentry/@id with >>>> >>>> concat('New Child: ', $c//childentry/text()) >>>> >>>> Does replace work differently for attributes ? >>>> >>>> Thanks, >>>> Sony >>>> >>>> >>>> >>>> On Thu, Feb 24, 2011 at 3:27 PM, Christian Grün < >>>> christian.gruen at gmail.com> wrote: >>>> >>>>> Sony, >>>>> >>>>> each FLWOR expression needs to be completed with a RETURN statement. >>>>> Please insert the following snippet (haven't tried it live): >>>>> >>>>> for $childentry in $c//childentry >>>>> return replace value of $childentry with >>>>> concat('New Child: ', $c//childentry/text()) >>>>> >>>>> Hope this helps, >>>>> Christian >>>>> ___________________________ >>>>> >>>>> Christian Grün >>>>> Uni KN, Box 188 >>>>> 78457 Konstanz, Germany >>>>> http://www.inf.uni-konstanz.de/~gruen >>>>> >>>>> >>>>> >>>>> On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> >>>>> wrote: >>>>> > Christian, >>>>> > Thank you very much for helping me with the query. However, I am not >>>>> quite >>>>> > sure how the transform operation works if I have to use a for loop. >>>>> Say, I >>>>> > twist around yesterday's question a bit like so: >>>>> > copy $c := >>>>> > <entry> >>>>> > <id>1</id> >>>>> > <title>How to use a transform expression</title> >>>>> > <updated>2011-02-23</updated> >>>>> > <author> >>>>> > <name>BaseX Team</name> >>>>> > <uri>http://basex.org</uri> >>>>> > </author> >>>>> > <childentry> 1 </childentry> >>>>> > <childentry> 2 </childentry> >>>>> > <childentry> 3 </childentry> >>>>> > <content type="html">Transform expression example created by BaseX >>>>> > Team</content> >>>>> > </entry> >>>>> > modify ( >>>>> > replace value of node $c//name with 'BaseX', >>>>> > replace value of node $c//content with concat('Copy of: ', >>>>> $c//content), >>>>> > insert node <member>Joey</member> into $c//author >>>>> > for $childentry in $c//childentry >>>>> > replace value of $childentry with concat('New Child: ', >>>>> > $c//childentry/text()) >>>>> > ) >>>>> > return $c >>>>> > >>>>> > The expected output is: >>>>> > <entry> >>>>> > <id>1</id> >>>>> > <title>How to use a transform expression</title> >>>>> > <updated>2011-02-23</updated> >>>>> > <author> >>>>> > <name>BaseX</name> >>>>> > <uri>http://basex.org</uri> >>>>> > <member>Joey</member> >>>>> > </author> >>>>> > <childentry> New Child: 1 </childentry> >>>>> > <childentry> New Child: 2 </childentry> >>>>> > <childentry> New Child: 3 </childentry> >>>>> > <content type="html">Copy of: Transform expression example created >>>>> by >>>>> > BaseX Team</content> >>>>> > </entry> >>>>> > The following exception is thrown when I tried my sample >>>>> transformation >>>>> > query with the for loop: >>>>> > [XPST0003] Expecting 'where', 'order' or 'return' expression. >>>>> > Thanks, >>>>> > Sony >>>>> > PS: @Lukas: I did notice the update in the documentation. Thank you ! >>>>> > >>>>> > >>>>> > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher >>>>> > <lukaskircher1 at googlemail.com> wrote: >>>>> >> >>>>> >> Hi Sony, >>>>> >> >>>>> >> to help others with the same question, I allowed myself to >>>>> >> add a modified version of your example to our >>>>> >> documentation [1]. >>>>> >> >>>>> >> Regards, >>>>> >> Lukas >>>>> >> >>>>> >> >>>>> >> [1] http://docs.basex.org/wiki/Update#transform >>>>> >> >>>>> >> >>>>> >> >>>>> >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> >>>>> wrote: >>>>> >>> >>>>> >>> Christian, >>>>> >>> Thank you for the quick and helpful reply. >>>>> >>> - Sony >>>>> >>> >>>>> >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün >>>>> >>> <christian.gruen at gmail.com> wrote: >>>>> >>>> >>>>> >>>> Sony, >>>>> >>>> >>>>> >>>> the following query might do what you want: >>>>> >>>> >>>>> >>>> copy $c := >>>>> >>>> <entry xmlns="http://www.w3.org/2005/Atom" >>>>> >>>> xmlns:libx="http://libx.org/xml/libx2"> >>>>> >>>> <id>1</id> >>>>> >>>> <title>Link Amazon By ISBN</title> >>>>> >>>> <updated>2010-09-29T18:37:48.592Z</updated> >>>>> >>>> <author> >>>>> >>>> <name>LibX Team</name> >>>>> >>>> <uri>http://libx.org</uri> >>>>> >>>> <email>libx.org at gmail.com</email> >>>>> >>>> </author> >>>>> >>>> <content type="html">Content created by LibX Libapp >>>>> Builder</content> >>>>> >>>> </entry> >>>>> >>>> modify ( >>>>> >>>> replace value of node $c//*:name with 'Sony', >>>>> >>>> replace value of node $c//*:content with >>>>> >>>> concat('Copy of: ', $c//*:content) >>>>> >>>> ) >>>>> >>>> return $c >>>>> >>>> >>>>> >>>> >>>>> >>>> Best, >>>>> >>>> Christian >>>>> >>>> ___________________________ >>>>> >>>> >>>>> >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay <sony.vibh at gmail.com >>>>> > >>>>> >>>> wrote: >>>>> >>>> > Hi, >>>>> >>>> > I am using BaseX 6.5. I am trying to transform a given node >>>>> using an >>>>> >>>> > XQuery. >>>>> >>>> > >>>>> >>>> > Say, I have an node like so: >>>>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>>> >>>> > <id>1</id> >>>>> >>>> > <title>Link Amazon By ISBN</title> >>>>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>>> >>>> > <author> >>>>> >>>> > <name>LibX Team</name> >>>>> >>>> > <uri>http://libx.org</uri> >>>>> >>>> > <email>libx.org at gmail.com</email> >>>>> >>>> > </author> >>>>> >>>> > <content type="html">Content created by LibX Libapp >>>>> >>>> > Builder</content> >>>>> >>>> > </entry> >>>>> >>>> > I am trying to send this node to an xquery which is expected to >>>>> do the >>>>> >>>> > following actions: >>>>> >>>> > >>>>> >>>> > create a copy of this node (so that the actual node in the >>>>> database >>>>> >>>> > does not >>>>> >>>> > change), >>>>> >>>> > transform/modify the duplicate copy of the given node >>>>> >>>> > return the modified duplicate copy of the given node >>>>> >>>> > >>>>> >>>> > I would expect the output to be like so: >>>>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>>> >>>> > <id>1</id> >>>>> >>>> > <title>Link Amazon By ISBN</title> >>>>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>>> >>>> > <author> >>>>> >>>> > <name>Sony</name> >>>>> >>>> > <uri>http://libx.org</uri> >>>>> >>>> > <email>libx.org at gmail.com</email> >>>>> >>>> > </author> >>>>> >>>> > <content type="html">Copy of: Content created by LibX Libapp >>>>> >>>> > Builder</content> >>>>> >>>> > </entry> >>>>> >>>> > I tried to perform the non-updating functions using transform >>>>> and also >>>>> >>>> > tried >>>>> >>>> > to use a pending update list >>>>> >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None >>>>> of this >>>>> >>>> > works >>>>> >>>> > as expected. Could you refer me to a more detailed documentation >>>>> for >>>>> >>>> > performing such transform operations on nodes ? >>>>> >>>> > Thanks, >>>>> >>>> > Sony >>>>> >>>> > >>>>> >>>> > _______________________________________________ >>>>> >>>> > BaseX-Talk mailing list >>>>> >>>> > BaseX-Talk at mailman.uni-konstanz.de >>>>> >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>>> >>>> > >>>>> >>>> > >>>>> >>> >>>>> >>> >>>>> >>> _______________________________________________ >>>>> >>> BaseX-Talk mailing list >>>>> >>> BaseX-Talk at mailman.uni-konstanz.de >>>>> >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>>> >>> >>>>> >> >>>>> > >>>>> > >>>>> >>>> >>>> >>> >> >
CG
Christian Grün25 Feb 2011 08:54 #
Quoted text · Lukas Kircher · 2 lines
> I'm sure the somewhat unrelated syntax error message didn't > help you to find this ... sorry for that.
I agree with Lukas. I've revised the misleading error feedback; feel free to check out the latest build:
http://files.basex.org/releases/latest/
C.
Quoted text · Lukas Kircher · 288 lines
On Fri, Feb 25, 2011 at 7:46 AM, Lukas Kircher <lukaskircher1 at googlemail.com> wrote: > Hey Sony, > > I found another small typo in your query - the keyword 'node' > is missing in your replace statement. So if you execute the > query below you should be fine. > > for $childentry in $c//childentry > return replace value of node $childentry/@id with > concat('New Child: ', data($c//childentry/@id)) > > Regards, > Lukas > > > > On Thu, Feb 24, 2011 at 11:08 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >> >> .. I see the syntax error : >> [XPST0003] Expecting ")", found "v". >> when I try : >> >> for $childentry in $c//childentry >> return replace value of $childentry/@id with >> concat('New Child: ', data($c//childentry/@id)) >> >> To modify the child entries like so: >> <childentry id="1"> ----- > <childentry id="New Child: 1"> >> >> On Thu, Feb 24, 2011 at 5:03 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >>> >>> ... Replacing the values of attribute nodes doesn't seem to work as >>> expected when I use modify. Please see my previous post with correction in >>> the typo. >>> >>> On Thu, Feb 24, 2011 at 5:00 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >>>> >>>> Please ignore the typo. My sample xquery looks something like this: >>>> >>>> for $childentry in $c//childentry >>>> return replace value of $childentry/@id with >>>> concat('New Child: ', data($c//childentry/@id)) >>>> >>>> To modify the child entries like so: >>>> <childentry id="1"> ----- > <childentry id="New Child: 1"> >>>> >>>> >>>> On Thu, Feb 24, 2011 at 4:50 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >>>>> >>>>> Christian, >>>>> Yes. I did realize that I must use a RETURN statement. I tried that >>>>> with a slight change in the requirement. Say, my child entries look like so >>>>> : >>>>> >>>>> <childentry id="1" /> >>>>> I tried: >>>>> for $childentry in $c//childentry >>>>> return replace value of $childentry/@id with >>>>> concat('New Child: ', $c//childentry/text()) >>>>> Does replace work differently for attributes ? >>>>> Thanks, >>>>> Sony >>>>> >>>>> >>>>> On Thu, Feb 24, 2011 at 3:27 PM, Christian Grün >>>>> <christian.gruen at gmail.com> wrote: >>>>>> >>>>>> Sony, >>>>>> >>>>>> each FLWOR expression needs to be completed with a RETURN statement. >>>>>> Please insert the following snippet (haven't tried it live): >>>>>> >>>>>> for $childentry in $c//childentry >>>>>> return replace value of $childentry with >>>>>> concat('New Child: ', $c//childentry/text()) >>>>>> >>>>>> Hope this helps, >>>>>> Christian >>>>>> ___________________________ >>>>>> >>>>>> Christian Grün >>>>>> Uni KN, Box 188 >>>>>> 78457 Konstanz, Germany >>>>>> http://www.inf.uni-konstanz.de/~gruen >>>>>> >>>>>> >>>>>> >>>>>> On Thu, Feb 24, 2011 at 9:24 PM, Sony Vijay <sony.vibh at gmail.com> >>>>>> wrote: >>>>>> > Christian, >>>>>> > Thank you very much for helping me with the query. However, I am not >>>>>> > quite >>>>>> > sure how the transform operation works if I have to use a for loop. >>>>>> > Say, I >>>>>> > twist around yesterday's question a bit like so: >>>>>> > copy $c := >>>>>> > <entry> >>>>>> > <id>1</id> >>>>>> > <title>How to use a transform expression</title> >>>>>> > <updated>2011-02-23</updated> >>>>>> > <author> >>>>>> > <name>BaseX Team</name> >>>>>> > <uri>http://basex.org</uri> >>>>>> > </author> >>>>>> > <childentry> 1 </childentry> >>>>>> > <childentry> 2 </childentry> >>>>>> > <childentry> 3 </childentry> >>>>>> > <content type="html">Transform expression example created by BaseX >>>>>> > Team</content> >>>>>> > </entry> >>>>>> > modify ( >>>>>> > replace value of node $c//name with 'BaseX', >>>>>> > replace value of node $c//content with concat('Copy of: ', >>>>>> > $c//content), >>>>>> > insert node <member>Joey</member> into $c//author >>>>>> > for $childentry in $c//childentry >>>>>> > replace value of $childentry with concat('New Child: ', >>>>>> > $c//childentry/text()) >>>>>> > ) >>>>>> > return $c >>>>>> > >>>>>> > The expected output is: >>>>>> > <entry> >>>>>> > <id>1</id> >>>>>> > <title>How to use a transform expression</title> >>>>>> > <updated>2011-02-23</updated> >>>>>> > <author> >>>>>> > <name>BaseX</name> >>>>>> > <uri>http://basex.org</uri> >>>>>> > <member>Joey</member> >>>>>> > </author> >>>>>> > <childentry> New Child: 1 </childentry> >>>>>> > <childentry> New Child: 2 </childentry> >>>>>> > <childentry> New Child: 3 </childentry> >>>>>> > <content type="html">Copy of: Transform expression example created >>>>>> > by >>>>>> > BaseX Team</content> >>>>>> > </entry> >>>>>> > The following exception is thrown when I tried my sample >>>>>> > transformation >>>>>> > query with the for loop: >>>>>> > [XPST0003] Expecting 'where', 'order' or 'return' expression. >>>>>> > Thanks, >>>>>> > Sony >>>>>> > PS: @Lukas: I did notice the update in the documentation. Thank you >>>>>> > ! >>>>>> > >>>>>> > >>>>>> > On Wed, Feb 23, 2011 at 2:32 AM, Lukas Kircher >>>>>> > <lukaskircher1 at googlemail.com> wrote: >>>>>> >> >>>>>> >> Hi Sony, >>>>>> >> >>>>>> >> to help others with the same question, I allowed myself to >>>>>> >> add a modified version of your example to our >>>>>> >> documentation [1]. >>>>>> >> >>>>>> >> Regards, >>>>>> >> Lukas >>>>>> >> >>>>>> >> >>>>>> >> [1] http://docs.basex.org/wiki/Update#transform >>>>>> >> >>>>>> >> >>>>>> >> >>>>>> >> On Wed, Feb 23, 2011 at 6:58 AM, Sony Vijay <sony.vibh at gmail.com> >>>>>> >> wrote: >>>>>> >>> >>>>>> >>> Christian, >>>>>> >>> Thank you for the quick and helpful reply. >>>>>> >>> - Sony >>>>>> >>> >>>>>> >>> On Tue, Feb 22, 2011 at 5:56 PM, Christian Grün >>>>>> >>> <christian.gruen at gmail.com> wrote: >>>>>> >>>> >>>>>> >>>> Sony, >>>>>> >>>> >>>>>> >>>> the following query might do what you want: >>>>>> >>>> >>>>>> >>>> copy $c := >>>>>> >>>> <entry xmlns="http://www.w3.org/2005/Atom" >>>>>> >>>> xmlns:libx="http://libx.org/xml/libx2"> >>>>>> >>>> <id>1</id> >>>>>> >>>> <title>Link Amazon By ISBN</title> >>>>>> >>>> <updated>2010-09-29T18:37:48.592Z</updated> >>>>>> >>>> <author> >>>>>> >>>> <name>LibX Team</name> >>>>>> >>>> <uri>http://libx.org</uri> >>>>>> >>>> <email>libx.org at gmail.com</email> >>>>>> >>>> </author> >>>>>> >>>> <content type="html">Content created by LibX Libapp >>>>>> >>>> Builder</content> >>>>>> >>>> </entry> >>>>>> >>>> modify ( >>>>>> >>>> replace value of node $c//*:name with 'Sony', >>>>>> >>>> replace value of node $c//*:content with >>>>>> >>>> concat('Copy of: ', $c//*:content) >>>>>> >>>> ) >>>>>> >>>> return $c >>>>>> >>>> >>>>>> >>>> >>>>>> >>>> Best, >>>>>> >>>> Christian >>>>>> >>>> ___________________________ >>>>>> >>>> >>>>>> >>>> On Tue, Feb 22, 2011 at 11:43 PM, Sony Vijay >>>>>> >>>> <sony.vibh at gmail.com> >>>>>> >>>> wrote: >>>>>> >>>> > Hi, >>>>>> >>>> > I am using BaseX 6.5. I am trying to transform a given node >>>>>> >>>> > using an >>>>>> >>>> > XQuery. >>>>>> >>>> > >>>>>> >>>> > Say, I have an node like so: >>>>>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>>>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>>>> >>>> > <id>1</id> >>>>>> >>>> > <title>Link Amazon By ISBN</title> >>>>>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>>>> >>>> > <author> >>>>>> >>>> > <name>LibX Team</name> >>>>>> >>>> > <uri>http://libx.org</uri> >>>>>> >>>> > <email>libx.org at gmail.com</email> >>>>>> >>>> > </author> >>>>>> >>>> > <content type="html">Content created by LibX Libapp >>>>>> >>>> > Builder</content> >>>>>> >>>> > </entry> >>>>>> >>>> > I am trying to send this node to an xquery which is expected to >>>>>> >>>> > do the >>>>>> >>>> > following actions: >>>>>> >>>> > >>>>>> >>>> > create a copy of this node (so that the actual node in the >>>>>> >>>> > database >>>>>> >>>> > does not >>>>>> >>>> > change), >>>>>> >>>> > transform/modify the duplicate copy of the given node >>>>>> >>>> > return the modified duplicate copy of the given node >>>>>> >>>> > >>>>>> >>>> > I would expect the output to be like so: >>>>>> >>>> > <entry xmlns="http://www.w3.org/2005/Atom" >>>>>> >>>> > xmlns:libx="http://libx.org/xml/libx2"> >>>>>> >>>> > <id>1</id> >>>>>> >>>> > <title>Link Amazon By ISBN</title> >>>>>> >>>> > <updated>2010-09-29T18:37:48.592Z</updated> >>>>>> >>>> > <author> >>>>>> >>>> > <name>Sony</name> >>>>>> >>>> > <uri>http://libx.org</uri> >>>>>> >>>> > <email>libx.org at gmail.com</email> >>>>>> >>>> > </author> >>>>>> >>>> > <content type="html">Copy of: Content created by LibX Libapp >>>>>> >>>> > Builder</content> >>>>>> >>>> > </entry> >>>>>> >>>> > I tried to perform the non-updating functions using transform >>>>>> >>>> > and also >>>>>> >>>> > tried >>>>>> >>>> > to use a pending update list >>>>>> >>>> > (Reference: http://docs.basex.org/wiki/Update#transform). None >>>>>> >>>> > of this >>>>>> >>>> > works >>>>>> >>>> > as expected. Could you refer me to a more detailed >>>>>> >>>> > documentation for >>>>>> >>>> > performing such transform operations on nodes ? >>>>>> >>>> > Thanks, >>>>>> >>>> > Sony >>>>>> >>>> > >>>>>> >>>> > _______________________________________________ >>>>>> >>>> > BaseX-Talk mailing list >>>>>> >>>> > BaseX-Talk at mailman.uni-konstanz.de >>>>>> >>>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>>>> >>>> > >>>>>> >>>> > >>>>>> >>> >>>>>> >>> >>>>>> >>> _______________________________________________ >>>>>> >>> BaseX-Talk mailing list >>>>>> >>> BaseX-Talk at mailman.uni-konstanz.de >>>>>> >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>>>> >>> >>>>>> >> >>>>>> > >>>>>> > >>>>> >>>> >>> >> > >
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery