Variables in Option Rules

Syntax: <yyyy rule="xpath" variable="xpath" …/>

Example: <overlay rule="count(//supplier[@name=VARIABLE()]) > count(//supplier[@name!=VARIABLE()])" variable="supplier/@name" pattern="#major" …/>

Use: Specifies a variable to use when checking if the rule matches.

The variable attribute is used to provide a local variable for the rule expression (it is only in scope for the rule for this option). This is useful in cases where the rule alone is not sufficient to capture the desired situation. In the above example, the value of supplier/@name is the name of the company who supplied the component. This datum is accessible in the rule expression through the XPath function VARIABLE(), which takes no arguments. The expression count(//supplier[@name= VARIABLE()]) is the number of components which have the same supplier. Likewise count(//supplier[@name!= VARIABLE()]) is the number that does not have that supplier. Hence, the total rule matches in the total number of components with the same supplier as the current component is greater than the number of components from all other suppliers.