multiple updates in a transform query

Friday, 23 September 2011 · 3 messages · last reply 24 Sep 2011
SV
Sony Vijay23 Sep 2011 07:44 #
Hi, Given the following xquery:
import module namespace functx = "http://www.functx.com" at "
http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq";
declare variable $entryid_prefix as xs:string external;
declare variable $src_prefix as xs:string external;
declare variable $other_src_prefix as xs:string external;

let $feeds_metadoc :=
  <feed>
    <entry>
      <id>1</id>
      <child src='2' />
      <child src='libx.org at gmail.com/core' />
    </entry>
  </feed>

return(
  copy $feed_copy := $feeds_metadoc
    modify (
      for $entry in $feed_copy/entry
        return (
          for $entry_id in $entry/id
            where fn:not(fn:contains($entry_id, '/'))
              return replace value of node $entry_id with
concat($entryid_prefix, $entry_id)
          for $src in $entry/child/@src
            return (
              if (fn:contains(data($src), '/'))
              then (
                let $src_id_new := concat($other_srcprefix, $src_id)
                return replace value of node $src with $src_id_new
              )
              else (
                let $src_data := concat($src_prefix, data($src))
                return replace value of node $src with $src_data
              )
            )
        )
    )
  return $feed_copy
)
Say, the values are passed are - $entryid_prefix = 'http://X/", $src_prefix="http://Y/", and $other_src_prefix="http://Z/". After running the above xqueries by passing these values, I expect the output to be:
 <feed>
    <entry>
      <id>http://X/1</id>
      <child src='http://Y/2' />
      <child src='http://Z/libx.org at gmail.com/core' />
    </entry>
  </feed>
I am trying to use multiple for statements within the modify statement and this does not work. I see the following error: java.io.IOException: Stopped at line 23, column 10: [XPST0003] Expecting ")", found "f". I highlighted line 23 for convenience. Please help me fix this. Thanks, Sony
LK
Lukas Kircher23 Sep 2011 09:59 #
Hi Sony, your problems mostly come down to some syntax mistakes: (line 22): There's a comma missing between the two for-loops of your modify clause (the query editor in BaseX actually shows you the exact position of the error - I always use it myself when formulating queries). (line 27) After fixing this the parser comes across an unknown variable, due to a missing underscore. (line27) Fixing this there's another unknown variable $src_id. Again, the highlighting shows you the exact location. I can't really help you with this, as I don't know where this variable is coming from. If you are able to fix this yourself I can further assist you with finishing the query. As for now, the partly corrected query looks like this:
import module namespace functx = "http://www.functx.com" at "
http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq";
declare variable $entryid_prefix as xs:string external;
declare variable $src_prefix as xs:string external;
declare variable $other_src_prefix as xs:string external;

let $feeds_metadoc :=
  <feed>
    <entry>
      <id>1</id>
      <child src='2' />
      <child src='libx.org at gmail.com/core' />
    </entry>
  </feed>

return(
  copy $feed_copy := $feeds_metadoc
  modify (
      for $entry in $feed_copy/entry
        return (
          for $entry_id in $entry/id
            where fn:not(fn:contains($entry_id, '/'))
              return replace value of node $entry_id with
concat($entryid_prefix, $entry_id),
          for $src in $entry/child/@src
            return (
              if (fn:contains(data($src), '/'))
              then (
                let $src_id_new := concat($other_src_prefix, $src_id)
                return replace value of node $src with $src_id_new
              )
              else (
                let $src_data := concat($src_prefix, data($src))
                return replace value of node $src with $src_data
              )
            )
        )
  )
  return $feed_copy
)
Make sure to consult the BaseX query editor first when you come across issues like this - this will save you a great deal of time as you don't have to wait for our answers ... Hope I could help! Lukas
Quoted text · Sony Vijay · 73 lines
On Fri, Sep 23, 2011 at 5:44 AM, Sony Vijay <sony.vibh at gmail.com> wrote: > Hi, > > Given the following xquery: > import module namespace functx = "http://www.functx.com" at " > http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq"; > declare variable $entryid_prefix as xs:string external; > declare variable $src_prefix as xs:string external; > declare variable $other_src_prefix as xs:string external; > > let $feeds_metadoc := > <feed> > <entry> > <id>1</id> > <child src='2' /> > <child src='libx.org at gmail.com/core' /> > </entry> > </feed> > > return( > copy $feed_copy := $feeds_metadoc > modify ( > for $entry in $feed_copy/entry > return ( > for $entry_id in $entry/id > where fn:not(fn:contains($entry_id, '/')) > return replace value of node $entry_id with > concat($entryid_prefix, $entry_id) > for $src in $entry/child/@src > return ( > if (fn:contains(data($src), '/')) > then ( > let $src_id_new := concat($other_srcprefix, $src_id) > return replace value of node $src with $src_id_new > ) > else ( > let $src_data := concat($src_prefix, data($src)) > return replace value of node $src with $src_data > ) > ) > ) > ) > return $feed_copy > ) > > Say, the values are passed are - $entryid_prefix = 'http://X/", > $src_prefix="http://Y/", and $other_src_prefix="http://Z/". After running > the above xqueries by passing these values, I expect the output to be: > > <feed> > <entry> > <id>http://X/1</id> > <child src='http://Y/2' /> > <child src='http://Z/libx.org at gmail.com/core' /> > </entry> > </feed> > > I am trying to use multiple for statements within the modify statement and > this does not work. I see the following error: > java.io.IOException: Stopped at line 23, column 10: > [XPST0003] Expecting ")", found "f". > > I highlighted line 23 for convenience. Please help me fix this. > > Thanks, > Sony > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
SV
Sony Vijay24 Sep 2011 00:18 #
Hi Lukas, Thanks! I sent the correct version of the code earlier to one of the team members who pointed out a possible syntax error but forgot to CC it to the mailing list. Sorry about that. Thanks for pointing out the use of the GUI Query Editor. I will use it from now.
The correct version of the code is shown below (just in case if someone
wants to have a look at it)
import module namespace functx = "http://www.functx.com" at "
http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq";
declare variable $entryid_prefix as xs:string external;
declare variable $src_prefix as xs:string external;
declare variable $other_src_prefix as xs:string external;

let $feeds_metadoc :=
  <feed>
    <entry>
      <id>1</id>
      <child src='2' />
      <child src='libx.org at gmail.com/core' />
    </entry>
  </feed>

return(
  copy $feed_copy := $feeds_metadoc
    modify (
      for $entry in $feed_copy/entry
        return (
          for $entry_id in $entry/id
            where fn:not(fn:contains($entry_id, '/'))
              return replace value of node $entry_id with
concat($entryid_prefix, $entry_id),
          for $src in $entry/child/@src
            return (
              if (fn:contains(data($src), '/'))
              then (
                let $src_id_new := concat($other_srcprefix, $src)
                return replace value of node $src with $src_id_new
              )
              else (
                let $src_data := concat($src_prefix, data($src))
                return replace value of node $src with $src_data
              )
            )
        )
    )
  return $feed_copy
)
Quoted text · Lukas Kircher · 149 lines
On Fri, Sep 23, 2011 at 3:59 AM, Lukas Kircher <lukaskircher1 at googlemail.com > wrote: > Hi Sony, > > > your problems mostly come down to some syntax mistakes: > > (line 22): There's a comma missing between the two for-loops of your > modify clause (the query editor in BaseX actually shows you the > exact position of the error - I always use it myself when formulating > queries). > > (line 27) After fixing this the parser comes across an unknown variable, > due to a missing underscore. > > (line27) Fixing this there's another unknown variable $src_id. Again, the > highlighting shows you the exact location. I can't really help you with > this, as I don't know where this variable is coming from. If you are able > to fix this yourself I can further assist you with finishing the query. > > As for now, the partly corrected query looks like this: > > > import module namespace functx = "http://www.functx.com" at " > http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq"; > declare variable $entryid_prefix as xs:string external; > declare variable $src_prefix as xs:string external; > declare variable $other_src_prefix as xs:string external; > > let $feeds_metadoc := > <feed> > <entry> > <id>1</id> > <child src='2' /> > <child src='libx.org at gmail.com/core' /> > </entry> > </feed> > > return( > copy $feed_copy := $feeds_metadoc > modify ( > for $entry in $feed_copy/entry > return ( > for $entry_id in $entry/id > where fn:not(fn:contains($entry_id, '/')) > return replace value of node $entry_id with > concat($entryid_prefix, $entry_id), > for $src in $entry/child/@src > return ( > if (fn:contains(data($src), '/')) > then ( > let $src_id_new := concat($other_src_prefix, $src_id) > return replace value of node $src with $src_id_new > ) > else ( > let $src_data := concat($src_prefix, data($src)) > return replace value of node $src with $src_data > ) > ) > ) > ) > return $feed_copy > ) > > > Make sure to consult the BaseX query editor first when you come > across issues like this - this will save you a great deal of time as > you don't have to wait for our answers ... > > > Hope I could help! > Lukas > > > On Fri, Sep 23, 2011 at 5:44 AM, Sony Vijay <sony.vibh at gmail.com> wrote: > >> Hi, >> >> Given the following xquery: >> import module namespace functx = "http://www.functx.com" at " >> http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq"; >> declare variable $entryid_prefix as xs:string external; >> declare variable $src_prefix as xs:string external; >> declare variable $other_src_prefix as xs:string external; >> >> let $feeds_metadoc := >> <feed> >> <entry> >> <id>1</id> >> <child src='2' /> >> <child src='libx.org at gmail.com/core' /> >> </entry> >> </feed> >> >> return( >> copy $feed_copy := $feeds_metadoc >> modify ( >> for $entry in $feed_copy/entry >> return ( >> for $entry_id in $entry/id >> where fn:not(fn:contains($entry_id, '/')) >> return replace value of node $entry_id with >> concat($entryid_prefix, $entry_id) >> for $src in $entry/child/@src >> return ( >> if (fn:contains(data($src), '/')) >> then ( >> let $src_id_new := concat($other_srcprefix, $src_id) >> return replace value of node $src with $src_id_new >> ) >> else ( >> let $src_data := concat($src_prefix, data($src)) >> return replace value of node $src with $src_data >> ) >> ) >> ) >> ) >> return $feed_copy >> ) >> >> Say, the values are passed are - $entryid_prefix = 'http://X/", >> $src_prefix="http://Y/", and $other_src_prefix="http://Z/". After running >> the above xqueries by passing these values, I expect the output to be: >> >> <feed> >> <entry> >> <id>http://X/1</id> >> <child src='http://Y/2' /> >> <child src='http://Z/libx.org at gmail.com/core' /> >> </entry> >> </feed> >> >> I am trying to use multiple for statements within the modify statement and >> this does not work. I see the following error: >> java.io.IOException: Stopped at line 23, column 10: >> [XPST0003] Expecting ")", found "f". >> >> I highlighted line 23 for convenience. Please help me fix this. >> >> Thanks, >> Sony >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >> >

⚡Generated with XQuery