Overriding and Importing

Overriding and Importing Templates

xsl:include pastes a module in at equal precedence; xsl:import gives its rules lower import precedence, so the importing stylesheet overrides them regardless of priority, and xsl:apply-imports calls the overridden rule. A brand layer over a shared base:

base.xsl: shared rules, one with a high priorityXML
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    expand-text="yes">
  <xsl:output method="text"/>
  <xsl:template match="/catalog">
    <xsl:apply-templates select="book[position() le 2]"/>
  </xsl:template>
  <xsl:template match="book">{title} ({subject})&#10;</xsl:template>
  <xsl:template match="book[pages > 400]" priority="9">Long: {title}&#10;</xsl:template>
</xsl:stylesheet>
brand.xsl: importing base.xsl and wrapping its ruleXML
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="base.xsl"/>
  <xsl:template match="book">* <xsl:apply-imports/></xsl:template>
</xsl:stylesheet>

Running base.xsl, then brand.xsl, on the catalog:

Output of 92
The Quiet Harbor (Fiction)
Long: Patterns of the Deep Web
* The Quiet Harbor (Fiction)
* Long: Patterns of the Deep Web

Base's priority="9" rule lost to brand's plain book rule (precedence first, priority second), but inside xsl:apply-imports it competed normally, so b2 still got "Long".