Skip to content

Instantly share code, notes, and snippets.

@avernet
Created February 1, 2013 18:02
Show Gist options
  • Save avernet/4692948 to your computer and use it in GitHub Desktop.
Save avernet/4692948 to your computer and use it in GitHub Desktop.
xforms-model.xpl A pipeline to run arbitrary XForms code on the server
<!--
Copyright (C) 2007 Orbeon, Inc.
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation; either version
2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
-->
<!--
This pipeline dispatches xforms-ready on the first XForms model.
<p:processor name="oxf:pipeline">
<p:input name="config" href="/ops/xforms/xforms-model.xpl"/>
<p:input name="model">
<models>
<xforms:model id="default-model"> ... </xforms:model>
</models>
</p:input>
<p:input name="input-instance"> ... </p:input>
<p:output name="output-instance" id="output-instance"/>
</p:processor>
Constraints:
* The 'input-instance' input must always be connected, even if not used in the model
* All the models must have an id attribute
* All the instances must have an id attribute
-->
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<p:param name="model" type="input"/>
<p:param name="input-instance" type="input"/>
<p:param name="output-instance" type="output"/>
<p:processor name="oxf:xslt">
<p:input name="data" href="#model"/>
<p:input name="config">
<xsl:stylesheet version="2.0">
<xsl:import href="oxf:/oxf/xslt/utils/copy.xsl"/>
<!-- Put the XForms models in an HTML wrapper as this is what the XForms engine still expects -->
<xsl:template match="/">
<xhtml:html xsl:version="2.0">
<xhtml:head>
<xsl:apply-templates select="/xforms:model treat as element()"/>
</xhtml:head>
</xhtml:html>
</xsl:template>
<!-- Content of input-instance comes from input instance -->
<xsl:template match="xforms:instance[@id = 'input-instance']">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="src">input:instance</xsl:attribute>
</xsl:copy>
</xsl:template>
<!-- At the end of the model, on xforms-ready, submit output-instance so it gets output by the XForms engine -->
<xsl:template match="xforms:model">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<!-- Log message on XForms error -->
<xforms:message ev:event="xxforms-action-error" level="xxforms:log-error" value="concat('xxforms-action-error: ', event('message'),
' in ', event('system-id'), ' line ', event('line'))"/>
<xforms:submission id="send-output-instance" ref="instance('output-instance')" method="post" action="echo:" replace="all"/>
<xforms:send if="exists(instance('output-instance'))" submission="send-output-instance" ev:event="xforms-ready"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</p:input>
<p:output name="data" id="xforms-document"/>
</p:processor>
<p:processor name="oxf:xforms-to-xhtml">
<p:input name="annotated-document" href="#xforms-document"/>
<p:input name="instance" href="#input-instance"/>
<p:input name="data"><dummy/></p:input>
<p:output name="document" id="binary-output-instance"/>
</p:processor>
<!-- Parse XML returned -->
<p:processor name="oxf:to-xml-converter">
<p:input name="data" href="#binary-output-instance"/>
<p:input name="config"><config/></p:input>
<p:output name="data" ref="output-instance" id="parsed-output-instance"/>
</p:processor>
<!-- In case nobody reads the output of this pipeline, still read the output of the XForms engine so XForms runs -->
<p:processor name="oxf:null-serializer">
<p:input name="data" href="#binary-output-instance"/>
</p:processor>
</p:config>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment