# FpML 5.5 Validation Rules - Functions

This is the shared functions part of the validation rule set accompanying the FpML 5.5 Recommendation .

This section introduces functions as a mechanism to define repeatable tests that are applied independent of a context. Functions take node-element types as parameters and return a typed result.

## Content

- Namespace
- Functions
  - ContractIdentifier-equal
  - fpml:deep-equal
  - different-frequencies
  - iff
  - is-unique
  - regular-period
  - same-currency
  - same-currency-scheme

## Namespace

default element namespace = http://www.fpml.org/spec/fpml-5-5-7-rec-1

namespace xs = http://www.w3.org/2001/XMLSchema

## Functions

Function: ContractIdentifier-equal
The result is true where any $contractId1//element(*, ContractId) correlates to any $contractId2//element(*, ContractId). The comparison function for correlation is fpml:deep-equal().

- parameter: $contractId1, $contractId2 (fpml:ContractIdentifier) (min=2, max=2)

- result: true/false (xsd:boolean)

- test: The result is true where any $contractId1//element(*, ContractId) correlates to any $contractId2//element(*, ContractId)

Function: fpml:deep-equal
The fpml:deep-equal function returns true if the $parameter1 and $parameter2 sequences contain the same values, in the same order. Only elements in a current FpML namespace are considered. Atomic values are compared based on their typed values, using the eq operator. If two atomic values cannot be compared (e.g. because one is a number, and the other is a string), the function returns false rather than raise an error. Informally, two nodes are deep-equal if they have all the same attributes and have children (in the same order) who are themselves deep-equal.

- parameter: $parameter1, $parameter2 (item()) (max=*)
- parameter: $collation (xs:string) (max=1)

- result: true/false (xsd:boolean)

- test: The fpml:deep-equal function returns true if the $parameter1 and $parameter2 sequences contain the same values, in the same order

Function: different-frequencies
All frequencies within the context of this rule must be different.

- parameter: $frequency (fpml:Interval) (min=2, max=*)

- result: true/false (xsd:boolean)

- test: All $frequency must not be the same

Function: iff
Return the logical "if and only if" of two xs:boolean operands. This is defined as (operand1 implies operand2) and (operand2 implies operand1). In simple terms, either both are true or neither is true.

- parameter: $p (xsd:boolean)
- parameter: $q (xsd:boolean)

- result: true/false (xsd:boolean)

- test: $p = $q

Function: is-unique
Returns whether the list of atomic types contains any duplicates. If there are no duplicates then result is true.

- parameter: $arg (xsd:anyAtomicType*)

- result: true/false (xsd:boolean)

- test: count(distinct-values($arg)) eq count($arg)

Function: regular-period
The regular period of a set of calculation period dates is the period between a start date and an end date. If firstRegularPeriodStartDate exists, then the start date is firstRegularPeriodStartDate, else the start date is effectiveDate/unadjustedDate. If lastRegularPeriodEndDate exists, then the end date is lastRegularPeriodEndDate, else the end date is terminationDate/unadjustedDate.

- parameter: $cpd (element(*, CalculationPeriodDates))

- result: element(period)

- test: startDate has the value of (if exists($cpd/firstRegularPeriodStartDate) then $cpd/firstRegularPeriodStartDate else $cpd/effectiveDate/unadjustedDate). endDate has the value of (if (exists($cpd/lastRegularPeriodEndDate)) then data($cpd/lastRegularPeriodEndDate) else data($cpd/terminationDate/unadjustedDate))

Function: same-currency
All instances of currency values within the context of this rule must be identical.

- parameter: $money (fpml:Money) (min=2, max=*)

- result: true/false (xsd:boolean)

- test: All ($money/currency and $money/currency/@currencyScheme) must be the same

Function: same-currency-scheme
All instances of currencyScheme URI values within the context of this rule must be identical.

- parameter: $currency (fpml:Currency) (min=2, max=*)

- result: true/false (xsd:boolean)

- test: All ($currency/@currencyScheme) must be the same