how to move nodes

  • Erdal Karaca

    Erdal Karaca - 2009-06-10


      <r id="r1"><contents>r1</contents></r>
      <r id="r2"><contents>r2.1</contents></r>
      <r id="r2"><contents>r2.2</contents></r>
      <r id="r2"><contents>r2.3</contents></r>
      <r id="r3"><contents>r3</contents></r>

    modify the input such that this will be the output:

      <r id="r1"><contents>r1</contents></r>
      <r id="r2">
      <r id="r3"><contents>r3</contents></r>

    I need to identify all nodes named "r" whose attributes are equal, then move the contents of the identified nodes into a single node...

    XQJ suggests the "Move Node" ability. Is this supported by mxquery. How to solve/simulate this if it is not supported?


    • Peter M. Fischer


      where did you find the "move node" ability in XQJ - I'm not familiar with it, and a Google search did not deliver any results

      To solve your problem, there are two separate concerns that need to be adressed:
      1) How to put the nodes into the right "group"
      2) Updating the original document or producing a new output

      I'll discuss 2) first:
      Do "input" and "output" need to be in the same file, DOM tree or do you just need to produce "output" from "input"?
      If the latter is the case, you don't need the update facility at all (or maybe just for modify/copy), "normal" XQuery is sufficient

      Regarding 1), there are three solutions:
      If you just want to use XQuery 1.0, you need to express this grouping by a nested loop
      for $a in distinct-values($input/root/r/@id)
        for $b := $input/root/r/@id
      return ...

      (see also\)

      In XQuery 1.1, there are two more elegant solutions:
      If the id values are sorted, the "for tumbling window" expression can create ranges with the same id value
      If the id values are not sorted, the group by expression can create groups with the same id value

      see ( and\)

      MXQuery 0.6.0 implements windowing, groupby will be part of the next release


    • Erdal Karaca

      Erdal Karaca - 2009-06-10

      Sorry, I just mixed up xquery/xqj...
      3.4.7 Moving nodes

      Though, this is marked as "[...]has not been met[...]".
      I am not familiar with w3c processes and thus do not know what that status is all about...

      Thanks for your suggestions, I will try them out.

    • Peter M. Fischer

      The import part there is the issue of "node identity". If you don't care about it (e.g. you are just interested in the new XML "text"), moving nodes can be performed by insert/delete.
      If you do care, there is a problem :)


Log in to post a comment.