When I apply the next XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="book">
<body>
<xsl:apply-templates select="node()" />
</body>
</xsl:template>
<xsl:template match="*[contains(local-name(), 'section')]">
<div>
<xsl:apply-templates select="node()" />
</div>
</xsl:template>
<xsl:template match="name">
<xsl:element name="h{count(ancestor::*[contains(local-name(), 'section')])}">
<xsl:value-of select="concat(parent::*/@id, ' ', .)" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
To the provided input XML
<?xml version="1.0" encoding="UTF-8"?>
<book>
<section id="1">
<name>Heading First chapter</name>
<p>
<i/> some text </p>
<p> other text </p>
<subsection id="1.1">
<name>Heading second chapter</name>
<subsubsection id="1.1.1">
<name>Heading third chapter</name>
<p>some text</p>
</subsubsection>
</subsection>
</section>
</book>
It produces:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<div>
<h1>1 Heading First chapter</h1>
<p>
<i/> some text </p>
<p> other text </p>
<div>
<h2>1.1 Heading second chapter</h2>
<div>
<h3>1.1.1 Heading third chapter</h3>
<p>some text</p>
</div>
</div>
</div>
</body>