<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml"
                              xmlns:html="http://www.w3.org/1999/xhtml"
                              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              exclude-result-prefixes="html xsl"
>
  <xsl:namespace-alias stylesheet-prefix="html" result-prefix="#default" />

  <xsl:output method="html" version="1.0" encoding="utf-8" indent="yes" />

  <xsl:template match="/">
    <html>
      <xsl:apply-templates mode="head" />
      <xsl:apply-templates />
    </html>
  </xsl:template>

  <xsl:template match="topic" mode="head">
    <head>
      <xsl:apply-templates mode="head" />
    </head>
  </xsl:template>

  <xsl:template match="title" mode="head">
    <title>
      <xsl:value-of select="./text()" />
    </title>
  </xsl:template>

  <xsl:template match="text()" mode="head">
    <!-- Ignore it -->
  </xsl:template>

  <xsl:template match="topic">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="body">
    <body>
      <h2><xsl:value-of select="preceding-sibling::title/text()" /></h2>

      <xsl:apply-templates />
    </body>
  </xsl:template>

  <xsl:template match="p">
    <div>
      <xsl:value-of select="./text()" />
    </div>
  </xsl:template>

  <xsl:template match="text()">
    <!-- Ignore -->
  </xsl:template>
</xsl:stylesheet>
