rsb:enum
The rsb:enum keyword can be used to enumerate through the attributes within an item, the values within a multi-valued attribute, or a supplied range of values. The body of rsb:enum is executed for each element of the set that is being iterated upon.
Parameters:
- item: The name of the item whose attributes you want to iterate upon.
- attr: If present, rsb:enum will only iterate over the attributes matching the specified expression: for example, "rsb:*" You can also provide this parameter to iterate over the values of a multi-valued attribute .
- expand: Boolean parameter that specifies how rsb:enum behaves when multi-valued attributes are encountered. If expand is set to true, the body of rsb:enum> will be executed once for each value of the attribute. If false, all values will be concatenated in a single string value and only a single iteration will be performed for the multiple values. By default rsb:enum will not expand all values..
- separator: If the expand parameter is false, the value of the separator parameter will be used to concatenate values of a multi-valued attribute. The default value is a newline character.
- range: This parameter supports enumerating through a range of numbers or characters in both ascending and descending order: for example, "a..z", "Z..A".
- list: This parameter supports enumerating over a list of separated values. For e.g. if the list of values is "violet, indigo, blue, green, yellow, orange, red" and the separator is a ',' the scope of rsb:enum is executed for each color in the rainbow.
Control Attributes:
- _attr: This attribute contains the name of the attribute being iterated. When you are iterating over the values of a multi-valued attribute ( attr = "name#"), the attribute name will be the same except that it will also have the index as part of the name: for example, name#1, name#2 etc.
- _index: The _index contains the index at which the attribute appears within an item considering the attributes, sorted alphabetically.
- _value: The _value contains the value of the attribute. For a multi-value attribute, you can see the values distinctly, one in each iteration, or see them all together based on the "expand" and "separator" parameter settings.
- _count: The _count contains the number of values in an attribute.
Examples:
This snippet displays the name and values of the item named "input", and generates the following output:<rsb:set item="input" attr="Greeting" value="Hello" /> <rsb:set item="input" attr="Goodbye" value="See ya" /> <rsb:enum item="input"> [_attr] is [_value] <br/> </rsb:enum>
goodbye is See ya greeting is HelloTo enumerate through all the values of an attribute, use the attr argument to specify a multi-value attribute. Such attributes are marked in rsb:info using the item name and ending with the character "#". For example:
Assuming that the attribute "email" of the item "foo" has the values joe@rssbus.com and john@rssbus.com, the result of the snippet below would be:<rsb:info desc="..."> <output name="email#" desc="Email addresses of the user"/> ... </rsb:info>
<rsb:set attr="foo.email#1" value="joe@rssbus.com"/> <rsb:set attr="foo.email#2" value="john@rssbus.com"/> <rsb:enum attr="foo.email" expand="true"> ([_index]) [_attr] -> [_value] </rsb:enum>
(1) email#1 -> joe@rssbus.com (2) email#2 -> john@rssbus.com
Enumerating over a range:
To enumerate over a range of values, use the range attribute. For example:
The snippets above list the character set from "a" to "z", from "Z" to "A" and the numbers from "1" to "25".<rsb:enum range="a..z"> [_value] </rsb:enum> <rsb:enum range="Z..A"> [_value] </rsb:enum> <rsb:enum range="1..25"> [_value] </rsb:enum>
Enumerating over a list of values:
To enumerate over a list of values use the "list" and "separator" parameters of rsb:enum. For example:
The snippets above listscolors specified in the colors attribute.<rsb:set attr="colors" value="violet, indigo, blue, green, yellow, orange, red"/> <rsb:enum list="[colors]" separator=","> [_value] </rsb:enum>
See Also:
- rsb:break: To learn how to break out of rsb:call or rsb:enum iterations
- rsb:continue: To learn how to skip a rsb:call or rsb:enum iteration.
- rsb:first: To learn how to provide special processing in the first iteration.