The syntax of If tags
This section will introduce the basics of the RXML If tags.
After reading this section you will know the proper usage of RXML If tags using attributes and operators.
If you are looking for an example, see A basic example of <if>.
If-statements in RXML are built up by combining the six basic tags <if>, <else>, <elseif>, <then>, <true> and <false>. With <if> and <elseif>, attributes are used to state which test(s) to do. One attribute should be one of several If plugins. Logical attributes and, or and not are used to further specify the test(s). We sum this up in the following general syntax (code within '[ ]' is optional):
Always remember to close tags
and to add values to attributes
for proper XML syntax. This is necessary since RXML is a XML compliant language.
Let's have a look at the basic tags:
A test is made if the variable var.foo is 1. This is true because the first line does nothing less than sets that variable to 1. Please note that the spaces around the '=' operator are mandatory.
The same test using if-then-else instead.
In this example the internal <true> is used to set the truth value to true so that the following <then> will be executed.
The attributes used with <if> are:
Here the test is logically negated with not.
The use of <if variable='var.foo != 1'> gives the the same result as <if variable='var.foo = 1' not=''>.
A common mistake done is when combining and, or and not.
will not work since the not attribute negates the whole tag, not just the domain attribute. If you want to negate the whole condition, add not at the end. If you only want to negate one of the attributes, you must rewrite the code with an if-elseif-else statement.
A multiple test with two different If plugins, variable and match.
You could be tempted to write expressions like:
This will not work, as you can only use the same attribute once. Here Variable is used twice.
Above we used the '>' operator. The operators that may be used in expressions are:
Note that '<=' and '>=' are not possible operators except in the Expr plugin. However, for the effect of <if variable='var.foo <= 1'> you simply use <if variable='var.foo > 1' not=''> instead.
Global patterns are possible to use in almost all plugin expressions. ' * ' match zero or more arbitrary characters while ' ? ' matches exactly one arbitrary character.
In this example 130.236.1 as well as 130.236.123 would be true. If the test would be <if ip='130.236.?'> only 130.236.0 - 9 would be true.
Regular expressions are not supported in If tags.
This section has taught you the basics of the If tags. If statements are built up by the six basic tags, <if>, <else>, <elseif>, <then>, <true> and <false>.
With <if> and <elseif> an attribute naming an If plugin must be added. The general syntax is:
Logical attributes, and, or and not adds functionality. Inside the attribute expression, the '=', '==', 'is', '!=', '<' and '>' operators are valid.
Always remember to close tags ( / ) and to give attributes a value ( ='' ) for proper XML syntax.
More details about If tags is found in the Web Site Creator Manual or by putting <help for='if' /> in a web page.
The next section, If plugins will explain the usage of the If plugins.