Switch Element (View)

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Allows for conditional rendering based on the value of a Collaborative Application Markup Language (CAML) expression.

<Switch
  StripWS = "TRUE" | "FALSE">
  <Expr></Expr>
  <Case Value="Value_1"></Case>
  <Case Value="Value_2"></Case>
  ...
  <Default></Default>
</Switch>

Attributes

Attribute

Description

StripWS

Optional Boolean. TRUE to remove white space from the beginning and end of the value returned by the element.

Child Elements

Case, Default, Expr

Parent Elements

Numerous

Occurrences

Minimum: 0

Maximum: Unbounded

Remarks

A Switch element contains an Expr element, any number of Case elements, and a Default element. The value of the Expr element is compared against the Value attribute of each Case element. When a match is found, the Switch element returns the value of the matching Case element. If no match is found, and if a Default element is given, the Switch element returns the value of the Default element. If no Default element is specified and none of the Case values match the Expr value, the Switch element returns an empty string.

This element does not require any particular parent element.

Example

The following example returns "User Zero" if the UserID value equals 0 (zero); otherwise, the example returns "Not User Zero."

<Switch>
  <Expr><UserID/></Expr>
  <Case Value=”0”>User Zero</Case>
  <Default>Not User Zero</Default>
</Switch>

See Also

Reference

FieldSwitch Element (View)