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@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@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@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@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@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk