Set Attribute conditionally changes an attribute on all elements in the supplied collection of document elements.
The rule does not apply to descendant elements.
This rule uses the following parameters:
- Find
- The text to be found within the existing attribute value of the elements. This can also be a regular expression.
- Replace With
- The text, which replaces the text that was matched.
- Attribute Name
- The name of the attribute whose value is to be modified.
- Case Sensitive
- A true/false selection indicating if the Find string must match the case. Select the check box for true; clear the check box for false.
- RegEx
- A true/false selection indicating if regular expression processing should be used. Select the check box for true; clear the check box for false.
Note: No validation is performed. For example, the attribute may not be allowed by the relevant schema or DTD. We recommend that you validate the change before checking in locking units of the affected elements.
Example: Change or Add an Approval Attribute Value
Note: This example assumes an XML attribute name of approval. This is not a DITA attribute or an Astoria snapshot label (previously called an approval label).
To make an approval attribute have the value
Solstice, regardless of whether an attribute value is currently present, specify a Set Attribute rule with:
Find |
^$|.+ |
Replace With |
Solstice |
Attribute Name |
approval |
Case sensitive |
false (not selected) |
RegEx |
true (selected) |
Note: In this example, the Find value is a regular expression indicating empty value or any character sequence one or more times.
Example: Change Status Attribute Value
To change elements with an existing
status attribute having a value of
pending to have a value of
done, specify a Set Attribute rule with:
Find |
pending |
Replace With |
done |
Attribute Name |
status |
Case sensitive |
false (not selected) |
RegEx |
false (not selected) |
Example: Set an Attribute Value Only if Value is Blank
If you want to set a
product attribute value of
abc only if there is no current value, specify a Set Attribute rule with:
Find |
^$ |
Replace With |
abc |
Attribute Name |
product |
Case sensitive |
false (not selected) |
RegEx |
true (selected) |
Note: In this example, the Find value is a regular expression indicating from start of line to end of line with nothing in between, so it will match only empty attribute values.