OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] refentry section headings



>>For example, if a refentry appears inside a sect1,
>>then its NAME title should be format as section
>>level 2, and any refsect1 should format as section
>>level 3, etc.  Does that sound right?

I had a go at fixing the section.level template in common/common.xsl
so that when invoked on a refentry section/sect[12345] or
refsynopsisdiv, it will include the depth of the containing section.
I've attached (as common.sectionlevel.xsl) my replacement for
section.level but I haven't tested it much. It works fine for the
document that I've been writing but I've probably missed some
cases. I'm sure it can be made much more compact but I'm not really
familiar enough with XSLT syntax.

The changes are picked up automatically by fo/refentry.xsl but
xhtml/refentry.xsl merely sets the sectn headings to <h{n+1}> and
doesn't use section.level. So I've attached (as xhtml.refentry.xsl)
some templates that I've been using in my customisation layer to use
the new section.level template.

Pointings-out of any potential pitfalls appreciated.

Brian McGurk

<xsl:template name="section.level">
  <xsl:param name="node" select="."/>
  <xsl:choose>
    <xsl:when test="name($node)='sect1'">1</xsl:when>
    <xsl:when test="name($node)='sect2'">2</xsl:when>
    <xsl:when test="name($node)='sect3'">3</xsl:when>
    <xsl:when test="name($node)='sect4'">4</xsl:when>
    <xsl:when test="name($node)='sect5'">5</xsl:when>
    <xsl:when test="name($node)='section'">
      <xsl:choose>
        <xsl:when test="$node/../../../../../../section">6</xsl:when>
        <xsl:when test="$node/../../../../../section">5</xsl:when>
        <xsl:when test="$node/../../../../section">4</xsl:when>
        <xsl:when test="$node/../../../section">3</xsl:when>
        <xsl:when test="$node/../../section">2</xsl:when>
        <xsl:otherwise>1</xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:when test="ancestor::refentry">
      <xsl:call-template name="refentry.section.level">
	<xsl:with-param name="node" select="$node"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="name($node)='simplesect'">
      <xsl:choose>
        <xsl:when test="$node/../../sect1">2</xsl:when>
        <xsl:when test="$node/../../sect2">3</xsl:when>
        <xsl:when test="$node/../../sect3">4</xsl:when>
        <xsl:when test="$node/../../sect4">5</xsl:when>
        <xsl:when test="$node/../../sect5">5</xsl:when>
        <xsl:when test="$node/../../section">
          <xsl:choose>
            <xsl:when test="$node/../../../../../section">5</xsl:when>
            <xsl:when test="$node/../../../../section">4</xsl:when>
            <xsl:when test="$node/../../../section">3</xsl:when>
            <xsl:otherwise>2</xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>1</xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>1</xsl:otherwise>
  </xsl:choose>
</xsl:template><!-- section.level -->

<!-- Finds the total section depth of a section in a refentry -->
<xsl:template name="refentry.section.level">
  <xsl:param name="node" select="."/>

  <xsl:variable name="RElevel">
    <xsl:call-template name="refentry.level">
      <xsl:with-param name="node" select="$node"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="levelinRE">
    <xsl:choose>
      <xsl:when test="name($node)='refsynopsisdiv'">1</xsl:when>
      <xsl:when test="name($node)='refsect1'">1</xsl:when>
      <xsl:when test="name($node)='refsect2'">2</xsl:when>
      <xsl:when test="name($node)='refsect3'">3</xsl:when>
      <xsl:when test="name($node)='refsection'">
        <xsl:choose>
          <xsl:when test="$node/../../../../../refsection">5</xsl:when>
          <xsl:when test="$node/../../../../refsection">4</xsl:when>
          <xsl:when test="$node/../../../refsection">3</xsl:when>
          <xsl:when test="$node/../../refsection">2</xsl:when>
          <xsl:otherwise>1</xsl:otherwise>
        </xsl:choose>
      </xsl:when>
    </xsl:choose>
  </xsl:variable>

  <xsl:value-of select="$levelinRE + $RElevel"/>
</xsl:template>

<!-- Finds the section depth of a refentry -->
<xsl:template name="refentry.level">
  <xsl:param name="node" select="."/>
  <xsl:choose>
    <xsl:when test="ancestor::section">
      <xsl:call-template name="section.level">
          <xsl:with-param name="node" select="ancestor::section"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:when test="ancestor::sect5">
      <xsl:call-template name="section.level">
        <xsl:with-param name="node" select="ancestor::sect5"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="ancestor::sect4">
      <xsl:call-template name="section.level">
        <xsl:with-param name="node" select="ancestor::sect4"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="ancestor::sect3">
      <xsl:call-template name="section.level">
        <xsl:with-param name="node" select="ancestor::sect3"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="ancestor::sect2">
      <xsl:call-template name="section.level">
        <xsl:with-param name="node" select="ancestor::sect2"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="ancestor::sect1">
      <xsl:call-template name="section.level">
        <xsl:with-param name="node" select="ancestor::sect1"/>
      </xsl:call-template>
    </xsl:when>
    <otherwise>
      0
    </otherwise>
  </xsl:choose>
</xsl:template>
<!-- Format the title of refsection/refsect? type elements -->
<xsl:template match="refsect1/title|refsect2/title|refsect3/title|
		     refsect4/title|refsect5/title|refsection/title">
  <xsl:variable name="hlevel">
    <xsl:call-template name="section.hlevel">
      <xsl:with-param name="node" select="parent::*"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml";>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

<!-- Format the title of refsynopsisdiv -->
<xsl:template match="refsynopsisdiv">
  <div class="{name(.)}">
    <xsl:call-template name="anchor"/>

    <xsl:variable name="title">
      <xsl:choose>
        <xsl:when test="refsynopsisdiv/title|title">
          <xsl:apply-templates select="(refsynopsisdiv/title|title)[1]" mode="titlepage.mode"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="gentext">
            <xsl:with-param name="key" select="'RefSynopsisDiv'"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="hlevel">
      <xsl:call-template name="section.hlevel">
	<xsl:with-param name="node" select="."/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml";>
      <xsl:value-of select="$title"/>
    </xsl:element>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<!-- map the current section depth to the corr. hlevel -->
<xsl:template name="section.hlevel">
  <xsl:param name="node" select="."/>
  <xsl:variable name="level">
    <xsl:call-template name="section.level">
      <xsl:with-param name="node" select="$node"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$level &gt; 5">6</xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$level+1"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]