Help
This form showcases formulas used for calculations and validations in Orbeon Forms.
Lease
Renew lease?

Compare numbers. These formulas compare numbers using all the comparison operators.
$number-1 =  $number-2
$number-1 != $number-2
$number-1 >  $number-2
$number-1 >= $number-2
$number-1 <  $number-2
$number-1 <= $number-2
Number 1
Number 2
false
true
true
false
false
true

Yes/No selection. This formula tells whether the user selected a "Yes" answer using radio buttons.
 
Here is a technical explanation for the use of the string() function:
 
  • Why not just write $yes-no?
    • If you do, the expression will always evaluate to true(), because Orbeon Forms evaluates the formula as boolean($yes-no).
    • Since $yes-no points to an element node, the function always returns true.
  • Why not write $yes-no = true()?
    • In this case, since $yes-no is compared to an xs:boolean value, it is first atomized. The node pointed to by $yes-no is of type xs:boolean, so the atomization process takes the node typed value.
    • When the node contains the string 'true' or 'false', this expression works as expected.
    • However, if it contains an empty string, then the expression fails. For the purpose of determining whether a field is valid, readonly, or visible, when the expression fails the result will be considered to be false(), so it will work if the expression is used on its own.
    • However, if the expression is used in an or clause ($yes-no = true() or something), if the $yes-no = true() part is evaluated first, the expression as a whole will fail and return false(), which is incorrect in case the other part of the or clause is true(). Also, in the case of a calculated value, the result will be the empty string, instead of 'false'.
$yes-no/string() = 'true'
Yes/No answer
false

Testing the value of a checkbox. This formula tells whether a specific option of a checkbox is selected.
if ($checkboxes/xxf:split() = '2') then 'Yes' else 'No'
CheckboxesTry to select various checkboxes
No
Counting selected checkboxes. This formula validates that at most 2 checkboxes are selected.
count(xxf:split($checkboxes-max)) <= 2
CheckboxesTry to select 3 checkboxes

Age. This formula calculates your age based on your birthdate.
 
This assumes that you turn a certain age on the month and day matching your birthday. For that reason, the formula is trickier than just subtracting years, or subtracting a number of days and then dividing (by 365 or 365.25). These other alternatives will not always produce the correct result!
let $date1        := $birthdate,
    $date2        := current-date(),
    $months-days1 := substring(xs:string($date1), 6, 11),
    $months-days2 := substring(xs:string($date2), 6, 11)
return
    if ($months-days2 > $months-days1) then
        year-from-date($date2) - year-from-date($date1)
    else
        year-from-date($date2) - year-from-date($date1) - 1
Birthdate
Current date. Set the initial value of a date field to the current date.
current-date()
Current date
Number of weekdays between two dates. This formula counts how many weekdays are between two dates.
for
    $start          in $first-date,
    $end            in $second-date,
    $startW         in xs:integer(format-date($start, '[F1]')),
    $endW           in xs:integer(format-date($end, '[F1]')),
    $days           in days-from-duration($end - $start),
    $daysNoWeekends in $days - (floor($days div 7) * 2)
return
    if ($days mod 7 != 0 and ($startW = 7 or $endW = 7)) then $daysNoWeekends - 1
    else if ($endW < $startW) then $daysNoWeekends - 2
    else $daysNoWeekends
First date
Second date
22

Number of hours. This formula calculates the number of whole hours between two times.
hours-from-duration(xs:time($end-time) - xs:time($start-time))
Start
End
8
Current time. Set the initial value of a time field to the current time.
current-time()
Current time

Regular expression validation. This formula validates that a text values matches a given regular expression.
matches(., $regex)
Type text here and see if it validates
Validating a Legal Entity Identifier (LEI). This formula validates an LEI (Legal Entity Identifier) field.

NOTE: Since Orbeon Forms 2024.1.2, Orbeon Forms includes a built-in LEI component which performs this validation out of the box.
let $lei := .
return
  string-length($lei) = 20 and
  xs:decimal(
    string-join(
      for $code in string-to-codepoints($lei)
      return
        if ($code >= string-to-codepoints('A') and string-to-codepoints('Z') >= $code) then
          (: Letters A-Z :)
          xs:string($code - string-to-codepoints('A') + 10)
        else if ($code >= string-to-codepoints('0') and string-to-codepoints('9') >= $code) then
          (: Digits 0-9 :)
          xs:string($code - string-to-codepoints('0'))
          (: Unrecognized characters :)
        else
          '',
      ''
    )
  ) mod 97 = 1
Validating an International Securities Identification Number (ISIN).
 
This formula validates an ISIN (International Securities Identification Number). This shows how a formula can become quite sophisticated.

NOTE: Since Orbeon Forms 2024.1.2, Orbeon Forms includes a built-in ISIN component which performs this validation out of the box.

let $isin := .
return
  (
    let
      $without-checksum := substring($isin, 1, 11),
      $letter-as-numbers-string :=
        string-join(
          for $code in string-to-codepoints($without-checksum)
          return
            if ($code >= string-to-codepoints('A') and
                string-to-codepoints('Z') >= $code) then
              (: Letters A-Z :)
              string($code - string-to-codepoints('A') + 10)
            else if ($code >= string-to-codepoints('0') and
                     string-to-codepoints('9') >= $code) then
              (: Digits 0-9 :)
              string($code - string-to-codepoints('0'))
              (: Unrecognized characters :)
            else
              '',
          ''
        ),
      $letter-as-numbers-digits :=
        for $code in string-to-codepoints($letter-as-numbers-string)
        return xs:decimal(codepoints-to-string($code)),
      $reversed-digits :=
        for $i in 1 to count($letter-as-numbers-digits)
        return $letter-as-numbers-digits[count($letter-as-numbers-digits) - $i + 1],
      $group-1-digits := $reversed-digits[position() mod 2 = 1],
      $group-2-digits := $reversed-digits[position() mod 2 = 0],
      $group-1-x2-decimals := for $d in $group-1-digits return $d * 2,
      $group-1-x2-string := string-join(
                              for $d in $group-1-x2-decimals
                              return string($d),
                              ''
                            ),
      $group-1-x2-digits := for $code in string-to-codepoints($group-1-x2-string)
                            return xs:decimal(codepoints-to-string($code)),
      $sum-digits := sum(($group-1-x2-digits, $group-2-digits)),
      $checksum-computed := string((10 - ($sum-digits mod 10)) mod 10),
      $checksum-provided := substring($isin, 12, 1),
      $proper-checksum := $checksum-computed = $checksum-provided,
      $proper-length := string-length($isin) = 12
    return
      $proper-checksum and $proper-length
  )
9a7f2cb98809f4462ce7cb33cb02e49284e3ce49
Confirm
Form Submitted
Review Form Validation Messages
Unable to complete action
Confirmation
Confirmation
Create link to share
Session About To ExpireSession Expired
Your session is about to expire. Click the button below if you wish to continue using this page.
Your session has expired.