#188 Add a preface to a section's autolabel.

output: all formats
open
nobody
XSL (122)
5
2014-08-21
2013-05-28
CNC
No

Perhaps this modification will be useful in the next release. I needed to add a preface to all of the section autolabels in my document. As an example, I'll just use the word "SECTION" as the preface.

I modified common/labels.xsl by changing this snippet:

<xsl:choose>
<xsl:when test="@label">
<xsl:value-of select="@label"/>
</xsl:when>
<xsl:when test="$label != 0">
<xsl:variable name="format">
<xsl:call-template name="autolabel.format">
<xsl:with-param name="format" select="$section.autolabel"/>
</xsl:call-template>
</xsl:variable>
<xsl:number format="{$format}" count="d:section"/>
</xsl:when>
</xsl:choose>

to this snippet:

<xsl:choose>
<xsl:when test="@label">
<xsl:value-of select="@label"/>
</xsl:when>
<xsl:when test="$label != 0">
<xsl:variable name="format">
<xsl:call-template name="autolabel.format">
<xsl:with-param name="format" select="$section.autolabel"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$section.label.preface">
<xsl:value-of select="$section.label.preface"/><xsl:value-of select="$section.label.preface.separator"/>
</xsl:if>
<xsl:number format="{$format}" count="d:section"/>
</xsl:when>
</xsl:choose>

I created a new file: params/section.label.preface.xml

<refentry xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="5.0" xml:id="webhelp.default.topic">
<refmeta>
<refentrytitle>section.label.preface</refentrytitle>
<refmiscinfo class="other" otherclass="datatype">string</refmiscinfo>
</refmeta>
<refnamediv>
<refname>section.label.preface</refname>
<refpurpose>A preface on the section autolabel</refpurpose>
</refnamediv>

<refsynopsisdiv>
<src:fragment xml:id="section.label.preface.frag">
<xsl:param name="section.label.preface">index.html</xsl:param>
</src:fragment>
</refsynopsisdiv>

<refsection><info><title>Description</title></info>
<para>The <parameter>section.label.preface</parameter> parameter lets you
add a preface to the section label. The label attribute on a section tag will override both this
preface and the autolabel.
<note>
<para>This preface will become part of the "labelnumber" of an xref cross-reference. Therefore, when defining a section preface, using the xrefstyle="select: labelnumber" attribute on section xref cross references will probably generate the most meaningful text for the cross reference label.
</para>
</note>
</para>
</refsection>
</refentry>

And I created a second new file: params/section.label.preface.separator.xml

<refentry xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="5.0" xml:id="webhelp.default.topic">
<refmeta>
<refentrytitle>section.label.preface.separator</refentrytitle>
<refmiscinfo class="other" otherclass="datatype">string</refmiscinfo>
</refmeta>
<refnamediv>
<refname>section.label.preface.separator</refname>
<refpurpose>The separator between the section preface and the section autolabel.</refpurpose>
</refnamediv>

<refsynopsisdiv>
<src:fragment xml:id="section.label.preface.separator.frag">
<xsl:param name="section.label.preface.separator">index.html</xsl:param>
</src:fragment>
</refsynopsisdiv>

<refsection><info><title>Description</title></info>
<para>The <parameter>section.label.preface.separator</parameter> parameter lets you
customize the separator text between the section preface and the section label.
<note>
<para>The default is a single blank space.
</para>
</note>
</para>
</refsection>
</refentry>

Then, I modified the html/param.xsl and fo/param.xsl files by adding:

<xsl:param name="section.label.preface"></xsl:param>
<xsl:param name="section.label.preface.separator"><xsl:text> </xsl:text></xsl:param>

Finally, in my customization file, I added:

<xsl:param name="section.label.preface">SECTION</xsl:param>

Discussion

  • CNC

    CNC - 2013-05-28

    Modified labels.xsl file

     
    Attachments
  • CNC

    CNC - 2013-05-29

    The two new params might be better named: "section.autolabel.preface" and "section.autolabel.preface.separator". The reason being that they are only prefixed to an autolabel value, and not to a section label attribute value.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks