Ralph Corrigan
Ralph Corrigan

Reputation: 23

Inserting nodeset into a document with Exist-db and XSLTforms

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

Upvotes: 1

Views: 68

Answers (2)

Ralph Corrigan
Ralph Corrigan

Reputation: 23

@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.

Upvotes: 0

Joe Wicentowski
Joe Wicentowski

Reputation: 5294

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.

Upvotes: 0

Related Questions