Writing XSLT for Non-DITA XML
Non-DITA content is processed and decorated with namespaced attributes describing each element's role using rules configured in the document type. This means that all non-DITA document types can be treated similarly by reading the decoration attributes instead of the element names. Additionally, non-DITA doctypes may include a basic, universal XSLT transform that should be applied in all portal themes.
Titania Delivery provides a "virtual" XSLT module, called
urn:titania:xsl:modules:decorated-html.xsl
, that can be used to style
most non-DITA XML content. This module will pull in the document type's default transform,
if
present, as well as supply default styling based on the configuration-based role attributes.
Most portal theme stylesheets for non-DITA XSLT can probably be a simple inclusion
of this
module.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:include href="urn:titania:xsl:modules:decorated-html.xsl"/> </xsl:stylesheet>
Utility Modes
This stylesheet also includes a number of template modes that can be used to easily customize certain aspects of certain elements.
html-tag
- This mode is called on every XML element to determine the HTML element in the output.
You can use this mode to customize this
behavior.
<xsl:template match="sidebar" mode="html-tag"> <xsl:text>section</xsl:text> </xsl:template>
html-attrs
- This mode will be called on all elements, and can be used to override the attributes
placed on the resulting HTML dlement for specific source XML elements. The default
implementation calculates the @class attribute and then applies this
mode to all attributes on the element, so to add a representation of a specific
attribute in the HTML output, you can simply match on that
attribute.
<!-- Customize attributes on a specific tag --> <xsl:template match="info" mode="html-attrs"> <xsl:attribute name="class">info</xsl:attribute> <xsl:attribute name="data-label" select="concat(@label, ' ', @date)"/> </xsl:template> <!-- Customize a specific attribute on a specific tag --> <xsl:template match="sidebar/@appliesTo" mode="html-attrs"> <xsl:attribute name="data-appliesTo" select="."/> </xsl:template>
class-tokens
- This mode can be used to augment the HTML @class attribute contents
for specific
elements.
<xsl:template match="graphic" mode="class-tokens"> <xsl:text>img-fluid contentGraphic</xsl:text> </xsl:template>
By default, the @class attribute contains the source element name as well as the roles described by the document type'sdoctype.xml
file for the element.
See Non-DITA XML Processing for additional details.