Writing binding implementations

A binding implementation contains the internal representation of the binding. The bd:implementation element is the root element of a binding implementation. XSL templates contained within a binding implementation define how to transform the bound element structure into the implementation structure, i.e. into built-in markup and/or bound elements for other bindings. Transformations must be written using XSLT 2.0, but not all elements and attributes are supported. Refer to the topic entitled XSL elements for a list of the supported elements.

A binding implementation contains the internal representation of the binding. The bd:implementation element is the root element of a binding implementation. XSL templates contained within a binding implementation define how to transform the bound element structure into the implementation structure, i.e. into built-in markup and/or bound elements for other bindings. Transformations must be written using XSLT 2.0, but not all elements and attributes are supported. Refer to the topic entitled XSL elements for a list of the supported elements.

A binding transformation is not applied directly to the whole document, instead the binding processor extracts the relevant portion of the document into a smaller document to which the transformation is applied. The extracted document contains the root bound element, its descendants and place holders for the content. This prevents the transformation from modifying parts of the document outside the scope of the component and minimizes the size of the input document, i.e. improves performance.

MCS provides integration functions and templates that extend XSLT and make it usable within the binding mechanism.

Integration functions

Integration functions are split into two groups. The first group covers functions that are generally useful for integrating with MCS and are already supported in a number of other contexts.

Function Purpose
device:policy-value

Used to access the value of a specific device policy for the current target device. If no value for the specified policy can be found, an empty sequence is returned. Otherwise the value of the policy is returned. The type of the returned value is chosen based on the type of device policy.

mcs:feature

Returns a boolean value indicating if the selected feature is supported on the current device.

The second group covers functions that are provided specifically to support the binding mechanism.

Function Purpose
bd:get-component-id

Returns the value of the component-id attribute of an element. If the element is not specified or the specified element has no component-id attribute, then this function delegates to the bd:get-id function.

bd:get-id

Returns the value of the id attribute of an element. If the element is not specified or the specified element has no id attribute, then this function generates an identifier that is unique within the page. Note that if the element is not provided, then the function returns a different value each time it is called.

bd:pseudo-element

Returns an extension value that represents a pseudo-element.

Integration templates

MCS provides a number of extension templates that can be used by the author of a binding implementation. These templates are included in a transform built into MCS which imports the transform provided by the binding author and is then compiled into a single transformation that is applied to the binding.

Template Purpose
bd:bound

Moves or copies information from a bound element to a result element.

bd:component

This is a shorthand for calling the bd:bound template with the aspects parameter set to 'component'. Refer to the topic entitled bd:bound for more information.

bd:presentational

This is a shorthand for calling the bd:bound template with the aspects parameter set to 'presentational'. Refer to the topic entitled bd:bound for more information.

Copying non-bound elements

MCS provides templates that allow authors to easily copy non-bound elements from the input document to the output document using <xsl:apply-templates/>. For example, the following template encloses the contents of the cool:summary element in a div element and copies that XML fragment to the output document.

<xsl:template match="cool:summary">
  <div>
    <xsl:apply-templates/>
  <div>
</xsl:template>

Related topics