<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rf="http://schemas.roadintranet.org/road-faq-1">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <xsl:text>&#xa;</xsl:text>
        <xsl:processing-instruction name="xml-stylesheet">
            <xsl:text>type="text/xsl" href="../xsl/topic-map.xsl"</xsl:text>
        </xsl:processing-instruction>
        <xsl:text>&#xa;</xsl:text>
        <rf:content>
            <xsl:for-each select="/rf:content/rf:topic">
                <xsl:if test="contains(@file,'.xml' ) ">
                    <xsl:variable name="topic-file" select="@file"/>
                    <xsl:variable name="topic" select="document(concat('../xml/', @file))"/>
                    <xsl:text>&#xa;</xsl:text>
                    <xsl:for-each select="$topic/rf:topic">
                        <xsl:copy>
                            <xsl:copy-of select="@*"/>
                            <xsl:text>&#xa;</xsl:text>
                            <xsl:for-each select="$topic/rf:topic/rf:section">
                                <xsl:copy>
                                    <xsl:copy-of select="@*"/>
                                    <xsl:attribute name="file">
                                        <xsl:value-of select="$topic-file"/>
                                    </xsl:attribute>
                                    <xsl:text>&#xa;</xsl:text>
                                    <xsl:for-each select="./rf:item">
                                        <xsl:copy>
                                            <xsl:copy-of select="@*"/>
                                            <xsl:attribute name="file">
                                                <xsl:value-of select="$topic-file"/>
                                            </xsl:attribute>
                                        </xsl:copy>
                                    </xsl:for-each>
                                </xsl:copy>
                            </xsl:for-each>
                        </xsl:copy>
                    </xsl:for-each>
                </xsl:if>
            </xsl:for-each>
        </rf:content>
    </xsl:template>
</xsl:stylesheet>
