Call an XSL Subtemplate from the Main Template

To implement the subtemplate in the main template, make two entries in the main template.

First, import the subtemplate file to the main template. The import syntax tells the Publisher engine where to find the Sub Template in the catalog.

Second, enter a call command to render the contents of the subtemplate at the position desired.

Import the Subtemplate

Enter the import command anywhere in the main template prior to the call template command as shown here.

<?import:xdoxsl:///{path to subtemplate.xsb}?>


path to subtemplate.xsb is the path to the subtemplate .xsb object in the catalog.

For example:

<?import:xdoxsl:///Executive/Financial Reports/mySubtemplate.xsb?>

Call the Subtemplate

The template statements that you defined within the XSL subtemplate file are applied to data elements. There are 'two ways you can call a template defined in the imported XSL subtemplate.

  • By matching the data content with the match criteria:

    <xsl:apply-templates select="data_element"/>

    This method applies all the templates that are defined in the XSL subtemplate to the data_element specified. Based on the data content of data_element, appropriate functions in those templates are applied. See the following use case for a detailed example: Handle XML Data with HTML Formatting.

  • By calling a template by name:

    <xsl:call-template name="templateName"/>

    This method calls the template by name and the template executes, similar to a function call. Here also parameters can be passed to the template call, similarly to an RTF subtemplate. See Pass Parameters to an XSL Subtemplate.

    See the following use case for a detailed example: Dynamically Apply Formatting to a Portion of Data.

Pass Parameters to an XSL Subtemplate

Declare the parameter in the <xsl:template> definition.

To pass parameters to the XSL subtemplate:

  1. Declare the parameter in the <xsl:template> definition, as follows:
    <xsl:template name="templateName" match="/">
       <xsl:param name="name" />
  2. Then call this template using the following syntax:
    <xsl:call-template name="templateName">
      <xsl:with-param name="name" select="expression">
        <?--- Content:template -->