#188 Copy DocBook's role attribute as class attr on HTML

output: HTML
open
nobody
XSL (399)
7
2005-02-09
2004-02-15
No

It'd be nice if the HTML (and XHTML) stylesheets would
copy the docbook 'role' attribute as an HTML class
attribute, to allow efficient styling via CSS. I
implimented this change for the section elements in my
organization's own copy of the stylesheets and it meets
my org's needs quite nicely, although now it's become
quite a pain this change into each new release of the
stylesheet. The code I added to sections.xsl was of
the form:

<xsl:template match="section">
<xsl:variable name="depth"
select="count(ancestor::section)+1"/>
<xsl:element name="div">
<xsl:attribute name="class">
<xsl:value-of select="name(.)"/>
+ <xsl:if test="string-length(@role) &gt; 0">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@role"/>
+ </xsl:if>
</xsl:attribute>

I did this for the sect1, sect2, sect3, sect4, sect5,
and section elements. I imagine similar checks could be
added for other elements having a 'role' attribute, but
for my needs, adding this feature to the sections was
sufficient.

Discussion

  • Michael(tm) Smith

    • priority: 5 --> 3
     
  • Michael(tm) Smith

    Logged In: YES
    user_id=118135

    the class atribute on some HTML elements is actually
    generated from the DocBook element name, so we can't
    have the stylesheets automatically generate class values
    based on role in all cases.

    sounds like mainly you want to do it for section and sect*

     
  • William McVey

    William McVey - 2005-02-08

    Logged In: YES
    user_id=25956

    An HTML class attribute can handle multiple values though.
    For example, the code I added above basically generates an
    attribute like class="sect3 recommendation" in the
    transformed HTML, which is handled just fine in browsers.

     
  • Michael(tm) Smith

    Logged In: YES
    user_id=118135

    > An HTML class attribute can handle multiple values though.
    > For example, the code I added above basically generates an
    > attribute like class="sect3 recommendation" in the
    > transformed HTML, which is handled just fine in browsers.

    Yep. I have to admit that I didn't think you could
    still use CSS to control styling of elements that have
    multi-valued class attributes. But I just did a simple
    test and you are correct.

    So I think the feature you're requesting is definitely
    worthwhile. I will look at trying to see if I can
    implement it. If not, will try to see if one of the
    other developers can.

     
  • Michael(tm) Smith

    • priority: 3 --> 7
     

Log in to post a comment.