This discussion is archived
4 Replies Latest reply: Mar 22, 2013 12:57 PM by KnightOfBlueArmor RSS

XQJ API and updating functions

KnightOfBlueArmor Newbie
Currently Being Moderated
Forgive me if I've cross-posted this; I didn't know whether to put this in the XML DB forum or here.

I have the following XQuery code which is intended to merge two XML documents together, except for the SUMM element which follows special rules.

When I run this code through XQJ using the xqjqpi/xqjori version JAR's, I receive the error "oracle.xquery.xqj.OXQException: XPST0003: It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF." Did I get the XQuery code wrong, or does XQJ not support updating functions at this point?
declare namespace myns="";
declare namespace subns="";
declare namespace mycomp="";

declare updating function mycomp:summ_merge($old, $summ)
     for $entr in $summ/subns:ENTR
     let $chgCd := $entr/subns:CHG_CD
     let $incDateYrMo := $entr[DATA_INC_DT]
     let $oldEntr := $old/subns:SUMM/subns:ENTR[DATA_INC_DT=$incDateYrMo]
        if( $chgCd = '399' and count($oldEntr) = 1 )
        then delete node $oldEntr
        else if( $chgCd = '399' )
        then fn:trace($entr, 'This node was ignored because it had a CHG_CD of 399, but there was no corresponding ENTR: ')
        else if( count($oldEntr) = 1 )
        then replace node $oldEntr with $entr
        else insert node $oldEntr into $summ

declare updating function mycomp:summ_update($old, $summ)
     let $chgCd := $summ/subns:CHG_CD;
        if( $chgCd = '600' )
        then delete node $old/subns:SUMM/*
        else mycomp:summ_merge($old, $summ)

copy $olddoc := $orig
    for $new in $newdoc//myns:PAYLOAD/*
          let $allNew := $newdoc//myns:PAYLOAD/*[name()=name($new)]
          let $old := $olddoc//myns:PAYLOAD
          let $match := $olddoc//myns:PAYLOAD/*[name()=name($new)]
          let $name := name($new)
  if ( local-name($new) = 'SUMM' and count($match) = 1 )
  then mycomp:summ_update($old, $new)
  else if ( local-name($new) = 'SUMM' and count($match) = 0 )
  then insert node $new into $olddoc/myns:PAYLOAD
  else if ( exists($match) and count($match) = 1 and count($allNew) = 1 )
  then replace node $match with $new
  else insert node $new into $old
) return $olddoc


  • Correct Answers - 10 points
  • Helpful Answers - 5 points