Hi David,

thanks a lot for this example. I took your input and created some
alternative approach:

        <xsl:template match="*...@role='highlight']" priority="10">
                <xsl:variable name="count">
                        <xsl:value-of 
select="count(ancestor::node()[...@role='highlight'])"/>
                </xsl:variable>
                <fo:block>
                        <xsl:attribute name="background-color">
                                <xsl:choose>
                                        <!-- first level -->
                                        <xsl:when test="$count = 
0">blue</xsl:when>
                                        <!-- second level -->
                                        <xsl:when test="$count = 
1">green</xsl:when>
                                        <!-- third level -->
                                        <xsl:when test="$count = 
2">purple</xsl:when>
                                        <xsl:otherwise>orange</xsl:otherwise>
                                </xsl:choose>
                        </xsl:attribute>
                        <xsl:apply-imports />
                </fo:block>
        </xsl:template>

I will test both approaches (yours and mine) with complex nestings of
elements with the role=highlight attribute. What do you think about?

Cheers, Tobias

On Sun, Mar 8, 2009 at 10:40 PM, David Cramer <[email protected]> wrote:
> To avoid needing to customize tons of templates, I do the following for
> that situation. This allows us to add role="highlight" to any element
> and have it be highlighted yellow. This needs to be in a customization
> layer that imports the docbook xsls because it relies on doing an
> xsl:apply-imports:
>
> For html (assuming you have something like .remark{ background: yellow;
> } in your css):
>
> <xsl:template match="text()[ ancestor::*/@role = 'highlight' ] | xref[
> ancestor::*/@role = 'highlight' ]" priority="10"><span
> class="remark"><xsl:apply-imports/></span></xsl:template>
>
> And for fo:
>
>  <xsl:template match="text()[ ancestor::*/@role = 'highlight' ] | xref[
> ancestor::*/@role = 'highlight' ]" priority="10">
>        <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format";
> background-color="yellow"><xsl:apply-imports/></fo:inline>
>  </xsl:template>
>
> David
>
>> -----Original Message-----
>> From: Tobias Anstett [k15t.com] [mailto:[email protected]]
>> Sent: Saturday, March 07, 2009 2:57 PM
>> To: [email protected]
>> Subject: [docbook] Highlighting complete areas in DocBook
>>
>> Hi together,
>>
>> is there a way to highlight docbook elements in a generic
>> way? I'd like to be able to put some extra attribute or pi to
>> any docbook element to highlight it e.g. set the background
>> color of a para (resulting fo:block) to red for PDF output. I
>> already had a look at the change highlighting documented at
>> http://www.sagehill.net/docbookxsl/Changebars.html, but
>> because i am using Apache FOP i need some other mechanism to
>> highlight docbook elements (and it childs) ranging from para,
>> admonition, programmlistings, table, etc. to table.
>>
>> Cheers, Tobias
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to