Skip to content

Instantly share code, notes, and snippets.

@ebruchez
Created November 4, 2016 00:14
Show Gist options
  • Save ebruchez/71968da1af24186b99c68a0de51a3604 to your computer and use it in GitHub Desktop.
Save ebruchez/71968da1af24186b99c68a0de51a3604 to your computer and use it in GitHub Desktop.
Simple service to post XForms and return the processed instance server-side
<controller xmlns="http://www.orbeon.com/oxf/controller">
<service
path="/validation/validate"
view="validate.xpl"
public-methods="POST"/>
<epilogue url="oxf:/config/epilogue.xpl"/>
</controller>
<p:config
xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<p:param name="instance" type="input"/>
<p:param name="data" type="output"/>
<p:processor name="oxf:xslt">
<p:input name="data" href="#instance"/>
<p:input name="config">
<xsl:transform version="2.0">
<xsl:import href="oxf:/oxf/xslt/utils/copy.xsl"/>
<xsl:template match="xh:head">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xf:model
id="fr-batch-validation-model"
xxf:xpath-analysis="true"
xxf:no-updates="true">
<xf:instance id="fr-result-instance" xxf:exclude-result-prefixes="#all">
<dummy/>
</xf:instance>
<xf:submission
id="fr-send-result"
ref="instance('fr-result-instance')"
method="post"
action="echo:"
replace="all"/>
<xf:action event="xforms-ready">
<!-- Store first instance of first model -->
<xf:insert
ref="instance('fr-result-instance')"
origin="xxf:instance(xxf:list-instances(xxf:list-models()[1]))"/>
<!-- Output resulting instance -->
<xf:send submission="fr-send-result"/>
</xf:action>
</xf:model>
</xsl:copy>
</xsl:template>
</xsl:transform>
</p:input>
<p:output name="data" id="full-form"/>
</p:processor>
<p:processor name="oxf:xforms-to-xhtml">
<p:input name="annotated-document" href="#full-form"/>
<p:input name="instance"><dummy/></p:input>
<p:input name="data"><dummy/></p:input>
<p:output name="document" ref="data"/>
</p:processor>
</p:config>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment