<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<!-- <xsl:output Method="book" doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN" doctype-system="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/> -->

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:template match="b"><emphasis><xsl:value-of select="."/></emphasis></xsl:template>

<xsl:template match="tt">
<literal>
<xsl:apply-templates/>
</literal>
</xsl:template>

<xsl:template match="ol"><orderedlist>
<xsl:apply-templates/>
</orderedlist></xsl:template>

<xsl:template match="ul">
<itemizedlist>
<xsl:apply-templates/>
</itemizedlist>
</xsl:template>

<xsl:template match="li"><listitem><para><xsl:apply-templates/></para></listitem>
</xsl:template>

<xsl:template match="p"><para><xsl:apply-templates/></para></xsl:template>

<xsl:template match="tr">
  <row>
    <xsl:apply-templates/>
  </row>
</xsl:template>
<xsl:template match="td">
  <entry>
    <xsl:apply-templates/>
  </entry>
</xsl:template>

<xsl:template match="table">
  <xsl:if test="count(tr) != 0">
  <informaltable><tgroup cols="2"><tbody>
  <xsl:apply-templates/>
  </tbody></tgroup></informaltable>
  </xsl:if>
</xsl:template>

<xsl:template match="pre">
<para>
<programlisting>
<xsl:apply-templates/>
</programlisting>
</para>
</xsl:template>

<xsl:template match="ref[@type = 'method']">
  <link>
    <xsl:attribute name="linkend"><xsl:value-of select="@target"/></xsl:attribute>
    <xsl:value-of select="."/>
  </link>
</xsl:template>

<xsl:template match="ref[@type = 'class']">
  <link>
    <xsl:attribute name="linkend">class-<xsl:value-of select="@target"/></xsl:attribute>
    <xsl:value-of select="."/>
  </link>
</xsl:template>

<xsl:template match="ref[@type = 'unknown']">
  <ulink>
    <xsl:attribute name="url"><xsl:value-of select="@target"/></xsl:attribute>
    <xsl:value-of select="."/>
  </ulink>
</xsl:template>

<xsl:template match="parents">
  <xsl:if test="count(ref) > 0">
  <para><emphasis role="bold">Derived from</emphasis></para>
  <para>
  <simplelist>
  <xsl:for-each select="ref">
    <member>
    <xsl:apply-templates select="."/>
    </member>
  </xsl:for-each>
  </simplelist>
  </para>
  </xsl:if>
</xsl:template>

<xsl:template match="friends">
  <xsl:if test="count(ref) > 0">
  <para><emphasis role="bold">Friends</emphasis></para>
  <para>
  <xsl:for-each select="ref">
    <xsl:apply-templates select="."/>
  </xsl:for-each>
  </para>
  </xsl:if>
</xsl:template>

<xsl:template match="header">
  <xsl:text>&lt;</xsl:text>
  <xsl:value-of select="@name"/>
  <xsl:text>&gt;

  </xsl:text>
</xsl:template>

<xsl:template match="@platforms">
  <xsl:value-of select="."/><xsl:text> only.</xsl:text>
</xsl:template>

<xsl:template match="style">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem><para>
      <xsl:value-of select="."/>
      <xsl:apply-templates select="@platforms"/>
    </para></listitem>
  </varlistentry>
</xsl:template>

<xsl:template match="windowstyles">
  <xsl:if test="count(style) != 0">
  <para><emphasis role="bold">Window styles</emphasis></para>

  <variablelist>
    <xsl:apply-templates/>
  </variablelist>

  <para>
See also \helpref{window styles overview}{windowstyles}. TODO make this a proper link
  </para>
  </xsl:if>
</xsl:template>

<xsl:template match="event">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem><para>
      <xsl:value-of select="."/>
      <xsl:apply-templates select="@platforms"/>
    </para></listitem>
  </varlistentry>
</xsl:template>

<xsl:template match="events">
  <xsl:if test="count(event) != 0">
  <para><emphasis role="bold">Event handling</emphasis></para>

  <variablelist>
    <xsl:apply-templates/>
  </variablelist>
  
  </xsl:if>
</xsl:template>

<xsl:template match="predefs">
  <para><emphasis role="bold">Predefs</emphasis></para>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="structs">
  <para><emphasis role="bold">Structs</emphasis></para>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="category">
  <para><emphasis role="bold">Category</emphasis></para>
  <para>
  <xsl:apply-templates/>
  </para>
</xsl:template>

<xsl:template match="includes">
  <para><emphasis role="bold">Include Files</emphasis></para>
  <para>
  <xsl:apply-templates/>
  </para>
</xsl:template>

<xsl:template match="override">
  <para><emphasis role="bold">Override</emphasis></para>
  <para>
  <xsl:value-of select="."/>
  </para>
</xsl:template>

<xsl:template match="types">
  <para><emphasis role="bold">Types</emphasis></para>
  <para>
  <xsl:value-of select="."/>
  </para>
</xsl:template>

<xsl:template match="iterators">
  <para><emphasis role="bold">Iterators</emphasis></para>
  <para>
  <xsl:value-of select="."/>
  </para>
</xsl:template>

<xsl:template match="note">
  <para><emphasis role="bold">Note</emphasis></para>
  <para>
  <xsl:value-of select="."/>
  </para>
</xsl:template>

<xsl:template match="remarks">
  <para><emphasis role="bold">Remark</emphasis></para>
  <para>
  <xsl:value-of select="."/>
  </para>
</xsl:template>

<xsl:template match="parameter">
  <xsl:text>
\docparam{</xsl:text>
  <xsl:value-of select="@name"/>}{<xsl:apply-templates/>}
</xsl:template>

<xsl:template match="parameters">
  <xsl:if test="count(parameters/parameter) != 0">
  <para><emphasis role="bold">Parameters</emphasis></para>
  <para>
  <xsl:apply-templates/>
  </para>
  </xsl:if>
  <xsl:if test="count(parameters/parameter) = 0">
  </xsl:if>
</xsl:template>

<xsl:template match="function">
  <para>
  <emphasis role="bold">
    <xsl:value-of select="@type"/><xsl:text> </xsl:text>
    <xsl:value-of select="@name"/>
  </emphasis>
  <xsl:text> (</xsl:text>
  <xsl:for-each select="parameters/parameter">
    <emphasis role="bold"><xsl:value-of select="@type"/></emphasis>
    <xsl:text> </xsl:text>
    <xsl:value-of select="@name"/>
    <xsl:if test="@value != ''">
      <xsl:text> = </xsl:text><xsl:value-of select="@value"/>
    </xsl:if>
    <xsl:if test="position() != last()">, </xsl:if>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
  </para>
  <xsl:apply-templates select="description"/>
  <xsl:apply-templates select="parameters"/>
  <xsl:apply-templates select="fseealso"/>
</xsl:template>

<xsl:template match="member">
  <anchor><xsl:attribute name="id">method-<xsl:value-of select="@class"/><xsl:text>::</xsl:text><xsl:value-of select="@name"/></xsl:attribute></anchor>
  <para><emphasis role="bold">
    <xsl:value-of select="@class"/>
    <xsl:text>::</xsl:text>
    <xsl:value-of select="@name"/>
  </emphasis></para>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="constants">
  <para><emphasis role="bold">Constants</emphasis></para>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="members">
  <para><emphasis role="bold">Members</emphasis></para>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="fseealso">
  <para><emphasis role="bold">See also</emphasis></para>
  <para>
  <xsl:apply-templates/>
  </para>
</xsl:template>

<xsl:template match="seealso">
  <para><emphasis role="bold">See also</emphasis></para>
  <para>
  <xsl:apply-templates/>
  </para>
</xsl:template>

  <!--<xsl:call-template name="LaTeXChar">
    <xsl:with-param name="inputstring" select="."/>
  </xsl:call-template>-->

<xsl:template match="description">
  <xsl:apply-templates/>
</xsl:template>

<xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'" />

<xsl:template match="class">
  <section>
  <xsl:attribute name="id">class-<xsl:value-of select="@name"/></xsl:attribute>
  <title><xsl:value-of select="@name"/></title>

  <xsl:apply-templates select="description"/>
  <xsl:apply-templates select="example"/>
  <!--<xsl:apply-templates select="category"/>-->
  <xsl:apply-templates select="parents"/>
  <xsl:apply-templates select="friends"/>
  <xsl:apply-templates select="includes"/>
  <!--<xsl:apply-templates select="library"/>-->
  <xsl:apply-templates select="windowstyles"/>
  <xsl:apply-templates select="events"/>
  <xsl:apply-templates select="constants"/>
  <xsl:apply-templates select="predefs"/>
  <xsl:apply-templates select="structs"/>
  <xsl:apply-templates select="types"/>
  <xsl:apply-templates select="iterators"/>
  <xsl:apply-templates select="override"/>
  <xsl:apply-templates select="remarks"/>
  <xsl:apply-templates select="note"/>
  <xsl:apply-templates select="seealso"/>
  <xsl:apply-templates select="members"/>
  </section>
</xsl:template>

<xsl:template match="classes">
  <chapter><title>Alphabetical Class Reference</title>
  <para>
    This is the Alphabetical Class Reference: <link linkend="class-wxString">wxString</link> That was a link. 
  </para>

  <para><itemizedlist>
  <xsl:for-each select="class">
    <listitem><para>
      <link>
        <xsl:attribute name="linkend">class-<xsl:value-of select="@name"/></xsl:attribute>
	<xsl:value-of select="@name"/>
      </link>
    </para></listitem>
  </xsl:for-each>
  </itemizedlist></para>
  <!-- here come the class pages themselves -->
  <xsl:apply-templates select="class"/>

  </chapter>

  <!-- alphabetical class reference -->
  <!--
  <xsl:document href="output/classes.tex" method="text">
    <xsl:text>
\chapter{Alphabetical class reference}\label{classref}
\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
\setfooter{\thepage}{}{}{}{}{\thepage}%

% NB: the files should be in alphabetic order of the classes documented in
%     them and *not* in alphabetic order of the file names!

This file was generated from the XML version of the wxWidgets documentation.

</xsl:text>
  </xsl:document>
  -->
</xsl:template>

<xsl:template name="nonewlines">
  <xsl:param name="inputstring"/>
   <xsl:choose>
   <xsl:when test='contains($inputstring, "\n")'>
     <xsl:value-of select='substring-before($inputstring, "\n")'/>
     <xsl:call-template name="nonewlines">
       <xsl:with-param name="inputstring"
         select='substring-after($inputstring, "\n")'/>
     </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$inputstring"/>
   </xsl:otherwise>
   </xsl:choose> 
</xsl:template>


<!-- Not used anymore - strange characters are
  now weeded out with perl in merge.sh -->
<xsl:template name="LaTeXChar">
  <xsl:param name="inputstring"/>
   <xsl:choose>
   <xsl:when test='contains($inputstring, "_")'>
     <xsl:value-of select='substring-before($inputstring, "_")'/>
     <xsl:text>\_</xsl:text>
     <xsl:call-template name="LaTeXChar">
       <xsl:with-param name="inputstring"
         select='substring-after($inputstring, "_")'/>
     </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$inputstring"/>
   </xsl:otherwise>
   </xsl:choose> 
</xsl:template>

</xsl:stylesheet>

