<?xml version="1.0" ?>
<!-- by Brian Lalonde
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 License. 
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ 
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="yes" indent="no"
  media-type="text/xml" doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN"
  doctype-system="file:/C:/Program Files/XXE/dtd/docbook/docbookx.dtd" />

<xsl:param name="filename" select="//registration/@progid" />
<xsl:param name="wsf.synop.title" select="'Usage'" />
<xsl:param name="wsf.arg.required" select="'Required. '" />
<xsl:param name="wsf.arg.optional" select="'Optional. '" />
<xsl:param name="wsf.arg.string" select="''" />
<xsl:param name="wsf.arg.boolean" select="'Boolean. '" />
<xsl:param name="wsf.arg.simple" select="''" />

<!-- WSC Section -->
<xsl:template match="component">
  <refentry>
    <refnamediv>
      <refname><xsl:value-of select="registration/@progid" /></refname>
      <refpurpose><xsl:value-of select="registration/@description" /></refpurpose>
    </refnamediv>
    <xsl:apply-templates select="public" />
    <refsect1><title>Examples</title>
      <example><title>VBScript ASP</title><programlisting
        >Set x= Server.CreateObject(&quot;<xsl:value-of select="registration/@progid" 
        />&quot;)</programlisting></example>
      <example><title>JScript WSH</title><programlisting
        >var x= WScript.CreateObject(&apos;<xsl:value-of select="registration/@progid" 
        />&apos;);</programlisting></example>
      <example><title>PerlScript HTA</title><programlisting
        >use Win32::OLE;&#10;my $x= Win32::OLE->new(&apos;<xsl:value-of select="registration/@progid" 
        />&apos;);</programlisting></example>
    </refsect1>
    <refsect1><title>Setup</title>
      <procedure>
        <step><simpara>Download <ulink url="http://webcoder.info/downloads/{$filename}">
          <filename><xsl:value-of select="$filename" /></filename></ulink>
          to the web server (somewhere permanent, like a system directory).</simpara>
        </step>
        <step>
          <simpara><mousebutton>Right-click</mousebutton> the file and choose
          <guimenuitem>Register</guimenuitem>.</simpara>
        </step>
      </procedure>
    </refsect1>
  </refentry>
</xsl:template>

<xsl:template match="public">
  <refsect1><title>Methods and Properties</title>
    <variablelist><xsl:apply-templates /></variablelist>
  </refsect1>
</xsl:template>

<xsl:template match="property">
	<varlistentry><term><varname><xsl:value-of select="@name" /></varname></term>
    <listitem><simpara><xsl:value-of select="comment" /></simpara></listitem>
  </varlistentry>
</xsl:template>

<xsl:template match="method">
	<varlistentry><term><methodname><xsl:value-of select="@name" /></methodname>
    <xsl:text>(</xsl:text><xsl:apply-templates select="parameter" /><xsl:text>)</xsl:text></term>
    <listitem><simpara><xsl:value-of select="comment" /></simpara></listitem>
  </varlistentry>
</xsl:template>

<xsl:template match="parameter">
  <xsl:if test="preceding-sibling::parameter"><xsl:text>,</xsl:text></xsl:if>
	<parameter class="function"><xsl:value-of select="@name" /></parameter>
</xsl:template>

<!-- WSF Section -->
<xsl:template match="package">
  <refentry>
    <refnamediv>
      <refname><xsl:value-of select="$filename" /></refname>
      <refpurpose><xsl:value-of select="job[1]/runtime/description" /></refpurpose>
    </refnamediv>
    <refsynopsisdiv><title><xsl:value-of select="$wsf.synop.title" /></title>
      <xsl:apply-templates mode="synopsis" />
    </refsynopsisdiv>
    <xsl:apply-templates />
    <refsect1><title>Setup</title>
      <procedure>
        <step><simpara>Download <ulink url="http://webcoder.info/downloads/{$filename}">
          <filename><xsl:value-of select="$filename" /></filename></ulink>
          to somewhere permanent on your workstation.</simpara>
        </step>
      </procedure>
    </refsect1>
  </refentry>
</xsl:template>

<xsl:template match="job">
  <xsl:apply-templates select="runtime" />
</xsl:template>

<xsl:template match="runtime">
  <refsect1><title><xsl:value-of select="parent::job/@id" /> Job</title>
    <xsl:apply-templates select="description" />
    <refsect2><title>Parameters</title>
      <xsl:choose>
        <xsl:when test="named|unnamed">
          <variablelist>
          <xsl:for-each select="named">
            <varlistentry><term><option><xsl:value-of select="@name" /></option></term>
              <listitem><simpara>
                <xsl:choose>
                  <xsl:when test="@required='true'"><xsl:value-of select="$wsf.arg.required" /></xsl:when>
                  <xsl:otherwise><xsl:value-of select="$wsf.arg.optional" /></xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@type='string'"><xsl:value-of select="$wsf.arg.string" /></xsl:when>
                  <xsl:when test="@type='boolean'"><xsl:value-of select="$wsf.arg.boolean" /></xsl:when>
                  <xsl:otherwise><xsl:value-of select="$wsf.arg.simple" /></xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="@helpstring" />
              </simpara></listitem>
            </varlistentry>
          </xsl:for-each>
          <xsl:for-each select="unnamed">
            <varlistentry><term><option><xsl:value-of select="@name" /></option></term>
              <listitem><simpara>
                <xsl:choose>
                  <xsl:when test="@required!='false'">
                    <xsl:if test="@required!='true'">
                      <xsl:value-of select="@required" /><xsl:text> </xsl:text>
                    </xsl:if>
                    <xsl:value-of select="$wsf.arg.required" />
                  </xsl:when>
                  <xsl:otherwise><xsl:value-of select="$wsf.arg.optional" /></xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="@helpstring" />
              </simpara></listitem>
            </varlistentry>
          </xsl:for-each>
          </variablelist>
        </xsl:when>
        <xsl:otherwise><simpara>No parameters.</simpara></xsl:otherwise>
      </xsl:choose>
    </refsect2>
    <refsect2><title>Examples</title>
      <xsl:apply-templates select="example" />
    </refsect2>
  </refsect1>
</xsl:template>

<xsl:template match="description">
  <simpara><xsl:value-of select="." /></simpara>
</xsl:template>

<xsl:template match="example">
  <simpara><xsl:value-of select="." /></simpara>
</xsl:template>

<xsl:template match="job" mode="synopsis">
	<cmdsynopsis><command><xsl:value-of select="$filename" /></command>
    <xsl:choose>
    	<xsl:when test="not(preceding-sibling::job)"><arg choice="opt">//Job:<xsl:value-of select="@id" /></arg></xsl:when>
    	<xsl:otherwise><arg choice="plain">//Job:<xsl:value-of select="@id" /></arg></xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates select="runtime/named|runtime/unnamed" mode="synopsis" />
  </cmdsynopsis>
</xsl:template>

<xsl:template match="named" mode="synopsis">
  <xsl:element name="arg">
    <xsl:if test="@required='true'"><xsl:attribute name="choice">plain</xsl:attribute></xsl:if>
    <xsl:choose>
      <xsl:when test="@type='string'"><option>/<xsl:value-of select="@name" 
        /></option>:<replaceable class="parameter">value</replaceable></xsl:when>
      <xsl:when test="@type='boolean'"><option>/<xsl:value-of select="@name" /></option>[+|-]</xsl:when>
      <xsl:otherwise><option>/<xsl:value-of select="@name" /></option></xsl:otherwise>
    </xsl:choose>
  </xsl:element>
</xsl:template>

<xsl:template match="unnamed" mode="synopsis">
  <xsl:element name="arg">
    <xsl:attribute name="rep">repeat</xsl:attribute>
    <xsl:if test="@required='true'"><xsl:attribute name="choice">plain</xsl:attribute></xsl:if>
    <replaceable><xsl:value-of select="@name" /></replaceable>
  </xsl:element>
</xsl:template>
</xsl:stylesheet>
