<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsd-to-dita="xsd-to-dita.xsd"
    
    exclude-result-prefixes="xs xsd-to-dita "
    version="2.0">
    
    <!--<xsl:variable name="xsd-to-dita:master.xsd" select="'xsd-to-dita_master.xsd'"/>-->
    <!--<xsl:output doctype-public="-//OASIS//DTD DITA Topic//EN" 
        doctype-system="topic.dtd"/>-->
    
    <xsl:template mode="xsd-to-dita:master.xsd__import" match="xs:import">
        <!--<xsl:copy>
            <xsl:copy-of select="@*"/>
            
        </xsl:copy>-->
    
        <xsl:call-template name="xsd-to-dita:xs__import"/>
    </xsl:template>
    <xsl:template name="xsd-to-dita:xs__import">
        <xsl:message >
            <xsl:value-of select="$xsd-to-dita:out__dir"/>/<xsl:value-of select="tokenize(@schemaLocation,'/')[last()]"/><xsl:value-of select="last()"/>
        </xsl:message>
        <xsl:comment>#21A import</xsl:comment>
        <topicref href="{$xsd-to-dita:out__dir}/{tokenize(@schemaLocation,'/')[last()]}.dita"/>
        <xsl:result-document 
            doctype-public="-//OASIS//DTD DITA Topic//EN" 
            doctype-system="topic.dtd" href="{$xsd-to-dita:out__dir}/{tokenize(@schemaLocation,'/')[last()]}.dita">
            
           
                        <xsl:apply-templates mode="xsd-to-dita:master.xsd__import" select="doc(@schemaLocation)">
                            <xsl:with-param name="xsd-to-dita:dita_id" select="xsd-to-dita:dita_id(@schemaLocation)" tunnel="yes"/>
                        </xsl:apply-templates>
                  
        </xsl:result-document>
        
    </xsl:template>
    
    <xsl:template mode="xsd-to-dita:master.xsd__import" match="xs:schema[xs:annotation[xs:documentation]]">
        <xsl:param name="xsd-to-dita:dita_id" required="yes" tunnel="yes"/>
        <xsl:comment>#28AM xsd-to-dita:master.xsd__import match="*" [<xsl:value-of select="name()"/>]</xsl:comment>
        <topic id="{$xsd-to-dita:dita_id}">
            <title><xsl:value-of select="xs:annotation/xs:documentation"/></title>
            
            <body>
                <p>
                    <xsl:apply-templates mode="xsd-to-dita:master.xsd__import" />
                </p>
            </body>
            
        </topic>
    </xsl:template>
    
    <!--<xsl:variable name="xsd-to-dita:master.xsd__import__schemaLocation"/>-->
    
    
</xsl:stylesheet>