Blame xslt/texi/sectioning.xsl

Packit e4b6da
Packit e4b6da
Packit e4b6da
-->
Packit e4b6da
Packit e4b6da
Packit e4b6da
                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
Packit e4b6da
                xmlns="http://docbook2x.sourceforge.net/xmlns/Texi-XML"
Packit e4b6da
                exclude-result-prefixes="doc"
Packit e4b6da
                version='1.0'
Packit e4b6da
                xml:lang="en">
Packit e4b6da
Packit e4b6da
Packit e4b6da
     $Id: sectioning.xsl,v 1.12 2004/08/22 22:46:07 stevecheng Exp $
Packit e4b6da
     ********************************************************************
Packit e4b6da
Packit e4b6da
     (C) 2000-2004 Steve Cheng <stevecheng@users.sourceforge.net>
Packit e4b6da
Packit e4b6da
     This file is part of the docbook2X XSLT stylesheets for
Packit e4b6da
     converting DocBook to Texinfo.
Packit e4b6da
Packit e4b6da
     See ../../COPYING for the copyright status of this software.
Packit e4b6da
Packit e4b6da
     ******************************************************************** -->
Packit e4b6da
Packit e4b6da
<doc:reference xmlns="">
Packit e4b6da
<title>Mapping of DocBook sections into Texinfo sections</title>
Packit e4b6da
</doc:reference>
Packit e4b6da
Packit e4b6da
Packit e4b6da
Packit e4b6da
<doc:template name="get-texinfo-section-level" xmlns="">
Packit e4b6da
  <refpurpose>
Packit e4b6da
    Give Texinfo structuring command for given section level
Packit e4b6da
  </refpurpose>
Packit e4b6da
  
Packit e4b6da
  <refdescription>
Packit e4b6da
    <para>
Packit e4b6da
      This template returns the name of the Texinfo command that is mapped to
Packit e4b6da
      the given DocBook element.
Packit e4b6da
    </para>
Packit e4b6da
Packit e4b6da
    <para>
Packit e4b6da
      This implementation internally uses numbers that reflect the DocBook
Packit e4b6da
      hierarchy, like Norm's <function>section.level</function> template.
Packit e4b6da
      However, <function>section.level</function> only maps the DocBook 
Packit e4b6da
      sectioning elements (<sgmltag class="element">sect<replaceable>n</replaceable></sgmltag>
Packit e4b6da
      and <sgmltag class="element">section</sgmltag>).
Packit e4b6da
    </para>
Packit e4b6da
Packit e4b6da
    <para>
Packit e4b6da
      This simplistic mapping of numbers to Texinfo commands sometimes yield
Packit e4b6da
      results that do not make a lot of sense; e.g. if the document element is
Packit e4b6da
      <sgmltag class="element">section</sgmltag>, then the first section is
Packit e4b6da
      mapped to <markup>@top</markup>, but the next nested section would be a
Packit e4b6da
      Texinfo <markup>chapter</markup>.  I have thought about letting each
Packit e4b6da
      template specify their own structuring element, but from my testing,
Packit e4b6da
      jumping around the hierarchy breaks at least the TeX portion of Texinfo.
Packit e4b6da
      Besides, this neccessitated writing a <sgmltag>xsl:choose</sgmltag>s
Packit e4b6da
      with non-trivial cases in many templates.
Packit e4b6da
    </para>
Packit e4b6da
    
Packit e4b6da
    <para>
Packit e4b6da
      The only thing I can say is that if you use 'weird' document elements,
Packit e4b6da
      you can't reasonably transform to Texinfo (whose top level is
Packit e4b6da
      semantically similar to <sgmltag>book</sgmltag>).  
Packit e4b6da
      <command>docbook2texixml</command> takes the same approach.
Packit e4b6da
    </para>
Packit e4b6da
Packit e4b6da
    <para>
Packit e4b6da
      I also have a suspicion that calling this template will be slow, but 
Packit e4b6da
      there's nothing we can do about it :-(
Packit e4b6da
    </para>
Packit e4b6da
  </refdescription>
Packit e4b6da
Packit e4b6da
  <refparameter>
Packit e4b6da
    <variablelist>
Packit e4b6da
      <varlistentry>
Packit e4b6da
        <term><parameter>node</parameter></term>
Packit e4b6da
        <listitem><para>
Packit e4b6da
          The node to get the Texinfo structuring command mapping for.
Packit e4b6da
          Default is the context node.
Packit e4b6da
        </para></listitem>
Packit e4b6da
      </varlistentry>
Packit e4b6da
Packit e4b6da
      <varlistentry>
Packit e4b6da
        <term><parameter>heading-class</parameter></term>
Packit e4b6da
        <listitem><para>
Packit e4b6da
          The class of heading commands to use:
Packit e4b6da
          <simplelist type="inline">
Packit e4b6da
            <member><literal>chapter</literal></member>
Packit e4b6da
            <member><literal>unnumbered</literal></member>
Packit e4b6da
            <member><literal>appendix</literal></member>
Packit e4b6da
            <member><literal>chapheading</literal></member>
Packit e4b6da
          </simplelist>
Packit e4b6da
    
Packit e4b6da
          See the chart in the Texinfo manual for the meanings of each class.
Packit e4b6da
          The default is <literal>chapter</literal>
Packit e4b6da
        </para></listitem>
Packit e4b6da
      </varlistentry>
Packit e4b6da
    </variablelist>
Packit e4b6da
  </refparameter>
Packit e4b6da
</doc:template>
Packit e4b6da
Packit e4b6da
<xsl:template name="get-texinfo-section-level">
Packit e4b6da
  <xsl:param name="node" select="." />
Packit e4b6da
  <xsl:param name="heading-class" select="'chapter'" />
Packit e4b6da
Packit e4b6da
  <xsl:variable name="count">
Packit e4b6da
    
Packit e4b6da
         are children of part should be at the same level as
Packit e4b6da
         components that are not enclosed in a part. -->
Packit e4b6da
    <xsl:choose>
Packit e4b6da
      <xsl:when test="self::part">
Packit e4b6da
        <xsl:value-of select="count($node/ancestor::*)" />
Packit e4b6da
      </xsl:when>
Packit e4b6da
      <xsl:when test="/part">
Packit e4b6da
        
Packit e4b6da
        
Packit e4b6da
          select="count($node/ancestor::*)" />
Packit e4b6da
      </xsl:when>
Packit e4b6da
      <xsl:otherwise>
Packit e4b6da
        
Packit e4b6da
          select="count($node/ancestor::*[not(self::set | self::part)])" />
Packit e4b6da
      </xsl:otherwise>
Packit e4b6da
    </xsl:choose>
Packit e4b6da
  </xsl:variable>
Packit e4b6da
  
Packit e4b6da
  <xsl:choose>
Packit e4b6da
    <xsl:when test="$heading-class = 'chapter'">
Packit e4b6da
      <xsl:choose>
Packit e4b6da
        <xsl:when test="$count = 0">top</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 1">chapter</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 2">section</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 3">subsection</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 4">subsubsection</xsl:when>
Packit e4b6da
        
Packit e4b6da
        <xsl:otherwise><xsl:text>subsubheading</xsl:text>
Packit e4b6da
          <xsl:call-template name="user-message">
Packit e4b6da
            <xsl:with-param name="key">section is too deep</xsl:with-param>
Packit e4b6da
          </xsl:call-template>
Packit e4b6da
        </xsl:otherwise>
Packit e4b6da
      </xsl:choose>
Packit e4b6da
    </xsl:when>
Packit e4b6da
    <xsl:when test="$heading-class = 'unnumbered'">
Packit e4b6da
      <xsl:choose>
Packit e4b6da
        <xsl:when test="$count = 0">top</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 1">unnumbered</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 2">unnumberedsec</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 3">unnumberedsubsec</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 4">unnumberedsubsubsec</xsl:when>
Packit e4b6da
        <xsl:otherwise><xsl:text>subsubheading</xsl:text>
Packit e4b6da
          <xsl:call-template name="user-message">
Packit e4b6da
            <xsl:with-param name="key">section is too deep</xsl:with-param>
Packit e4b6da
          </xsl:call-template>
Packit e4b6da
        </xsl:otherwise>
Packit e4b6da
      </xsl:choose>
Packit e4b6da
    </xsl:when>
Packit e4b6da
    <xsl:when test="$heading-class = 'appendix'">
Packit e4b6da
      <xsl:choose>
Packit e4b6da
        <xsl:when test="$count = 0">top</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 1">appendix</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 2">appendixsec</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 3">appendixsubsec</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 4">appendixsubsubsec</xsl:when>
Packit e4b6da
        <xsl:otherwise><xsl:text>subsubheading</xsl:text>
Packit e4b6da
          <xsl:call-template name="user-message">
Packit e4b6da
            <xsl:with-param name="key">section is too deep</xsl:with-param>
Packit e4b6da
          </xsl:call-template>
Packit e4b6da
        </xsl:otherwise>
Packit e4b6da
      </xsl:choose>
Packit e4b6da
    </xsl:when>
Packit e4b6da
    <xsl:when test="$heading-class = 'chapheading'">
Packit e4b6da
      <xsl:choose>
Packit e4b6da
        <xsl:when test="$count = 0">majorheading</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 1">chapheading</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 2">heading</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 3">subheading</xsl:when>
Packit e4b6da
        <xsl:when test="$count = 4">subsubheading</xsl:when>
Packit e4b6da
        <xsl:otherwise><xsl:text>subsubheading</xsl:text>
Packit e4b6da
          <xsl:call-template name="user-message">
Packit e4b6da
            <xsl:with-param name="key">section is too deep</xsl:with-param>
Packit e4b6da
          </xsl:call-template>
Packit e4b6da
        </xsl:otherwise>
Packit e4b6da
      </xsl:choose>
Packit e4b6da
    </xsl:when>
Packit e4b6da
  </xsl:choose>
Packit e4b6da
</xsl:template>
Packit e4b6da
Packit e4b6da
Packit e4b6da
Packit e4b6da
Packit e4b6da
<doc:template name="make-texinfo-section" xmlns="">
Packit e4b6da
  <refpurpose>Make Texinfo section</refpurpose>
Packit e4b6da
  <refdescription>
Packit e4b6da
    <para>
Packit e4b6da
      This template outputs the corresponding Texinfo sectioning
Packit e4b6da
      command for the DocBook sectioning elements.
Packit e4b6da
    </para>
Packit e4b6da
Packit e4b6da
    <para>
Packit e4b6da
      Logically speaking, this template might better be
Packit e4b6da
      called <function role="xsl-template">make-texinfo-heading</function>,
Packit e4b6da
      as it only output the Texinfo sectioning command, but not
Packit e4b6da
      the actual content of the section.
Packit e4b6da
    </para>
Packit e4b6da
  </refdescription>
Packit e4b6da
Packit e4b6da
  <refparameter>
Packit e4b6da
    <variablelist>
Packit e4b6da
      <varlistentry>
Packit e4b6da
        <term><parameter>level</parameter></term>
Packit e4b6da
        <listitem><para>
Packit e4b6da
          The name of the Texinfo structuring command.  If not specified,
Packit e4b6da
          automatically uses <function>get-texinfo-section-level</function>.
Packit e4b6da
        </para></listitem>
Packit e4b6da
      </varlistentry>
Packit e4b6da
      <varlistentry>
Packit e4b6da
        <term><parameter>title</parameter></term>
Packit e4b6da
        <listitem><para>
Packit e4b6da
        The title to use for the section.  The default is found by applying
Packit e4b6da
        <function>title</function> mode templates to the context node.
Packit e4b6da
        </para></listitem>
Packit e4b6da
      </varlistentry>
Packit e4b6da
    </variablelist>
Packit e4b6da
  </refparameter>
Packit e4b6da
</doc:template>
Packit e4b6da
Packit e4b6da
<xsl:template name="make-texinfo-section">
Packit e4b6da
  <xsl:param name="level">
Packit e4b6da
    <xsl:call-template name="get-texinfo-section-level" />
Packit e4b6da
  </xsl:param>
Packit e4b6da
  <xsl:param name="title">
Packit e4b6da
    <xsl:apply-templates select="." mode="for-title" />
Packit e4b6da
  </xsl:param>
Packit e4b6da
 
Packit e4b6da
  
Packit e4b6da
               namespace="http://docbook2x.sourceforge.net/xmlns/Texi-XML">
Packit e4b6da
    <xsl:copy-of select="$title" />
Packit e4b6da
  </xsl:element>
Packit e4b6da
 
Packit e4b6da
</xsl:template>
Packit e4b6da
Packit e4b6da
Packit e4b6da
Packit e4b6da
<doc:template name="section" xmlns="">
Packit e4b6da
  <refpurpose>Standard template for section structures</refpurpose>
Packit e4b6da
  <refdescription>
Packit e4b6da
    <para>
Packit e4b6da
      For the given element, it creates a node for it if is.node=1, otherwise
Packit e4b6da
      an anchor, and calls <function>make-texinfo-section</function> for the actual
Packit e4b6da
      sectioning command.  Finally templates are applied for the child
Packit e4b6da
      elements.
Packit e4b6da
    </para>
Packit e4b6da
Packit e4b6da
    <para>
Packit e4b6da
      With this, the user can easily decide what elements are to be converted
Packit e4b6da
      to nodes with a simple change to <filename>texinode.xsl</filename>.
Packit e4b6da
    </para>
Packit e4b6da
  
Packit e4b6da
   </refdescription>
Packit e4b6da
Packit e4b6da
  <refparameter>
Packit e4b6da
    <para>
Packit e4b6da
      The arguments are the same as the ones for
Packit e4b6da
      <function>make-texinfo-section</function>, plus
Packit e4b6da
      <parameter>content</parameter>.
Packit e4b6da
    </para>
Packit e4b6da
Packit e4b6da
    <variablelist>
Packit e4b6da
      <varlistentry>
Packit e4b6da
        <term><parameter>content</parameter></term>
Packit e4b6da
        <listitem><para>
Packit e4b6da
          The result tree fragment of the section.  Defaults to applying
Packit e4b6da
          templates.
Packit e4b6da
        </para></listitem>
Packit e4b6da
      </varlistentry>
Packit e4b6da
    </variablelist>
Packit e4b6da
  </refparameter>
Packit e4b6da
</doc:template>
Packit e4b6da
Packit e4b6da
<xsl:template name="section">
Packit e4b6da
  <xsl:param name="level">
Packit e4b6da
    <xsl:call-template name="get-texinfo-section-level" />
Packit e4b6da
  </xsl:param>
Packit e4b6da
  <xsl:param name="title">
Packit e4b6da
    <xsl:apply-templates select="." mode="for-title" />
Packit e4b6da
  </xsl:param>
Packit e4b6da
  <xsl:param name="content">
Packit e4b6da
    <xsl:apply-templates />
Packit e4b6da
  </xsl:param>
Packit e4b6da
  
Packit e4b6da
  <xsl:variable name="is-node">
Packit e4b6da
    <xsl:apply-templates select="." mode="is-texinfo-node" />
Packit e4b6da
  </xsl:variable>
Packit e4b6da
Packit e4b6da
  <xsl:choose>
Packit e4b6da
    <xsl:when test="$is-node = '1'">
Packit e4b6da
      <xsl:call-template name="make-texinfo-node" />
Packit e4b6da
    </xsl:when>
Packit e4b6da
    <xsl:otherwise>
Packit e4b6da
      <xsl:call-template name="anchor" />
Packit e4b6da
    </xsl:otherwise>
Packit e4b6da
  </xsl:choose>
Packit e4b6da
  
Packit e4b6da
  
Packit e4b6da
  <xsl:if test="@lang|@xml:lang">
Packit e4b6da
    <documentlanguage>
Packit e4b6da
      <xsl:attribute name="lang">
Packit e4b6da
        <xsl:value-of select="(@lang|@xml:lang)[last()]" />
Packit e4b6da
      </xsl:attribute>
Packit e4b6da
    </documentlanguage>
Packit e4b6da
  </xsl:if>
Packit e4b6da
Packit e4b6da
  <xsl:call-template name="make-texinfo-section">
Packit e4b6da
    <xsl:with-param name="level" select="$level" />
Packit e4b6da
    <xsl:with-param name="title" select="$title" />
Packit e4b6da
  </xsl:call-template>
Packit e4b6da
Packit e4b6da
  <xsl:copy-of select="$content" />
Packit e4b6da
Packit e4b6da
  <xsl:if test="@lang|@xml:lang">
Packit e4b6da
    
Packit e4b6da
    <documentlanguage />
Packit e4b6da
  </xsl:if>
Packit e4b6da
</xsl:template>
Packit e4b6da
Packit e4b6da
</xsl:stylesheet>
Packit e4b6da