Difficulty: ★☆☆ (easy)
Keywords: sectX, section, sectX to section

Problem

You need to transform every sectX element into a section element.

Solution

This problem is solved through the following XSLT stylesheet:

Example 3.10. Transforms every sectX Element into a section Element
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:d="http://docbook.org/ns/docbook"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="copy.xsl"/>
  
  <xsl:template match="d:sect1|d:sect2|d:sect3|d:sect4|d:sect5">
    <xsl:element name="section" namespace="http://docbook.org/ns/docbook">
      <xsl:apply-templates select="node()"/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Discussion

The stylesheet from Example 3.10, “Transforms every sectX Element into a section Element” is very easy: it imports the standard rules to copy every node from copy.xsl and create special rules for all sectX elements. As every sectX element creates the same structure, we can collect it in one template rule.


Project@GitHubIssue#8