Share via


Combining Data-Driven and Template-Driven Transformations

 

In practice, it might be most effective to combine data-driven transformations with template-driven ones. The following is an example.

<xsl:template match="/">
  <HTML>
    <HEAD>
      <TITLE><xsl:value-of select="document/title"/></TITLE>
    </HEAD>
    <BODY>
      <H1><xsl:value-of select="document/title"/></H1>
      <xsl:apply-templates select="document/section"/>
    </BODY>
  </HTML>
</xsl:template>

Here, the template rules for the top-level element are template-driven. They stipulate that, in the output, the title of the document always precedes the sections of the document — even when the order is different in the source document. The data-driven transformations apply only to the sections of the source document.

The following topic provides the complete source files and output for this example.