Using template within xsl:result-document

Okay, at the moment I have a very simple script, which transforms my xml into html, one page for each chapter, and also creates an index. I now want to start improving the design of the pages but have one major problem. The code below shows the two <xsl:result-document> tags that create the two different types of file. I want to create a template so that all of my files will have the same style. As you can see below both <xsl:result-document> tags contain the same HTML tags. How could I change this so that both use a template which would basically contain the <html><head></head><body></body></html> tags and then I would be wanting to just create different content within the <body>. I believe I will need to do some conditional formatting to make this happen, as I only want one index page whereas I want one page for each chapter, plus to make the contents within the <body> tag different. I have been looking at the different elements I can use, such as xsl:if, xsl:para and xsl:call-template but can’t yet work out how to do it.

If anyone has some experience with this and can offer some help I will be extremely grateful!!!

Here’s the code at the moment:

    <xsl:template match="/">
        <xsl:apply-templates select="//chapter"/>
        <xsl:result-document href="new/index.php" format="html">
            <html>
                <head>
                    <title>
                        <xsl:value-of select="book/info/title"/>
                    </title>
                </head>
                <body>
                    <xsl:for-each select="//chapter">
                        <a href="{abbrev}.php"><xsl:value-of select="title" />
                        </a><br/>
                    </xsl:for-each>
                </body>
            </html>
        </xsl:result-document>
    </xsl:template>
    
    <xsl:template match="//chapter">
        <xsl:variable name="filename" select="concat('new/',abbrev,'.php')" />
        <xsl:value-of select="$filename" />
        <xsl:result-document href="{$filename}" format="html">
            <html>
                <head>
                    <title>Test results - <xsl:value-of select="title"/></title>
                </head>
                <body>
                    <xsl:value-of select="title"/>                 
                    <xsl:apply-templates select="section"/>                
                </body>
            </html>
        </xsl:result-document>
    </xsl:template>

Thanks!
Russ