Orbeon Forms
  • Getting started
  • Installation
    • Logging
    • Configuration banner
    • Docker
    • Azure
    • Tomcat
    • WildFly
    • WebSphere
    • WebLogic
    • GlassFish
    • Caches
    • Replication
    • Upgrading
  • Configuration
    • Properties
      • General
        • HTTP client
      • Form Runner
        • Detail page
          • Attachments
          • Email properties
          • PDF
          • Table of contents
        • Persistence
        • Summary page
      • Form Builder
      • XForms
    • Advanced
      • Workflows
      • Session management
      • State handling
      • Client-side error handling
      • Clustering and High Availability
      • Configuring a Form Runner eXist database
      • Creating a production WAR
      • Environments
      • JavaScript and CSS assets
      • Limiter filter
      • Run modes
      • Security
        • Content-Security-Policy header
      • SAP Hybris Module
      • XForms logging
    • Troubleshooting
      • Troubleshooting with the orbeon.log
      • Memory and threads
      • Relational database logging
      • Misc
  • Form Builder
    • Form settings
      • Time window
    • Form editor
      • Form area
      • Toolbox
      • Buttons bar
      • Control settings
      • Dependent fields and sections
      • Validation
      • Choices editor
      • Publishing
      • Cut, copy and paste
      • Section and grid settings
      • Section settings
      • Grid settings
      • Quick control search
      • Repeat settings
      • Repeated grids
      • Undo and redo
      • Keyboard shortcuts
    • Formulas
      • Examples of formulas
      • Formulas inspector
      • Formulas console
    • Summary page
    • Form localization
    • Advanced
      • Edit source
      • Services and actions
        • HTTP services
        • Database services
        • Simple Actions
        • Action Syntax
        • Action Syntax examples
        • Synchronizing repeated content
      • Testing a form in web mode
      • Testing PDF production
      • Testing offline functionality
      • Email Settings dialog
      • Field-level encryption
      • Messages
      • Section templates
      • Template syntax
      • XML Schemas support
      • Extensibility
        • Extension API
        • Integration
        • Toolbox component metadata
  • Form Runner
    • Overview
      • Terminology
    • Pages
      • Landing page
      • Published Forms page
      • Forms Admin page
      • Summary page
    • Components
      • Alert dialog
      • Attachment
      • Autocomplete
      • Captcha
      • Character counter
      • Checkbox input
      • Currency
      • Date
      • Dropdown date
      • Static and dynamic dropdown
      • Error summary
      • Grid
      • Handwritten signature
      • Hidden field
      • Image
      • Image annotation
      • Image attachment
      • Number
      • Open selection
      • Repeater
      • Formatted Text / Rich Text Editor
      • Section
      • Single-selection tree
      • Source code editor
      • Time
      • US phone
      • US state
      • Video
      • Video attachment
      • Wizard
      • XForms inspector
      • Yes/No answer
    • Features
      • Automatic calculations dependencies
      • Datasets
      • Excel and XML import
      • Excel and XML export
      • Summary page Excel Export
      • Form definitions and form data Zip Export
      • Purging historical data
      • Lease
      • Localization
      • Supported languages
      • Mobile support
      • Multitenancy
      • Form Runner navigation bar
      • PDF production
        • Automatic PDF
        • Automatic PDF header and footer configuration
        • PDF templates
      • Responsive design
      • Revision history
      • S3 storage
      • Simple data migration
      • TIFF production
      • Versioning
      • Wizard view
      • Workflow stage
    • Persistence
      • Using a relational database
      • Relational database schema
      • Purging old data using SQL
      • Auditing
      • Autosave
      • Database support
      • Flat view
    • Linking and embedding
      • Linking
      • Java Embedding API
      • JavaScript Embedding API
      • Liferay full portlet
      • Liferay proxy portlet
      • Securing Form Runner access
      • Form Runner offline embedding API
      • Angular component
      • React component
    • Access control and permissions
      • Users
      • Login & Logout
      • Deployed forms
      • Form fields
      • Editing forms
      • Owner and group member
      • Organizations
      • Scenarios
      • Token-based permissions
    • Styling
      • CSS
      • Grids CSS
      • Automatic PDF styling and CSS
    • APIs
      • Authentication of server-side service APIs
      • Persistence API
        • CRUD API
        • Search API
        • List form data attachments API
        • Form Metadata API
        • Lease API
        • Reindexing API
        • Caching
        • Versioning
        • Revision History API
        • Zip Export API
        • Custom persistence providers
      • Other APIs
        • Connection context API
        • Duplicate form data API
        • File scan API
        • Form Runner JavaScript API
        • Generate XML Schema API
        • PDF API
        • Publish form definition API
        • Run form in the background API
      • Data formats
        • Form data
        • Date and time
        • Form definition
    • Architecture and integration
      • Architecture
      • Access form data
      • Integration
    • Advanced
      • Buttons and processes
        • Simple process syntax
        • Core actions
        • Form Runner actions
          • Save action
          • Send action
          • Email action
        • XForms actions
        • Predefined buttons, processes and dialogs
        • Summary page buttons and processes
      • Custom dialogs/model logic
      • Services
      • Singleton form
      • Monitoring HTTP requests
  • XForms
    • Core
      • Attribute Value Templates (AVTs)
      • Binds
      • Validation
      • Variables
      • Keyboard focus
      • XForms JavaScript API
      • Error handling
        • Detailed behavior
      • Model-Bind variables
      • XForms 2.0 support
    • Events
      • Standard support
      • UI refresh events
      • Keyboard events
      • Extension events
      • Extension context information
      • Other event extensions
    • Actions
      • Repeat, insert and delete
      • Scripting actions
      • Extensions
    • Controls
      • Label, hint, help
      • Input
      • Output
      • Text area
      • Button
      • Upload
      • Dialog
    • Submission
      • Standard support
      • JSON support
      • Asynchronous submissions
      • Caching extension
      • Other submission extensions
    • XPath
      • Type annotations
      • Expression analysis
      • Tips
      • Compatibility
      • Standard functions
      • Maps and arrays Functions
      • Extension functions
        • Core functions
        • Utility functions
        • Model functions
        • Controls functions
        • XML functions
        • JSON functions
        • HTTP functions
        • Form Runner functions
        • Other functions
        • Deprecated functions
    • XBL components
      • FAQ
      • Guide
        • XBL Tutorial
        • Bindings
        • XForms models
        • Including content
        • Event handling
        • Conventions
        • Map XBL example
        • Learning from existing components
      • Advanced topics
        • XBL Modes
        • JavaScript companion classes
        • XBL library
        • Extensions
        • Attachment controls
    • XForms tutorial
      • Introduction
      • Installation
      • The Hello application
      • The Bookcast application
        • The basic app
        • Database access
        • Polishing the app
        • Adding a feed
    • Using XForms from Java apps
  • XML Platform
    • Page Flow Controller
      • Basics
      • XML submission
      • Navigating between pages
      • Paths and matchers
      • Other configuration elements
      • Typical combinations of page model and page view
      • Examples
      • Authorizing pages and services
    • Processors
      • URL generator
      • Request generator
      • PDF to image converter
    • Resources
      • Resource managers
      • Setting up an external resources directory
    • Other
      • Binary and text documents
  • FAQ
    • Licensing
    • PE and Dev Support
    • Form Builder and Form Runner
    • Resources and support
    • Other technical questions
  • Contributors
    • Automated tests
    • Building Orbeon Forms
    • Localizing Orbeon Forms
    • Validation functions
    • Contributor License Agreement
  • Release notes
    • Orbeon Forms 2022.1.9
    • Orbeon Forms 2024.1.1
    • Orbeon Forms 2023.1.7
    • Orbeon Forms 2024.1
    • Orbeon Forms 2023.1.6
    • Orbeon Forms 2023.1.5
    • Orbeon Forms 2021.1.11
    • Orbeon Forms 2022.1.8
    • Orbeon Forms 2023.1.4
    • Orbeon Forms 2023.1.3
    • Orbeon Forms 2023.1.2
    • Orbeon Forms 2022.1.7
    • Orbeon Forms 2023.1.1
    • Orbeon Forms 2023.1
    • Orbeon Forms 2022.1.6
    • Orbeon Forms 2021.1.10
    • Orbeon Forms 2022.1.5
    • Orbeon Forms 2021.1.9
    • Orbeon Forms 2022.1.4
    • Orbeon Forms 2022.1.3
    • Orbeon Forms 2021.1.8
    • Orbeon Forms 2022.1.2
    • Orbeon Forms 2022.1.1
    • Orbeon Forms 2022.1
    • Orbeon Forms 2021.1.7
    • Orbeon Forms 2021.1.6
    • Orbeon Forms 2021.1.5
    • Orbeon Forms 2021.1.4
    • Orbeon Forms 2021.1.3
    • Orbeon Forms 2021.1.2
    • Orbeon Forms 2021.1.1
    • Orbeon Forms 2021.1
    • Orbeon Forms 2020.1.6
    • Orbeon Forms 2019.2.4
    • Orbeon Forms 2019.1.2
    • Orbeon Forms 2018.2.5
    • Orbeon Forms 2018.1.4
    • Orbeon Forms 2020.1.5
    • Orbeon Forms 2020.1.4
    • Orbeon Forms 2020.1.3
    • Orbeon Forms 2020.1.2
    • Orbeon Forms 2019.2.3
    • Orbeon Forms 2020.1.1
    • Orbeon Forms 2020.1
    • Orbeon Forms 2019.2.2
    • Orbeon Forms 2019.2.1
    • Orbeon Forms 2019.1.1
    • Orbeon Forms 2019.2
    • Orbeon Forms 2019.1
    • Orbeon Forms 2018.2.4
  • Release history
  • Use cases
  • Product roadmap
  • Index of features
Powered by GitBook
On this page
  • Rationale
  • The variable element
  • Variables within xf:model
  • Variables declared by xf:bind elements
  • Variables outside of xf:model
  • Variables within xf:action
  • The xxf:value element
  • Scoping of variables in the view
  • Current limitations
  1. XForms
  2. Core

Variables

Rationale

Orbeon Forms supports declaring variables which look and behave very much like XSLT variables. Variables are extremely useful, for example to avoid repeating long XPath expressions, or to give an XPath expression unambiguous access to data computed in enclosing <xf:group> or <xf:repeat> elements.

The variable element

You define variables with the extension element:

<xf:var>

For backward compatibility, the following elements are still supported:

  • <xxf:variable>

  • <exf:variable> (in the eXforms namespace)

The element supports the following attributes:

name

mandatory

name of the variable

as

optional

type of the variable (ignored but can be used for documentation purposes)

model

optional

contributes to the variable's single-item binding

context

optional

contributes to the variable's single-item binding

ref

optional

contributes to the variable's single-item binding

bind

optional

contributes to the variable's single-item binding

value

optional

XPath 2.0 expression determining the value of the variable

The expression is evaluated in the element's single-item binding if present, otherwise in the context of its parent.

If the value attribute is omitted, the text content of the <xf:var> element is used as the value.

Variables within xf:model

Directly under the <xf:model> element, the following rules apply:

  • Variables are supported directly under the <xf:model> element.

  • Model variables are evaluated in the order in which they appear in the model.

  • All model variables are visible to other model elements such as <xf:bind> or <xf:submission>.

  • Model variables are also visible from XPath expression outside of models whenever that model is in scope.

<xh:head>
    <xf:model id="my-model">
        <xf:instance id="my-instance">...</xf:instance>
        <xf:var name="mine" value="."/>
    </xf:model>
    <xf:model id="her-model">
        <xf:instance id="her-instance">...</xf:instance>
        <xf:var name="hers" value="instance('her-instance')"/>
    </xf:model>
</xh:head>
<xh:body>
    <!-- $mine is visible from here, but not $hers -->
    <xf:output value="$mine">
        <xf:label>My stuff:</xf:label>
    </xf:output>
    <xf:group model="her-model">
        <!-- $hers is visible from here, but not $mine -->
        <xf:output value="$hers">
            <xf:label>Her stuff:</xf:label>
        </xf:output>
    </xf:group>
</xh:body>

Variables declared by xf:bind elements

Variables outside of xf:model

Outside of models, the following rules apply:

  • Variables are supported anywhere XForms controls are allowed.

  • A given variable is visible to any XPath expression on a following sibling element or on a following sibling element's descendant element.

<xh:body>
    <!-- Variable pointing to the default instance's root element -->
    <xf:var name="instance" value="."/>
    <!-- variable pointing to all the item children -->
    <!-- It uses the variable declared above -->
    <xf:var name="items" value="$instance/item"/>

    <!-- The code below uses the variables in scope -->
    <xf:repeat ref="$items" id="items-repeat">
        <xf:var name="current-item" value="."/>
        <xf:var name="current-position" value="position()"/>
        <xf:output id="my-count" ref="$current-item/value">
            <xf:label value="concat($current-item/label, ':')"/>
            <xf:setvalue event="my-event" ref="$current-item/value" value="count($items) + $current-position"/>
        </xf:output>
    </xf:repeat>
</xh:body>

Variables within xf:action

Variables are allowed within <xf:action> elements, whether those elements are used within models or controls.

<xf:model>
    <xf:instance>
        <instance>
            <foo>42</foo>
            <bar>43</bar>
        </instance>
    </xf:instance>
    <!-- These variables are defined within the model -->
    <xf:var name="foo" value="foo"/>
    <xf:var name="bar" value="bar"/>
</xf:model>
...
<xf:group>
    <!-- This variable is defined within the group control and has access to the in-scope model variables -->
    <xf:var name="sum" value="$foo + $bar"/>
    <xf:group>
        <xf:action event="my-event">
            <!-- This action has access to all variables in scope -->
            <xf:setvalue ref="sum" value="$sum"/>
            <!-- This variable is defined within the action and has access to all the variables in scope -->
            <xf:var name="difference" value="$foo - $bar"/>
            <xf:setvalue ref="difference" value="$difference"/>
        </xf:action>
    </xf:group>
</xf:group>

The xxf:value element

You can nest an <xxf:value> element within <xf:var>.

NOTE: The <xxf:value> element replaces the deprecated <xxf:sequence> element but works exactly the same way. Until Orbeon Forms 4.6 included, you must use the element <xxf:sequence>. From Orbeon Forms 4.7 onward, use <xxf:value>.

The element supports the following attributes:

model

optional

contributes to the element's single-item binding

context

optional

contributes to the element's single-item binding

ref

optional

contributes to the element's single-item binding

bind

optional

contributes to the element's single-item binding

value

optional

XPath 2.0 expression determining the value of the variable

The expression is evaluated in the element's single-item binding if present, otherwise in the context of its parent <xf:var> element. If the attribute is omitted, the text content of the <xxf:value> element is used as the value.

This allows you to decouple the variable definition (name) from its evaluation:

<xf:var name="sum">
    <xxf:value value="$foo + $bar"/>
</xf:var>

This is particularly useful for XBL component implementors, where this can be used in combination with the xxbl:scope attribute:

<xf:var name="result" as="node()?">
    <xxf:value value="." xxbl:scope="outer"/>
</xf:var>

Single-item attributes may be used on the <xxf:value> element.

Scoping of variables in the view

The following guidelines apply when using variables in the view:

  • Only variables in the current XBL scope are visible

  • All preceding view variables are visible even across changes of models (with model="...")

  • Finally, the current model's variables are visible

  • Variable hiding applies between view variables and model variables

Example:

<xh:html>
    <xh:head>
        <xf:model id="model1">
            <xf:instance>
                <instance>
                    <foo>42</foo>
                </instance>
            </xf:instance>
            <xf:var name="foo" value="foo"/>
        </xf:model>
        <xf:model id="model2">
            <xf:instance>
                <instance>
                    <foo>44</foo>
                </instance>
            </xf:instance>
            <xf:var name="foo" value="foo"/>
        </xf:model>
    </xh:head>
    <xh:body>
        <!-- Top-level -->
        <!-- model1 is the default model: $foo from model1 is visible -->
        <xf:var name="gaga" value="41"/>
        <!-- $gaga is visible because preceding in the view -->
        <xf:group model="model2">
            <!-- model2 is the current model: $foo from model2 is visible -->
            <xf:var name="toto" value="43"/>
            <!-- $gaga and $toto are visible because they are preceding in the view -->
            <xf:group model="model1">
                <!-- model1 is the current model: $foo from model1 is visible, and $gaga is visible  -->
                <!-- $gaga and $toto are visible because they are preceding in the view -->
            </xf:group>
        </xf:group>
    </xh:body>
</xh:html>

Current limitations

The <xf:var> element has the following limitations:

  • The as attribute is ignored but can be used for documentation purposes.

  • Cannot be used within XForms leaf controls such as <xf:input>, including within nested items or itemsets (except within <xf:action> elements, where they are allowed).

  • Cannot be used within nested model elements, including <xf:bind> or <xf:submission> (except within <xf:action> elements, where they are allowed).

PreviousValidationNextKeyboard focus

Last updated 2 years ago

See .

XForms: Model bind variables