It is often necessary to enable or disable parts of a style sheet, or make them dependent on run-time parameters. While it's possible to solve the problem using several different style sheets, it is much easier to put everything into one style sheet and select different features at run-time using conditional compilation controlled by parameters set by the application.

You can select any part of a style sheet (that is, any balanced XML) using

<if exp="expression"> ... </if>

If the expression's value is non-zero the section is compiled, otherwise it is ignored. The operators 'and', 'or', 'lt', 'le', 'eq' or '==', 'ge', 'gt', '+', '-' (unary and binary), '!', '*' and '/' are supported, as are most other C++ operators, and also bracketed sub-expressions using ( ... ). Operator precedence follows C++. (The operators &&, ||, <, <=, >= and > are also legal but cannot easily be used because of conflicts with XML syntax.) The variable 'scale' is built-in. Other variables can be set using CMap::SetStyleSheetVariable.

There is a full explanation of the expression syntax here.

Example:

in the app code:

<condition exp='@feature_type == "primary road"'>
   <line fill='khaki'/>
   <if exp="HIGHLIGHTING and scale lt 25000">
   <highlight fill='green' width='70%,1' opacity='50%' distance='-40%'/>
   </if>
</condition