Writing Specialization-Aware XSLT

When developing XSLT for DITA content, it's important to take specialization into account.

Specialization in DITA is implemented using the special format of the @class attribute. When writing a template, the @match attribute should not use a tag name.

<!-- DO NOT match on DITA element name! -->
<xsl:template match="note"><!-- bad practice -->

Instead, match on the @class attribute.

<!-- This is OK, but verbose. It will match on "note" elements and all specializations therefrom -->
<xsl:template match="*[contains(@class, ' topic/note ')]">

Titania Delivery provides a utility entity file that contains entity declarations for all of the base DITA elements mapping to the @class-qualified form, in a way that is easier to read. This allows the above to be rewritten as:

<xsl:template match="&note;"/>

For every element in the base DITA vocabulary, the entity file referenced above contains entries similar to the following:

<!ENTITY note-condition "contains(@class, ' topic/note ')">
<!ENTITY note "*[&note-condition;]">

To use these entities, link in the entity file using the public ID -//Titania//ENTITIES DITA XPath Definitions//EN.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY % tags PUBLIC "-//Titania//ENTITIES DITA XPath Definitions//EN" "dita-xpaths.ent">
%tags;
]>
<xsl:stylesheet version = "2.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" >
  <xsl:import href= "urn:titania:dita-xsl:topic-html-fragment.xsl" />
  <xsl:template match="&note;" mode="html #default">
    <!-- Custom note handling -->
  </xsl:template>
</xsl:stylesheet>