# Executing the Transformation

To actually perform the transformation, you need to perform one or more actions.

## Selecting XML source data

This step is optional, but if you omit it, then you must name the initial template.

Create an `XM_XSLT_URI_SOURCE`, passing it the SYSTEM id of your XML text data, as an absolute URI. (If your data source is not XML text, then you will have to create some other descendant of `XM_XSLT_SOURCE`).

## Naming the initial mode

Normally the transformation will start executing in the default mode. If you wish to start the transformation in some other mode, then pass the name of that mode (as an expanded QName, that is, an optional namespace-URI enclosed in curly braces, followed by a local name with no intervening space) to `set_initial_mode`.

## Naming the initial template

If you supply XML source data to the transformation, then the initial template will normally be found by matching on the initial context item, that is, the document element of the source data, using the initial mode.

If you do not supply any XML source data, or if you wish to override the normal choice for an initial template, then pass the name of that template (as an expanded QName, that is, an optional namespace-URI enclosed in curly braces, followed by a local name with no intervening space) to `set_initial_template`.

## Setting Global Parameters

If your stylesheet has any top-level <xsl:param>s, then you may well wish to set values for them (if any of the parameters are required, then this step is mandatory).

There are two features provided to set the value of a parameter. If, as is common, you wish to supply a string value (type xs:string), then you can call `set_string_parameter`. This takes two `STRING`s as arguments. The first is the name of the parameter, and the second is the value you wish to set.

In the general case, you may pass an XPath expression as the value for a parameter. In this case you call `set_xpath_parameter`. The arguments are the same as for `set_string_parameter`, but in this case the value is interpreted as an XPath expression, not a literal string value.

The XPath expression is parsed using the xsl:stylesheet/xsl:transform element of the principal stylesheet module for a static context (so if your XPath expression contains prefixed QNames, then the namespaces will be resolved using the bindings in scope on that element).

Hm. This means the executable stylesheet is not quite so reusable, as functions and variables might be bound. Not really a problem, I think, but better clone the static context before parsing - TODO).

The XPath expression is evaluated using a dynamic context based on the document element of the XML source data file. That means, if you do not supply any XML source data (in which case you must have selected an initial template), then you may not set any XPath-valued parameters (you may call `set_xpath_parameter`, but you will get an error when attempting to execute the transformation). This makes perfect sense, as XPath expressions are navigations around an instance of the XPath data model, and so are meaningless without one.

## Defining the output destination

You must define the destination for the output from the transformation. To do this, create an `XM_XSLT_TRANSFORMATION_RESULT`.

## Running the transformation

At this point, all that remains to be done is to call `transform`. You pass the `XM_XSLT_SOURCE` representing the XML source data as the first parameter (or `Void` if you have not supplied any), and the `XM_XSLT_TRANSFORMATION_RESULT` you defined for the output destination as the second parameter.