1

I'm working on setting up an exist-db instance using XSLTforms for non-technical data input. What I want to do sounds simple, but I can't find documentation for it, nor have other asked similar questions, so I'm guessing that I'm missing something obvious here. I want to insert a nodeset from my XSLTforms instance to a pre-existing xml file, but without overwriting the existing data.

<xf:submission id="s03" method="put" nodeset="instance('template')/x/y" resource="../data/XX.xml" replace="none">

works fine in terms of xpath etc, but replaces the entire xx.xml with the new instance. All I want to do is add my instance to the document. I've tried various approaches to create an xpath context for an insert, but this hasn't worked.

What am I doing wrong? Thanks R

  • 1
    Thanks Joe, that looks like it will do exactly what I'm looking to do. Hadn't thought of pivoting via an xq, but that makes sense now. I'll try it later. – Ralph Corrigan May 21 '21 at 06:30
  • Great! If my answer ends up solving the issue for you, please accept is as the answer, and this will help other users know that it was the solution. (For info on accepting & voting on answers, see https://stackoverflow.com/help/someone-answers.) Good luck! – Joe Wicentowski May 21 '21 at 16:39

2 Answers2

0

I recall from my class with Dan McCreary, the primary author of the XForms Wikibook (a great resource), that PUT does overwrite the resource, and the pattern to follow is to POST the result to a saved XQuery that receives the payload and saves it to the database.

As an illustration of this pattern, see the wikibook's article Displaying Save Results, in which you'll the save.xq endpoint receives the POST request's payload, stores the results, and reports on the results.

Joe Wicentowski
  • 5,159
  • 16
  • 26
  • Sorry for the delay Joe, busy here and also some database and implementation specific issues to negotiate. Unfortunately, this is still overwriting the whole document and I've now found the exist-db link that explains that this is the default (without explanation of how to change it! (https://exist-db.org/exist/apps/doc/beginners-guide-to-xrx-v4) I think I still need to provide an somewhere but this is proving problematic... – Ralph Corrigan May 24 '21 at 16:58
  • Glad you found that article, which I really should've mentioned! Are you sure you changed method from PUT to POST? And did you notice how the article distinguishes between the save-new.xq and update.xq endpoints? – Joe Wicentowski May 26 '21 at 06:00
0

@Joe Wicentowski put me on the right path but what I was missing was a simple pre return statement for the update insert:

let $update := update insert $formdata into $target

This allows me to insert a nodeset ($formdata) into a target nodeset ($target) and the return function is simply communicating success or error.

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39