<?xml version="1.0"?>
<!-- Copyright (c) 2002 Felix Rosencrantz

 Information about this tool can be found at:
     http://www.oocities.org/f_rosencrantz/xml_completion.htm
 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>

<!-- Start -->
<xsl:template match="/command">
    <xsl:processing-instruction name="DOCTYPE">
    COMPLETION SYSTEM "completion.dtd"
    </xsl:processing-instruction>
    <completion version='.02'>
    <meta>
    <filename>_<xsl:value-of select="@command"/></filename>
    <xsl:variable name="include_file">
        <xsl:choose>
        <xsl:when test="@include"><xsl:value-of select="@include"/></xsl:when>
    <xsl:otherwise><xsl:value-of select="@command"/>_defines.xml</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <includes>
        <include file="{$include_file}"/>
    </includes>
    <generation>
        <xsl:if test="generation">
            <xsl:for-each select="generation">
                <gen_command><xsl:value-of select="@command"/></gen_command>
            </xsl:for-each>
        </xsl:if>
        <gen_command>simple2long.xsl</gen_command>
    </generation>
    </meta>
       <state_prolog/>
       <services>
        <service name='{@command}'>
            <!-- lll Problem here:  What are we using arg for? -->
            <arguments>
                <xsl:for-each select="arg">
                    <argoption>
                        <name><xsl:value-of select="@name"/></name>
                    </argoption>
                </xsl:for-each>
            </arguments>
            <argspecs>
                <xsl:for-each select="flag">
                    <argspec>
                        <optspec>

                            <xsl:choose>
                                <xsl:when test="exclusion_list">
                                    <xsl:for-each select="exclusion_list">
                                        <xsl:copy-of select="."/>
                                    </xsl:for-each>
                                </xsl:when>
                                <xsl:when test="@exclusionlist">
                                    <exclusionlist>
                                        <xsl:call-template name="AddFlagList">
                                            <xsl:with-param name="IgnoreFlag"
                                                    select="@name"/>
                                            <xsl:with-param name="set"
                                                    select="@exclusionlist"/>
                                        </xsl:call-template>
                                    </exclusionlist>
                                </xsl:when>
                            </xsl:choose>
                            <xsl:if test="@same_word">
                                <xsl:if
                                   test="@same_word='true' or @same_word='yes'">
                                    <same_word must='true'/>
                                </xsl:if>
                            </xsl:if>
                            <flagarg name="{@name}">
                                <xsl:for-each select="plus_sign">
                                    <xsl:copy-of select="."/>
                                </xsl:for-each>
                        <xsl:choose>
                        <xsl:when test="@multiple">
                            <xsl:if test="@multiple='true' or @multiple='yes'">
                                <more_than_once/>
                            </xsl:if>
                        </xsl:when>
                        <xsl:when test="../@multiple">
                             <xsl:if
                             test="../@multiple = 'true' or ../@multiple='yes'">
                                <more_than_once/>
                             </xsl:if>
                        </xsl:when>
                        </xsl:choose>
                                <explanation>
                                    <xsl:value-of select="@flaghelp"/>
                                </explanation>
                            </flagarg>
                        </optspec>
                        <xsl:if test="@taghelp != '' or @argtag != '' or ./action or @fixedstrings != ''">
                            <description>
                                <message>
                                        <xsl:value-of select="@taghelp"/>
                                </message>
                                <xsl:choose>
                                    <xsl:when test="./action">
                                        <xsl:copy-of select="./action"/>
                                    </xsl:when>
                                                                        <xsl:when test="@fixedstrings">
                                                                                <action>
                                                                                        <fixed_set>
                                                                                        <xsl:call-template name="AddFixedSet">
                                                                                         <xsl:with-param name="set" select="@fixedstrings"/>
                                                                                        </xsl:call-template>
                                                                                        </fixed_set>
                                                                                </action>
                                                                        </xsl:when>
                                    <xsl:when test="@argtag">
                                        <action tag="{@argtag}">
                                        </action>
                                    </xsl:when>
                                    <xsl:otherwise/>
                                </xsl:choose>
                            </description>
                        </xsl:if>
                    </argspec>
                </xsl:for-each>
                <xsl:for-each select="arg">
                    <argspec>
                        <optspec>
                            <xsl:choose>
                                <xsl:when test="exclusion_list">
                                    <xsl:for-each select="exclusion_list">
                                        <xsl:copy-of select="."/>
                                    </xsl:for-each>
                                </xsl:when>
                                <xsl:when test="@exclusionlist">
                                    <!-- Name of position for exclusionlists -->
                                    <xsl:variable name="PosName">
                                        <xsl:choose>
                                            <xsl:when test="@position='any'">
                                                <xsl:text>*</xsl:text>
                                            </xsl:when>
                                            <xsl:otherwise>
                                              <xsl:value-of select="@position"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:variable>

                                    <exclusionlist>
                                        <xsl:call-template name="AddFlagList">
                                            <xsl:with-param name="IgnoreFlag"
                                                    select="$PosName"/>
                                            <xsl:with-param name="set"
                                                    select="@exclusionlist"/>
                                        </xsl:call-template>
                                    </exclusionlist>
                                </xsl:when>
                            </xsl:choose>
                            <xsl:variable name="ElementName">
                                <xsl:choose>
                                    <xsl:when test="@position='any'">
                                        <xsl:text>anyposition</xsl:text>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:text>position</xsl:text>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                            <xsl:element name="{$ElementName}">
                                <xsl:choose>
                                    <xsl:when test="@position='any'">
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:attribute name="position">
                                            <xsl:value-of select="@position"/>
                                        </xsl:attribute>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:element>
                        </optspec>
                        <description>
                                <message>
                                        <xsl:value-of select="@arghelp"/>
                                </message>
                                <xsl:choose>
                                    <xsl:when test="./action">
                                        <xsl:copy-of select="./action"/>
                                    </xsl:when>
                                    <xsl:when test="@fixedstrings">
                                        <action>
                                            <fixed_set>
                                                <xsl:call-template name="AddFixedSet">
                                                    <xsl:with-param name="set" select="@fixedstrings"/>
                                                </xsl:call-template>
                                            </fixed_set>
                                        </action>
                                    </xsl:when>
                                    <xsl:when test="@argtag">
                                        <action tag="{@argtag}">
                                        </action>
                                    </xsl:when>
                                    <xsl:otherwise/>
                                </xsl:choose>
                            </description>
                    </argspec>
                </xsl:for-each>
            </argspecs>
        </service>
    </services>
    <xsl:variable name="states">
        <xsl:for-each select="flag|arg">
        </xsl:for-each>
    </xsl:variable>
    <xsl:if test="$states != ''">
        <xsl:value-of select="$states"/>
    </xsl:if>
    </completion>

    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="flag">
    <!-- Do per flag stuff here -->
</xsl:template>

<xsl:template match="arg">
    <!-- Do per arg stuff here -->
</xsl:template>

<xsl:template name="AddFixedSet">
        <xsl:param name="set"/>

        <xsl:choose>
                <xsl:when test="contains($set,' ')">
                        <fixed_string><value><xsl:value-of select="substring-before($set,' ')"/></value></fixed_string>
                        <xsl:call-template name="AddFixedSet">
                                <xsl:with-param name="set" select="substring-after($set,' ')"/>
                        </xsl:call-template>
                </xsl:when>
                <xsl:when test="not($set = '')">
                        <fixed_string><value><xsl:value-of select="$set"/></value></fixed_string>
                </xsl:when>
                <xsl:otherwise/>
        </xsl:choose>
</xsl:template>

<xsl:template name="AddFlagList">
    <xsl:param name="IgnoreFlag" select="''"/>
    <xsl:param name="set"   select="''"/>

    <xsl:choose>
        <xsl:when test="contains($set,' ')">
            <xsl:variable name="flag" select="substring-before($set,' ')"/>
            <xsl:if test="not($flag = $IgnoreFlag)">
                <flag><xsl:value-of select="$flag"/></flag>
            </xsl:if>
            <xsl:call-template name="AddFlagList">
                <xsl:with-param name="IgnoreFlag" select="$IgnoreFlag"/>
                <xsl:with-param name="set" select="substring-after($set,' ')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:when test="not($set='')">
            <xsl:if test="not($set = $IgnoreFlag)">
                <flag><xsl:value-of select="$set"/></flag>
            </xsl:if>
        </xsl:when>
        <xsl:otherwise/>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c)1998-2001 eXcelon Corp.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario2" userelativepaths="yes" url="simple_editted_new.xml" htmlbaseurl="" processortype="internal" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo  srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" />
</metaInformation>
-->