This is the mail archive of the
docbook@lists.oasis-open.org
mailing list for the DocBook project.
Re: Decorating a template call?
- From: Bob Stayton <bobs at caldera dot com>
- To: Michael Schuerig <schuerig at acm dot org>, docbook at lists dot oasis-open dot org
- Date: Thu, 02 Jan 2003 02:10:28 -0800
- Subject: Re: DOCBOOK: Decorating a template call?
- References: <200301010725.05432.schuerig@acm.org>
On Wed, Jan 01, 2003 at 07:25:05AM +0100, Michael Schuerig wrote:
>
> I wanted to be able to have a way to make an author's name into a link
> and so added a url attribute to the author element. To process this new
> attribute, I had to customize the person.name template. The real work
> is still done in a slightly changed copy of the original template. The
> only change is the new name. Works fine, but the code duplication is
> not pretty:
>
> <xsl:template name="person.name">
> <xsl:param name="node" select="."/>
> <xsl:choose>
> <xsl:when test="$node/@url">
> <a href="{$node/@url}">
> <xsl:call-template name="person.name.original">
> <xsl:with-param name="node" select="$node"/>
> </xsl:call-template>
> </a>
> </xsl:when>
> <xsl:otherwise>
> <xsl:call-template name="person.name.original">
> <xsl:with-param name="node" select="$node"/>
> </xsl:call-template>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> <xsl:template name="person.name.original">
> <!-- ...duplicated original template... -->
> </xsl:template>
>
> The duplication could be avoided if there was an indirection in the
> docbook stylesheets. But that doesn't seem right, either.
I agree that it is best to avoid duplicating a
whole template. In this case it isn't necessary.
You mention that you want this feature for author, but
the person.name template is used by several other
elements such as editor and othercredit. You can
focus on author without touching person.name.
If you want to customize author on titlepages, then
copy this template from html/titlepage.xsl to
your customization layer:
<xsl:template match="author" mode="titlepage.mode">
<div class="{name(.)}">
<h3 class="{name(.)}"><xsl:call-template name="person.name"/></h3>
<xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
<xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
</div>
</xsl:template>
Replace:
<h3 class="{name(.)}"><xsl:call-template name="person.name"/></h3>
with:
<h3 class="{name(.)}">
<xsl:choose>
<xsl:when test="@url">
> <a>
<xsl:attribute name="href">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:call-template name="person.name"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="person.name"/>
</xsl:otherwise>
</h3>
If you want to also handle author elements that are inline
then do something similar with the template that
matches "author" in html/inline.xsl.
Bob Stayton 400 Encinal Street
Publications Architect Santa Cruz, CA 95060
Technical Publications voice: (831) 427-7796
The SCO Group fax: (831) 429-1887
email: bobs@sco.com