[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]
Subject: Re: DOCBOOK: Decorating a template call?
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
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]
Powered by eList eXpress LLC