この XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<div>
<div class="contents">
<ul>
<xsl:apply-templates select="chapter" mode="contents" />
</ul>
</div>
<xsl:apply-templates select="chapter" />
</div>
</xsl:template>
<xsl:template match="chapter" mode="contents">
<li>
<a href="#{@id}">
<xsl:value-of select="title" />
</a>
</li>
</xsl:template>
<xsl:template match="chapter">
<div class="chapter" id="{@id}">
<xsl:apply-templates select="*" />
</div>
</xsl:template>
<xsl:template match="chapter/title" />
</xsl:stylesheet>
この入力に適用すると:
<chapters>
<chapter id="1">
<title>Chapter 1</title>
<p>text</p>
</chapter>
<chapter id="2">
<title>Chapter 2</title>
<p>text</p>
</chapter>
</chapters>
生成されます:
<div>
<div class="contents">
<ul>
<li>
<a href="#1">Chapter 1</a>
</li>
<li>
<a href="#2">Chapter 2</a>
</li>
</ul>
</div>
<div class="chapter" id="1">
<p>text</p>
</div>
<div class="chapter" id="2">
<p>text</p>
</div>
</div>
あなたの XSLT を見せていただければ (2,410 の評判ポイントがあればそれは明らかだと思います)、あなたが間違っていることを教えてくれます。