set-dc action manipulates Delivery Context Properties for the
You should think twice before changing system properties in the DC — because virtually all components of FIT rely on them. That said, there may be situations where this is the right solution for your problem.
set-dc action has the following attributes:
property="..."defining the path to the property as described in the Delivery Context, in context of
xpath="..."XPath defining the value the property will be set to. It is evaluated in the context of
/dcas described in the DC document (default:
value="..."sets the property to a static value
value are mutually exclusive. If neither
attributes are defined, the property is set to true (i.e. it will be created).
In the DC document structure boolean values are expressed
by the presence or absence of a DOM element. This makes XPath expressions very
Obviously, setting boolean values with the
set-action requires you to define
a boolean value. This is only possible with the
<set-dc property="js" xpath="true()"/> <set-dc property="js" xpath="false()"/>
false() are valid XPath expression that return boolean values.
Of course you can use fancier arithmetic like
not(server/role = 'production').
It is not possible to set a boolean value with the
value attribute because
value will always set a text value . The following code will not
js element, but set its text value to the string
<set-dc property="js" value="false"/>
<if test="js"> would still be true.
We distinguish between overriding system properties and adding your own custom properties. From the system perspective, adding custom properties is safe, because no built-in behaviour depends on it.
In your project you can use them to gather decisions or settings centrally. These may be your breakpoint definitions, your theme colors and so on.
While it is not enforced, we recommend putting your custom properties into the
<set-dc property="custom/colors/main" value="green"/> <set-dc property="custom/colors/sub" value="blue"/> <set-dc property="custom/api-call" xpath="request/ajax and fit-document('fit://request/request')/*/query[@name = 'ver' and @value='2']"/>
We also recommend running
set-dc actions as early as possible in your
flow. This makes the use of your properties consistent throughout
the request. In the example above, you may use
custom/colors/main as a
replacement in your CSS and
custom/api-call in an
XSLT to change the output format. Your fellow
developers will recognize the
custom/ convention as a non-standard
information local to your project or organization.
You are not limited to set your properties to a value determined by an XPath.
You can make use of the flow control structures
to prepare alternative values by choosing between multiple
<!-- sets custom/tablesize depending on viewport width --> <choose> <when test="viewport/width > 1200"> <set-dc property="custom/tablesize" value="huge" /> </when> <when test="viewport/width > 700"> <set-dc property="custom/tablesize" value="medium" /> </when> <otherwise> <set-dc property="custom/tablesize" value="small" /> </otherwise> </choose>