main | demo | docs
download | community | pike
2000 Roxen Internet Software
Suggestions, Comments or Complaints

DocsRoxen2.0RXML TutorialIf tags

  • The basics of if-else
  • If tags syntax
  • If plugins
  • A basic example
  • <if> and <define>
  • <if supports>
  • Summary
  • If plugins

    This Section will introduce the If plugins used as attributes with <if> and <elseif>.

    After reading this Section you will have knowledge of the different plugin categories and the usage of the plugins.

    The following Sections will contain examples of how to use different plugins for creating dynamic web pages in many different ways.

    The categories

    The If plugins are sorted into five categories according to their function: Eval, Match, State, Utils and SiteBuilder.

    clientvar accept config date ppoint
    cookie client false exists .
    expr domain pragma group .
    match ip prestate time .
    variable language supports user .
    . referrer true . .
    . . . . .

    The following parts will go through these categories and the corresponding plugins. We will look at the proper way of usage and some traps you might fall into.


    The Eval category is the one corresponding to the regular tests made in programming languages, and perhaps the most used. They evaluate expressions containing variables, enities, strings etc and are a sort of multi-use plugins. All If-tag operators and global patterns are allowed (see

    RXML run error: Emit dir couldn't find any contents.
     | <emit glob="*" source="dir">

    clientvar clientvar="var[ is value]"
    cookie cookie="name[ is value]"
    expr expr="pattern"
    match match="pattern1[,pattern2,...]"
    variable variable="name[ is pattern]"

    Cookie and Variable plugins use a similar syntax. is can be any valid operator and name is the name of any defined or undefined variable(cookie). They first check if the named variable(cookie) exists, and if it does and a pattern(value) is specified, the expression will be evaluated. Variable is a general plugin while Cookie is for testing existence and/or values of cookies.

    <set variable="" value="10" />
    <if variable="&; = 10">

    RXML parse error: No current scope.
     | <if variable="10 = 10">

    Please note that it is the name of the variable, not the entity representing it, that should be used. Here we receive an error from the RXML parser becase we used an entity instead of a variable name. The proper way to do the test above is <if variable=" = 10">.

    Match is used in a similar way, but there are certain differences. The syntax is <if match="pattern">, where pattern could be any expression. We could use <if match=" = 10"> although this is rather meaningless, since we would check if the name of the variable (or the string "") was equal to the string "10", which it obviously is not. The only thing that would return true in this case is another meaningless expression: <if match=" is">.

    Instead we should always use entities with Match, i.e. &;. In RXML, entities are used to represent the contents of something, e.g. a variable. An entity is written as a variable name enclosed with '&' and ';'. Above the name of the variable is, the value is "10" and the entity is &;. The entity is replaced by its content when parsed to HTML, in this case "10".

    <set variable="" value="10" />
    <if match="&; = 10">

    Again, variable name goes with Variable and entity goes with Match.

    A warning when testing patterns with whitespaces. If you want to test if the entity &; equals the string "he is nice" and do like this...

    <set variable="" value="he is nice" />
    "&;" <br /><br />
    <if match="&; is he is nice"> is "he is nice"
    <else> is not "he is nice"
    "he is nice" is not "he is nice" won't get the expected result. This is because the Match plugin interprets the first valid operator after a whitespace as the operator to use. In the example above the test really is if "he" equals "nice is he is nice", which obviously is false. Rember that the string "is" also is a valid operator.

    Expr evaluates mathematical and logical expressions. The following characters only should be used in the expression:

    1, 2, 3, 4, 5, 6, 7, 8, 9, 0, ., x, a, b, c, d, e, f, X, A, B, C, D, E, F
    For numbers, decimal, octal and hexadecimal. E.g. 1.23, 010 == 8, 0xA1 == 161

    i, n, t, f, l, o, a, t
    For type casting between integers and floats. E.g. (int)3.45 == 3, (float)3 == 3.000000

    <, >, =, -, +, *, /, %, ( ,)
    Mathematical operators. Note that '==' should be used for equality. E.g. 10 % 4 == 2 , (1 + 2) * 3 == 9

    &, |
    Logical operators. Note that '&&' and '||' should be used for 'and' and 'or', that '1' equals 'true' and '0' equals 'false'. E.g. 1+0 && 1

    If any other character is used there will be an error in the RXML parser. Therefore entities should be used, not the variable name, in a similar way as Match.

    <set variable="" value="2" />
    <if expr="1+&;*3==7"> = 7
    <else> = 9
    </else> = 7

    An example of expr showing that the regular rules of mathematics applies here. The expression evaluates correctly as

    1+2*3 == 1+6 == 7

    and not as

    1+2*3 == 3*3 == 9

    Note that the '==' operator must be used for "equals", unlike the other Eval plugins. Also note that whitespaces around operators are not mandatory.

    Clientvar extends the Supports plugin, see State below. It is used for tests of the client requesting the web page, e.g. a browser or a WAP phone. The following variables (var) are currently testable:

  • height - The presentation area height in pixels (WAP clients)
  • javascript - The highest version of javascript supported
  • robot - The name of the web robot
  • width - The presentation area width in pixels (WAP clients)
  • is can be any valid operator.

    <if supports="javascript">
      <if clientvar="javascript < 1.2">
        Your browser supports older versions of javascript
        Your browser supports javascript
      Your browser doesn't support javascript at all
    Your browser doesn't support javascript at all

    The variable can be used in expressions as shown above. Clientvar can test the exact JavaScript version supported, unlike Supports, that only checks if JavaScript is supported or not.


    The Match category contains plugins that match contents of something, e.g. an IP package header, with arguments given to the plugin as a string or a list of strings.

    accept accept="type1[,type2,...]"
    client client="pattern"
    domain domain="pattern1[,pattern2,...]"
    ip ip="pattern1[,pattern2,...]"
    language language="language1[,language2,...]"
    referrer referrer="pattern1[,pattern2,...]"

    Accept checks which content types the browser accepts as specified by it's Accept-header, e.g. "image/jpeg" or "text/html".

    <p>You are using
    <if client="Mozilla*">
      <if client="*compatible*msie*">
        <b>Internet Explorer</b>.
      <elseif client="*compatible*opera*">
      another client.

    You are using another client.

    Client compares the user agent string with the given pattern.

    Domain and Ip plugins checks if the DNS name or IP address of the user's computer match any of the patterns specified. Note that domain names are resolved asynchronously, and that the first time the browser accesses a page containing <if domain>, the domain name might not have been resolved yet.

    Language matches languages with the Accept-Language header.

    Referrer checks if the Referrer header match any of the patterns.


    State plugins check which of the possible conditions something is in, e.g. if a flag is set or not, if something is supported or not, if something is defined or not etc.

    config config="name"
    false false=""
    pragma pragma="string"
    prestate prestate="option1[,option2,...]"
    supports supports="feature"
    true true=""

    True and False are plugins used in exactly the same way as <then> and <else>. Should not be confused with the <true> and <false> tags.

    <set variable="" value="10" />
    <if variable=" is 10" />
    <if true=""> is 10
    <if false=""> is not 10
    </if> is 10

    Config tests if the RXML config named has been set by use of the <aconf> tag.

    <if pragma="no-cache">
      The page has been reloaded!
      Reload this page!
    Reload this page!

    Pragma compares the HTTP header pragma with the given string.

    Prestate checks if all of the specified prestate options, e.g. "(debug)", are present in the URL.

    Supports tests if the client browser supports certain features such as frames, cookies, javascript, ssl among others. An example of this with a complete list of features that can be tested is found in the Section

    RXML run error: Emit dir couldn't find any contents.
     | <emit glob="*" source="dir">


    The Utils category contains additional plugins, each specialized in a certain type of test.

    date date="yyyymmdd" [before,after] [inclusive]
    exists exists="path"
    group group="name" groupfile="path"
    time time="hhmm"" [before,after] [inclusive]
    user user="name1[,name2,...] [any]"

    <if time="1200" before="" inclusive="">
       ante meridiem (am)
       post meridiem (pm)
    ante meridiem (am)

    Date and Time plugins are quite similar. They check if today is the date "yyyymmdd" or if the time is "hhmm". The attributes before, after and inclusive may be added for wider ranges.

    <if exists="/dir1/dir2/foo.html">
       foo.html exists
       foo.html doesn't exist
    foo.html exists

    Exists checks if a file path exists in a file system. If the entered path does not begin with '/', it is assumed to be a URL relative to the directory containing the page with the <if exists> statement.

    Group checks if the current user is a member of the group according the groupfile.

    A useful Util plugin is User, that tests if the user accessing a site has been authenticated as one of the users specified. The argument any can be given for accepting any authenticated user. More about this plugin in the Section User authentication with <if user>.


    SiteBuilder plugins requires a Roxen Platform SiteBuilder installed to work. They are adding test capabilities to web pages contained in sites administered via SiteBuilder.

    ppoint ppoint="RXML protection point" none,read,write

    The Ppoint plugin test if a user has access to a RXML protection point. The attributes none, read and write specify what permissions are required for the test to return true.


    This Section has presented the If plugins that is divided into five categories, Eval, Match, State, Utils and SiteBuilder, according to their function.

    Eval plugins evaluate expressions as in regular programming languages, Match plugins match contents with arguments given and State plugins check which of two possible conditions is met. Utils plugins perform specific tests such as present date or time. SiteBuilder plugins require a Roxen Platform SiteBuilder and add test capabilities to web pages contained in a SiteBuilder.

    More details about If plugins are found in the Web Site Creator Manual. Information about SiteBuilder is found in the Administration Manual.

    The next Section, A basic example of <if>, will show an example of a basic usage of the <Match> plugin.