<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!--
// // See license.txt for license information. // // schema_tree.xsl // // NOTES // Schema used to output a tree of objects as an html file. // prefix - the prefix to use for all the files. // indexpath - full path to the index page. // // 7-Oct-2004 phamilton Created //
-->

<xsl:stylesheet xmlns:db="http://docbook.org/ns/docbook" xmlns:str="http://exslt.org/strings" xmlns:lit="urn:xmlliterate.schema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="str" version="1.0">
    <xsl:include href="common/get_node_jscript_path.xsl"/>
    <xsl:include href="common/object_name.xsl"/>
    <xsl:output method="xml" indent="yes"/>
    <xsl:param name="date"/>
    <xsl:param name="prefix"/>
    <xsl:param name="schemapath"/>
    <xsl:param name="indexpath"/>
<!--
Place any fragment objects correctly onto the node that they belong. The path passed in is the "location" of the object. If we find any we add in this object to the tree.
-->

    <xsl:template name="search_fragment">
        <xsl:param name="path"/>
        <xsl:param name="node"/>
        <xsl:choose>
            <xsl:when test="count($node/lit:fragment) > 0">
                <xsl:for-each select="$node/lit:fragment">
                    <xsl:choose>
                        <xsl:when test="$path = @location">
                            <xsl:for-each select="./*">
                                <xsl:call-template name="object">
                                    <xsl:with-param name="object" select="."/>
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise> </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
                <xsl:for-each select="$node/lit:derived/*">
                    <xsl:call-template name="search_fragment">
                        <xsl:with-param name="path" select="$path"/>
                        <xsl:with-param name="node" select="."/>
                    </xsl:call-template>
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
<!--
Process a single object for the tree.
-->

    <xsl:template name="object">
        <xsl:param name="object"/>
        <db:simplelist>
            <db:member>
                <db:ulink>
                    <xsl:attribute name="url">
                        <xsl:value-of select="$prefix"/>
                        <xsl:value-of select="$object/@name"/>
                        <xsl:text>.html</xsl:text>
                    </xsl:attribute>
                    <xsl:call-template name="object_name">
                        <xsl:with-param name="name" select="$object/@name"/>
                    </xsl:call-template>
                </db:ulink>
<!--
place any derived objects.
-->

                <xsl:if test="count($object/lit:derived/*) > 0">
                    <xsl:for-each select="$object/lit:derived/*">
                        <xsl:call-template name="object">
                            <xsl:with-param name="object" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>
                </xsl:if>
                <xsl:choose>
                    <xsl:when test="name($object/..) = 'fragment'">
<!--
parent is a fragment. search for fragments under this one.
-->

                        <xsl:variable name="path">
                            <xsl:value-of select="substring($object/../@location, 1, string-length($object/../@location)-1)"/>
                            <xsl:text>'</xsl:text>
                            <xsl:value-of select="$object/@name"/>
                            <xsl:text>').derived()</xsl:text>
                        </xsl:variable>
<!--
place any fragments that belong under this location onto the path
-->

                        <xsl:call-template name="search_fragment">
                            <xsl:with-param name="path" select="$path"/>
                            <xsl:with-param name="node" select="/lit:object"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
<!--
calculate this objects path.
-->

                        <xsl:variable name="path">
                            <xsl:call-template name="get_node_jscript_path">
                                <xsl:with-param name="node" select="$object"/>
                                <xsl:with-param name="nodename" select="$object/@name"/>
                                <xsl:with-param name="path" select="''"/>
                                <xsl:with-param name="append" select="'.derived()'"/>
                            </xsl:call-template>
                        </xsl:variable>
<!--
place any fragments that belong under this location onto the path
-->

                        <xsl:call-template name="search_fragment">
                            <xsl:with-param name="path" select="$path"/>
                            <xsl:with-param name="node" select="/lit:object"/>
                        </xsl:call-template>
                    </xsl:otherwise>
                </xsl:choose>
            </db:member>
        </db:simplelist>
    </xsl:template>
    <xsl:template match="/">
        <xsl:comment>
Woven from             <xsl:value-of select="$schemapath"/>
through schema_tree.xsl on             <xsl:value-of select="$date"/>
. Edit at your own risk!         </xsl:comment>
        <db:book>
            <db:bookinfo>
                <db:title>
                    <xsl:text>Schema for </xsl:text>
                    <xsl:for-each select="str:tokenize($schemapath, '/')">
                        <xsl:if test="position() < last()-1">
                            <xsl:if test="position() > 1">
                                <xsl:text>/</xsl:text>
                            </xsl:if>
                            <xsl:value-of select="."/>
                        </xsl:if>
                    </xsl:for-each>
                </db:title>
            </db:bookinfo>
            <db:chapter>
                <db:para>This page contains a tree representation of all objects in this schema. Each object is a child of the object that is higher in the tree.</db:para>
                <db:para>
                    <db:ulink>
                        <xsl:attribute name="url">
                            <xsl:value-of select="$indexpath"/>
                            <xsl:text>index.html</xsl:text>
                        </xsl:attribute>
                        <xsl:text>Click here</xsl:text>
                    </db:ulink>
to return to the main index page.                 </db:para>
                <db:para>Click on a link below to view a description of that object in the heirarchy.</db:para>
                <db:para>
                    <xsl:call-template name="object">
                        <xsl:with-param name="object" select="lit:object[@name='@root']"/>
                    </xsl:call-template>
                </db:para>
            </db:chapter>
        </db:book>
    </xsl:template>
</xsl:stylesheet>