[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]
Subject: Re: DOCBOOK: Decorating a template call?
On Thursday 02 January 2003 11:10, Bob Stayton wrote: > 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. I wasn't clear about that, I want this (at least) for editors, too. > If you want to customize author on titlepages, No, I've extended the docbook-website stylesheets with a bookreview element where I'm using author, editor, and authorgroup. (See http://www.schuerig.de/michael/about.hmlt). Here's a longish excerpt: <xsl:template match="bookreview"> <div class="bookreview"> <xsl:call-template name="anchor"/> <div class="head"> <xsl:call-template name="title"/> <xsl:call-template name="subtitle"/> <xsl:call-template name="authorgroup"/> <xsl:call-template name="author"/> <xsl:call-template name="publisher"/> <xsl:call-template name="year"/> </div> <div class="body"> <xsl:apply-templates select="*|text()" mode="bookreview.body"/> </div> </div> </xsl:template> <xsl:template name="author"> <div class="authors"> <xsl:choose> <xsl:when test="author"> <xsl:call-template name="person.name"> <xsl:with-param name="node" select="author"/> </xsl:call-template> </xsl:when> <xsl:when test="editor"> <xsl:text>Edited by </xsl:text> <xsl:call-template name="person.name"> <xsl:with-param name="node" select="editor"/> </xsl:call-template> </xsl:when> </xsl:choose> </div> </xsl:template> <xsl:template match="author" mode="bookreview.body"> </xsl:template> <xsl:template name="authorgroup"> <div class="authors"> <xsl:choose> <xsl:when test="authorgroup/author"> <xsl:call-template name="person.name.list"> <xsl:with-param name="person.list" select="authorgroup/author"/> </xsl:call-template> </xsl:when> <xsl:when test="authorgroup/editor"> <xsl:text>Edited by </xsl:text> <xsl:call-template name="person.name.list"> <xsl:with-param name="person.list" select="authorgroup/editor"/> </xsl:call-template> </xsl:when> </xsl:choose> </div> </xsl:template> <xsl:template match="authorgroup" mode="bookreview.body"> </xsl:template> I'm using call-template because that way I can determine the ordering of elements in the output independent of their ordering in the input. (Yes, I know that verbatim text doesn't belong in the stylesheet. I'll have to use substiture-markup and gentext.template or something.) > 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. Yes, this would work for single author elements, but I don't see how to make it work for authorgroups. Thanks for your suggestions, so far. Michael -- Michael Schuerig If at first you don't succeed... mailto:schuerig@acm.org try, try again. http://www.schuerig.de/michael/ --Jerome Morrow, "Gattaca"
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]
Powered by eList eXpress LLC