The case() Function
string case(string)
xf:case($switch-id as xs:string) as xs:string?
Function case takes a string argument that is the IDREF of a switch and returns the ID of the selected case for the identified switch—see 9.2.1 The switch Element for details on switch. If the specified argument does not identify a switch or a the switch has no case selected, the the empty string/sequence is returned.
Note:
The IDREF obtained from the function parameter may not uniquely identify the desired repeat if the repeat element bearing the matching ID resides in a repeating construct such as element repeat. The general method described in 4.7 Resolving ID References in XForms is used to determine the desired run-time repeat object.
<xforms:switch id="my-switch"> <xforms:case id="my-case-1">...</xforms:case> <xforms:case id="my-case-2">...</xforms:case> </xforms:switch> ... <xforms:trigger> <xforms:label>Do something</xforms:label> <xforms:setvalue if="xforms:case('my-switch')" ref="foobar" value="12"/> </xforms:trigger>
7.3 References, Dependencies, and Dynamic Dependencies
Add the following paragraph, beneath the one of index()
The referencing of a selected case by the case() function is handled as a special case. Implementations must behave as if each occurrence of a switch is associated with an implicitly managed instance data node containing the selected case. If a switch identified as SW1 contains a switch identified as SW2, then a selected case instance node is managed for each occurrence of SW2 that is generated by SW1. An invocation of the function case() in an XPath expression is considered to reference the selected case instance node corresponding to the selected case value that it returns.
XPath 2.0 notes
There should be a global note that sates that if an expression language :
- doesn't supports empty sequences an empty string will be used to represent the empty sequence.
- a sequence of node() (node()*) is a set of nodes if sequences aren't supported
- a sequence of item() (item()*) is degraded to a sequence of node() if sequence of item() aren't supported