Skip to content

fig:case

Gabriel Zerbib edited this page May 22, 2014 · 3 revisions

fig:case Attribute

This attribute operates in a similar way to fig:cond, but additionally it enables to build a group of mutually exclusive conditions among sibling tags, much like the switch / case construct of the C language.

A group of mutually exclusive conditions is automatically made up, as soon as several sibling tags (i.e. immediate children of the same parent) hold the fig:case attribute. The remaining siblings, which do not hold this attribute, are not part of the group.

The engine renders only the first tag whose condition is satisfied, within the group. All other members of the group are discarded. All other siblings which are not part of the group (i.e. without the fig:case attribute) are rendered regularly.

The default construct of the C language can be achieved by adding to the group a final tag with condition fig:case="true". Then, if no previous condition was satisfied, this last member will be.

It is possible to nest several groups, at different levels of depth in the XML tree. Each group operates independently, within the node space of its parent tag.

Note that each condition can test anything. Unlike the switch/case construct, where one single expression is tested against several values, here each fig:case attribute can use a different condition. The only rule is that, as soon as one is satisfied, in the order of the DOM, then the group finishes.

Value

Expression. If evaluating to true: indicates that the tag should be rendered with all its contents. The other members of the group are then short-circuited. If false, the engine skips the tag and all its contents, including active directives such as fig:feed or fig:include.

Example

<div>
	Only one situation below will appear:
	<span fig:case="price == 20"> Cheap </span>
	<span fig:case="count(items) == 0"> Empty </span>
	<span fig:case="true"> Default case </span>

	<span> And this one always shows! </span>
</div>
Clone this wiki locally