<?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:template match="b"><emphasis><xsl:value-of select="."/></emphasis></xsl:template>

<xsl:template match="ol">\begin{enumerate}\itemsep=0pt
<xsl:apply-templates/>
\end{enumerate}</xsl:template>

<xsl:template match="ul">\begin{itemize}\itemsep=0pt
<xsl:apply-templates/>
\end{itemize}</xsl:template>

<xsl:template match="li">\item <xsl:apply-templates/>
</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">
<!-- TODO: make monospaced etc - 
  PROBLEM: para may not occur inside para. 
    maybe we should update classes.dtd not to allow <pre> inside <p> (and use <tt> or something instead) -->
</xsl:template>

<xsl:template match="classref">
  <link>
    <xsl:attribute name="linkend">class-<xsl:value-of select="@name"/></xsl:attribute>
    <xsl:attribute name="label"><xsl:value-of select="@name"/></xsl:attribute>
  </link>
</xsl:template>

<xsl:template match="ref">
  <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">
  <row>
  <entry>
  <xsl:value-of select="@name"/>
  </entry>
  <entry>
  <xsl:value-of select="."/>
  <xsl:apply-templates select="@platforms"/>
  </entry>
  </row>
</xsl:template>

<xsl:template match="events">
  <xsl:if test="count(event) != 0">
  <section><title>Event handling</title>
  <para>
  <informaltable><tgroup cols="2"><tbody>
  <xsl:apply-templates/>
  </tbody></tgroup></informaltable>
  </para>
  </section>
  </xsl:if>
</xsl:template>

<xsl:template match="predefs">
  <section><title>Predefs</title>
  <para>
  <xsl:apply-templates/>
  </para>
  </section>
</xsl:template>

<xsl:template match="structs">
  <section><title>Structs</title>
  <para/>
  <xsl:apply-templates/>
  </section>
</xsl:template>

<xsl:template match="category">
  <section><title>Category</title>
  <para>
  <xsl:apply-templates/>
  </para>
  </section>
</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">
  <section><title>Override</title>
  <para>
  <xsl:value-of select="."/>
  </para>
  </section>
</xsl:template>

<xsl:template match="types">
  <section><title>Types</title>
  <para>
  <xsl:value-of select="."/>
  </para>
  </section>
</xsl:template>

<xsl:template match="iterators">
  <section><title>Iterators</title>
  <para>
  <xsl:value-of select="."/>
  </para>
  </section>
</xsl:template>
<xsl:template match="note">
  <section><title>Note</title>
  <para>
  <xsl:value-of select="."/>
  </para>
  </section>
</xsl:template>

<xsl:template match="remarks">
  <section><title>Remark</title>
  <para>
  <xsl:value-of select="."/>
  </para>
  </section>
</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">
  <section><title>Parameters:</title>
  <para>
  <xsl:apply-templates/>
  </para>
  </section>
  </xsl:if>
  <xsl:if test="count(parameters/parameter) = 0">
  <para/>
  </xsl:if>
</xsl:template>

<xsl:template match="function">
  <para>
  <xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>
  <xsl:text> (</xsl:text>
  <xsl:for-each select="parameters/parameter">
    <xsl:value-of select="@type"/><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="seealso"/>
</xsl:template>

<xsl:template match="member">
  <section><title>
  <xsl:value-of select="@class"/>
  <xsl:text>::</xsl:text>
  <xsl:value-of select="@name"/>
  </title>
  <para></para>
  <xsl:apply-templates/>
  </section>
</xsl:template>

<xsl:template match="constants">
  <section><title>Constants</title>
  <para>
  <xsl:apply-templates/>
  </para>
  </section>
</xsl:template>

<xsl:template match="members">
  <section><title>Members</title>
  <para/>
  <xsl:apply-templates/>
  </section>
</xsl:template>

<xsl:template match="seealso">
  <section><title>See also</title>
  <para>
  <xsl:apply-templates/>
  </para>
  </section>
</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">
<book>
  <bookinfo>
    <title>wxWidgets 2.6.2: A portable C++ and Python GUI toolkit (DocBook docs generated from XML)</title>
    <author><firstname>Julian</firstname><surname>Smart</surname></author>
    <author><firstname>Robert</firstname><surname>Roebling</surname></author>
    <author><firstname>Vadim</firstname><surname>Zeitlin</surname></author>
    <author><firstname>Robin</firstname><surname>Dunn</surname></author>
    <author><firstname>et</firstname><surname>al</surname></author>
  </bookinfo>

  <chapter><title>Alphabetical Class Reference</title>
  <para>
    This is the Alphabetical Class Reference: <link linkend="class-wxString">wxString</link> That was a link. 
  </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:for-each select="class">
      <xsl:text>\include </xsl:text><xsl:value-of select="translate(@name,$uc,$lc)"/>
      <xsl:text>.tex
</xsl:text>
    </xsl:for-each>
  </xsl:document>
  -->
</book>
</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>

