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] Change class attribute for titles based on value

On Wed, May 28, 2003 at 10:12:13PM -0700, David Pratt wrote:
> I want to change the value of the class attribute for sect2 titles 
> based on the value of the title
> so that I have finer control over CSS (style same level headers 
> differently).
> I have located the following templates in the titlepage.templates.xsl 
> in the xhtml directory.  I am chunking my output
> and using version 1.61.0.  sect2.titlepage.recto holds the output value 
> that is currently being displayed (including the numbering it appears 
> that I have turned on)
> So I am having difficulty with what to compare.  For example I want to 
> compare the title value against terms like summary, introduction etc.
> so that the resulting div tag will be <div 
> xmlns="http://www.w3.org/1999/xhtml" class="summary"> when title value 
> equals summary,  <div xmlns="http://www.w3.org/1999/xhtml" 
> class="introduction">  when title value equals introduction, and so on. 
>   It is a bit complicated with the modes as well to determine
> what to do.  Help appreciated.

The string matching capabilities of XSLT 1.0 are pretty
limited.  No regular expressions, not even case-
insensitive matching.  But maybe your titles are
easy to match using the contains() function.

It might be easier to customize the 'section.heading'
template in html/sections.xsl.  That's where the
<h* class="title"> elements are generated.

<!-- HTML H level is one higher than section level -->
<xsl:variable name="hlevel" select="$level + 1"/>
<xsl:element name="h{$hlevel}">
   <xsl:attribute name="class">title</xsl:attribute>

Make that last line conditional using a choose statement.
The 'when' test would use contains() to find one
of your special headings.  Since the current
context is the section element, you can use
string(title) to get the content of the section's
<title> element to compare.

Another approach:
The stylesheets have a feature that let you control
the HTML class attribute for a few elements.
It would require more markup in your documents, but would
not require any stylesheet customization.

If you set the parameter named 'phrase.propagates.style'
to 1, then any role attribute value on a DocBook phrase
element will be passed through as the class attribute in
the HTML <span> element generated for that phrase.

Then if you write your title like this:

  <title><phrase role="foo">My title</phrase></title>

then you will get your title wrapped in:

<h2 class="title"><span class="foo">My title</span></h2>

The nice thing about this approach is that you can
have a base h2.title CSS style, and just add the
differences in the .foo style, since it will inherit
the rest.  But it does require more markup.


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] | [List Home]