About Arbortext Styler > Extending Stylesheets > Extending the Edited Source Function by Adding More Complex Code > Adding Custom XSL Code
  
Adding Custom XSL Code
At times you may need to further extend the functionality of the edited source feature by introducing XSL templates containing a complete set of formatting requests, none of which can be fulfilled by existing Arbortext Styler window functionality. In this instance you must introduce the code to the Arbortext Styler window in such a way that Arbortext Styler window recognizes the code as edited source, even if the code bears no relation to any existing element in the document. To accomplish this, create a random User Formatting Element (UFE) that will hold the templates - the templates can then be referenced by other elements when their formatting is required.
The general process to create the new UFE is defined below, although a specific example is included at the end of the section for reference, including instructions on how to associate your new template with an existing element:
1. In Arbortext Styler, create a new element via the Insert > Element menu option. Give it a _ufe prefix and a self explanatory name - for example _ufe:custom-xsl-code. This prefix will ensure that Arbortext Styler creates the element as a User Formatting Element.
2. Highlight the _ufe:custom-xsl-code element in the Elements list and elect to edit its source by selecting Edit > Edit Element Source and choosing the desired XSL output.
3. Delete the contents of the edited source window.
4. Paste your custom XSL code into the empty edited source window. Save the changes to the edited source by clicking File > Apply and Close
5. Your new template now exists in your stylesheet and can be referenced by any other elements to which its formatting properties should be applied.
For example: your current doctype includes an empty fill-in-the-blank element, which contains an optional blanksize attribute whose value is an unsigned and limitless number. The presence of the blanksize attribute will output a baseline rule whose length in inches is either the value of the attribute, or 1 if the attribute does not have a value. It is not possible to format the baseline in this way in the Arbortext Styler window, although XSL-FO provides this formatting capability. In this instance, you must create a separate XSLT template named, for example, blanksize-to-leader-length, which will perform the baseline length computation. The steps are defined below:
1. In Arbortext Styler, style the fill-in-the-blank element as required, in this case it is given the Inline style
2. Using the Generated Text Editor to place generated text before the element, add a rule as a leader by selecting the Insert > Leaders, Rule or Space menu option and selecting Rule from the Type menu.
3. In the Elements list, elect to edit the source of the fill-in-the-blank element for XSL-FO via the Edit > Edit Element Source menu option.
4. In the edited source window, locate the element fo:leader. Change its content from:
<fo:leader leader-pattern="rule" rule-thickness="1.00pt"
leader-length="12.00pt" leader-pattern-width
="use-font-metrics" baseline-shift="0.00pt"/>
to:
<fo:leader leader-pattern="rule" rule-thickness="1.00pt"
leader-length="12.00pt" leader-pattern-width
="use-font-metrics" baseline-shift="0.00pt">
<xsl:attribute name="leader-length">
<xsl:call-template name="blanksize-to-leader-length">
<xsl:with-param name="blanksize" select="@blanksize"/>
</xsl:call-template>
</xsl:attribute>
</fo:leader>
Ensuring that the code is entered in tag form, not text.
Click File > Apply and Close to save the changes to the element and ensure that the custom blanksize-to-leader-length template will be called every time the length to which to set the fo:leader element's leader-length property needs to be calculated.
5. Now you must introduce the custom blanksize-to-leader-length template into the .style stylesheet. Follow the steps detailed in the outline procedure at the beginning of this section:
a. In Arbortext Styler, create a new element via the Insert > Element menu option. Give it a _ufe prefix and a self explanatory name - for example _ufe:custom-xsl-code. This prefix will ensure that Arbortext Styler creates the element as a User Formatting Element.
b. Highlight the _ufe:custom-xsl-code element in the Elements list and elect to edit its source for XSL-FO by selecting Edit > Edit Element Source and choosing XSL-FO from the list.
c. Delete the contents of the edited source window.
d. Add the following code in the edited source window, to declare the custom blanksize-to-leader-length template as the formatting option for the _ufe:custom-xsl-code element, and set up its rule length calculation mechanism:
<xsl:template name="blanksize-to-leader-length">
<xsl:param name="blanksize" select="''"/>
<xsl:choose>
<xsl:when test="$blanksize!=''">
<xsl:value-of select="$blanksize"/>
<xsl:text>in</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>1in</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
e. Click File > Apply and Close to save the changes and ensure that the fill-in-the-blank element has the desired effect when publishing for XSL-FO, i.e. producing a rule of a specified length when the blanksize attribute value is defined, or a rule of 1 inch in length when the attribute does not have a value.