Declarative Amsterdam 2019
O'Neil Delpratt [email protected] |
Debbie Lockett [email protected] |
Initialization:
Processing:
<html>
<head>
<script id="xforms-cache">
var XFormsDoc;
var initialInstanceDoc;
var instanceDoc;
var pendingUpdatesMap; /* XPath map*/
var relevantMap; /* XPath map*/
var actions;
/*Getter/Setter Functions */
var setInstance = function(doc) {
instanceDoc = doc;
}
var getInstance = function() {
return instanceDoc;
}
var addAction = function(name, value){
actions[name] = value;
}
var getAction = function(name){
return actions[name];
}
...
</script>
</head>
<body>
...
<div id="xform">
...
<span style="display:inline">
<input data-element="MaintenanceDays"
data-constraint="number(.) ge 0"
data-action="d26aApDhDa"
type="text" value="30"
data-ref="Document/Shipment/Order/MaintenanceDays"/>
</span>
...
</div>
</body>
</html>
<xsl:variable name='action-map' select='map{
"@ref": "Document/Shipment/Order/MaintenanceDays",
"@event": "xforms-value-changed",
"setvalue": [map{"@value": "if(xs:integer(.) > 0) then ...",
"ref": "../../../Options/MaintenanceDate"},
map{"value": "true",
"ref": "../../../Options/Updated"}]
}' />
<xsl:sequence select='js:addAction("d26aApDhDa", $action-map)' />
<xsl:template match="input[exists(@data-action)]"
mode="ixsl:onchange">
<xsl:variable name="refi" select="@data-ref"/>
<xsl:variable name="refElement" select="@data-element"/>
...
<xsl:variable name="xforms-value-change"
select="js:getAction(string(@data-action))"/>
<xsl:variable name="updatedInstanceXML">
...
</xsl:variable>
<xsl:sequence
select="js:setInstance($updatedInstanceXML)"/>
<xsl:for-each select="$xforms-value-change">
<xsl:variable name="action-map" select="."/>
<xsl:variable name="ref"
select="map:get($action-map, '@ref')"/>
<!-- if and while clause setup-->
...
<xsl:variable name="instanceXML_Frag" as="node()">
<xsl:evaluate xpath="$ref"
context-item="$updatedInstanceXML"/>
</xsl:variable>
...
<xsl:sequence>
<xsl:evaluate xpath="map:get(.,'@value')"
context-item="$instanceXML_Frag" />
</xsl:sequence>
...
<!-- update form controls directly or add
change to pendingUpdateMap to change instance later -->
</xsl:for-each>
...
<xsl:sequence select="xforms:checkRelevantFields($refElement)"/>
</xsl:template>