[publican-list] Custom Header/Footer

Paul Morgan pmorgan at redhat.com
Mon Nov 23 21:03:35 UTC 2009


On Mon, Nov 23, 2009 at 03:52:12PM -0500, Josh Kayse wrote:
> I'm attempting to switch our documentation to publican at my workplace  
> and was wondering if publican supports custom headers/footers on each  
> page for PDF output or top and bottom of HTML output.  Could I use the  
> override.css for the HTML output?  We want to include something like "Our 
> Company" at the top and bottom of each page.

Here's a stylesheet I hacked together that has running footers and
headers. The stylesheet belongs in a "brand" directory, such as
/usr/share/publican/xsl/mybrand/pdf.xsl

hth,
-paul


<?xml version='1.0'?>
 
<!--
	Copyright 2009 Red Hat, Inc.
	License: GPL
	Author: Jeff Fearn <jfearn at redhat.com>
	Author: Tammy Fox <tfox at redhat.com>
	Author: Andy Fitzsimon <afitzsim at redhat.com>
	Author: Paul Morgan <pmorgan at redhat.com>
-->

<!DOCTYPE xsl:stylesheet [
<!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
<!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
 ]>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		version='1.0'
		xmlns="http://www.w3.org/TR/xhtml1/transitional"
		xmlns:fo="http://www.w3.org/1999/XSL/Format"
		exclude-result-prefixes="#default">

<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/graphics.xsl"/>
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/titlepage.templates.xsl"/>
<xsl:import href="../defaults.xsl"/>
<xsl:import href="../pdf.xsl"/>

<xsl:param name="fop1.extensions" select="1"></xsl:param>

<xsl:param name="body.font.master">8.5</xsl:param>
<xsl:param name="shade.padding">0pt</xsl:param>


<!-- name of header graphic -->
<xsl:param name="header.image.filename">/usr/share/publican/Common_Content/redhatgps/en-US/images/red_bar.jpg</xsl:param>

<!-- running header -->
<xsl:param name="header.rule" select="0"/>
<xsl:template name="header.content">
<xsl:param name="position" select="''"/>
<xsl:choose>
  <xsl:when test="$position='left'">
    <fo:block-container
    absolute-position="absolute"
    left="-1in"
    >
    <fo:block>
      <fo:external-graphic
      content-width="8in"
      >
          <xsl:attribute name="src">
      		<xsl:call-template name="fo-external-image">
		<xsl:with-param name="filename" select="$header.image.filename"/>
      		</xsl:call-template>
      	  </xsl:attribute>
      </fo:external-graphic>
    </fo:block>
    </fo:block-container>
    <xsl:choose>
    <xsl:when test="$confidential = 1">
    <xsl:message>============= MATCHED CONFIDENTIAL TEST BASED ON MAKEFILE ===================</xsl:message>
    	<fo:block-container 
    	absolute-position="absolute"
    	top=".25in"
    	z-index="1"
    	>
  	<fo:block keep-together.within-line="always" font-weight="bold" color="white" font-size="14pt">
	  <xsl:text>RED HAT CONFIDENTIAL: INTERNAL USE ONLY</xsl:text>
        </fo:block>
    	</fo:block-container>
    </xsl:when>
    </xsl:choose>
  </xsl:when>
  <!--
  <xsl:when test="$confidential = 1 and ($position='center')">
  	<fo:block keep-together.within-line="always" font-weight="bold" color="white">
	  <xsl:text>RED HAT CONFIDENTIAL</xsl:text>
        </fo:block>
  </xsl:when>
  -->
  <xsl:when test="$draft.mode = 'yes'">
      <fo:block-container
    	absolute-position="absolute"
    	top=".5in"
    	z-index="1"
       >
       <fo:block font-weight="bold" color="black" font-size="14pt">
         <xsl:message>******************* DRAFT *******************</xsl:message>
         <xsl:text>DRAFT</xsl:text>
       </fo:block>
       </fo:block-container>
  </xsl:when>

</xsl:choose>
</xsl:template>


<!-- running footer -->
<xsl:template name="footer.content">
<xsl:param name="position" select="''"/>
<xsl:choose>
  <xsl:when test="$confidential = 1 and ($position='center')">
  	<fo:inline keep-together.within-line="always" font-weight="bold">
	  <xsl:text>RED HAT CONFIDENTIAL: INTERNAL USE ONLY</xsl:text>
        </fo:inline>
  </xsl:when>
  <xsl:when test="$position='left'">
	<fo:block-container 
	position="absolute" 
	top="0pt" 
	left="4.2in" 
	height="10pt" 
	width="2in" 
	font-size="8.5pt"
	>
		<fo:block text-align="right">Page <fo:page-number/></fo:block>
	</fo:block-container>

	<fo:block-container 
	position="absolute" 
	top="0pt" 
	left="0in" 
	height="10pt" 
	width="2in" 
	font-size="8.5pt"
	>
		<fo:block>www.redhat.com</fo:block>
	</fo:block-container>

	<fo:block-container 
	position="absolute" 
	left="0in" 
	height=".5in" 
	width="6.2in" 
	>
		<fo:block text-align="justify" font-size="7.5pt">
		Copyright 2009 Red Hat, Inc.
		All rights reserved. Red Hat, Red Hat Linux, the
		Red Hat Shadowman logo, and the products listed are
		trademarks or registered trademarks of Red Hat,
		Inc. in the US and other countries. Linux is a
		registered trademark of Linus Torvalds.
		</fo:block>
	</fo:block-container>
</xsl:when>
</xsl:choose>
</xsl:template>




<xsl:attribute-set name="chapter.titlepage.recto.style">
        <xsl:attribute name="color"><xsl:value-of select="$title.color"/></xsl:attribute>
        <xsl:attribute name="background-color">white</xsl:attribute>
        <xsl:attribute name="font-size">
                <xsl:choose>
                        <xsl:when test="$l10n.gentext.language = 'ja-JP'">
                                <xsl:value-of select="$body.font.master * 1.8"/>
                                <xsl:text>pt</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:value-of select="$body.font.master * 1.8"/>
                                <xsl:text>pt</xsl:text>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:attribute>
        <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="text-align">left</xsl:attribute>
        <!--xsl:attribute name="wrap-option">no-wrap</xsl:attribute-->
        <xsl:attribute name="padding-left">1em</xsl:attribute>
        <xsl:attribute name="padding-right">1em</xsl:attribute>
</xsl:attribute-set>



<!-- reference on this parameter:
 http://docbook.sourceforge.net/release/xsl/current/doc/fo/generate.toc.html
-->
<xsl:param name="generate.toc">
article toc,title,figure,table,example,equation
book    toc,title,figure,table,example,equation
</xsl:param>




<!-- labelling -->
<xsl:param name="appendix.autolabel">A</xsl:param>
<xsl:param name="section.autolabel" select="1"></xsl:param>

<!-- highlighting -->
<xsl:param name="highlight.source" select="1"></xsl:param>
<xsl:param name="highlight.default.language">sh</xsl:param>




<xsl:param name="paper.type" select="'Letter'"/>
<xsl:param name="double.sided">0</xsl:param>


<!-- Space between paper border and content (chaotic stuff, don't touch) -->
<xsl:param name="region.before.extent">1in</xsl:param>
<xsl:param name="body.margin.top">1.25in</xsl:param>
<xsl:param name="body.margin.inner">1in</xsl:param>
<xsl:param name="body.margin.left">1in</xsl:param>
<xsl:param name="body.margin.outer">1.3in</xsl:param>
<xsl:param name="body.margin.bottom">.25in</xsl:param>
<xsl:param name="region.after.extent">.75in</xsl:param>
<xsl:param name="page.margin.top">.5in</xsl:param>
<xsl:param name="page.margin.bottom">1in</xsl:param>
<xsl:param name="page.margin.inner">1in</xsl:param>
<xsl:param name="page.margin.outer">1.3in</xsl:param>


<!-- page breaks -->
<xsl:attribute-set name="section.title.level0.properties">
  <xsl:attribute name="break-before">page</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="above.title.properties" use-attribute-sets="formal.title.properties">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
	<xsl:attribute name="background-color"></xsl:attribute>
        <xsl:attribute name="font-size">
                <xsl:value-of select="$body.font.master"/>
                <xsl:text>pt</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="space-before.optimum"><xsl:text>2em</xsl:text></xsl:attribute>
        <xsl:attribute name="space-before.minimum"><xsl:text>2em</xsl:text></xsl:attribute>
        <xsl:attribute name="space-before.maximum"><xsl:text>2em</xsl:text></xsl:attribute>
        <xsl:attribute name="space-after.optimum"><xsl:text>0.1pt</xsl:text></xsl:attribute>
        <xsl:attribute name="space-after.minimum"><xsl:text>0.1pt</xsl:text></xsl:attribute>
        <xsl:attribute name="space-after.maximum"><xsl:text>0.1pt</xsl:text></xsl:attribute>
</xsl:attribute-set>


<xsl:attribute-set name="below.title.properties" use-attribute-sets="formal.title.properties">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="font-size">
                <xsl:value-of select="$body.font.master"/>
                <xsl:text>pt</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="space-before.optimum"><xsl:text>0.1pt</xsl:text></xsl:attribute>
        <xsl:attribute name="space-before.minimum"><xsl:text>0.1pt</xsl:text></xsl:attribute>
        <xsl:attribute name="space-before.maximum"><xsl:text>0.1pt</xsl:text></xsl:attribute>
</xsl:attribute-set>





<xsl:param name="title.color">#000000</xsl:param>
<xsl:param name="admon.graphics.extension" select="'.svg'"/>



<xsl:attribute-set name="shade.verbatim.style">
        <xsl:attribute name="padding-top">0pt</xsl:attribute>
        <xsl:attribute name="padding-bottom">0pt</xsl:attribute>
</xsl:attribute-set>


<!-- default stylesheet causes page to implode 
     if <example><screen> consumes an entire column 
     See http://www.sagehill.net/docbookxsl/PageBreaking.html -->
<xsl:attribute-set name="formal.object.properties">
  <xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
</xsl:attribute-set>




<xsl:attribute-set name="graphical.admonition.properties">
	<xsl:attribute name="keep-together.within-column">always</xsl:attribute>
        <xsl:attribute name="color">white</xsl:attribute>
        <xsl:attribute name="background-color">
          <xsl:choose>
                <xsl:when test="local-name(.)='note'">
                        <xsl:text>#5CB3FF</xsl:text>
                        <!--<xsl:text>#0099ff</xsl:text>-->
                        <!--<xsl:text>#0033ff</xsl:text>-->
                        <!--<xsl:text>#8e9f00</xsl:text>-->
                </xsl:when>
                <xsl:when test="local-name(.)='important'">
                        <!--<xsl:text>#cc0000</xsl:text>-->
                        <!--<xsl:text>#990000</xsl:text>-->
                        <xsl:text>#d08e13</xsl:text>
                </xsl:when>
                <xsl:when test="local-name(.)='warning'">
                        <xsl:text>#cc0000</xsl:text>
                        <!--<xsl:text>#0066ff</xsl:text>-->
                        <!--<xsl:text>#9e292b</xsl:text>-->
                </xsl:when>
                <xsl:when test="local-name(.)='caution'">
                        <xsl:text>#cc0000</xsl:text>
                        <!--<xsl:text>#0066ff</xsl:text>-->
                        <!--<xsl:text>#9e292b</xsl:text>-->
                </xsl:when>
                <xsl:when test="local-name(.)='tip'">
                        <xsl:text>#5CB3FF</xsl:text>
                        <!--<xsl:text>#0099ff</xsl:text>-->
                </xsl:when>
                <xsl:otherwise>
                        <xsl:text>#dddddd</xsl:text>
                </xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
</xsl:attribute-set>



<!--
From: fo/table.xsl
Reason: Table Header format
Version:1.72
-->
<xsl:template name="table.cell.block.properties">
  <!-- highlight this entry? -->
  <xsl:if test="ancestor::thead or ancestor::tfoot">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="background-color">#cc0000</xsl:attribute>
        <xsl:attribute name="color">white</xsl:attribute>
  </xsl:if>
</xsl:template>


<!-- customize this template to add row properties -->
<xsl:template name="table.row.properties">
  <xsl:variable name="bgcolor">
    <xsl:call-template name="dbfo-attribute">
      <xsl:with-param name="pis" select="processing-instruction('dbfo')"/>
      <xsl:with-param name="attribute" select="'bgcolor'"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:if test="$bgcolor != ''">
    <xsl:attribute name="background-color">
      <xsl:value-of select="$bgcolor"/>
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="ancestor::thead or ancestor::tfoot">
        <xsl:attribute name="background-color">#cc0000</xsl:attribute>
  </xsl:if>
</xsl:template>




<xsl:attribute-set name="sidebar.properties" use-attribute-sets="formal.object.properties">
	<xsl:attribute name="keep-together.within-column">always</xsl:attribute>
	<xsl:attribute name="background-color">#eeeeee</xsl:attribute>
	<!--
	<xsl:attribute name="margin-left">0.5in</xsl:attribute>
	<xsl:attribute name="margin-right">0.5in</xsl:attribute>
	-->
</xsl:attribute-set>


<xsl:attribute-set name="blockquote.properties" use-attribute-sets="sidebar.properties">
	<!--
	<xsl:attribute name="margin-{$direction.align.start}">0.5in</xsl:attribute>
	<xsl:attribute name="margin-{$direction.align.end}">0.5in</xsl:attribute>
	-->
	<xsl:attribute name="space-after.minimum">0.5em</xsl:attribute>
	<xsl:attribute name="space-after.optimum">1em</xsl:attribute>
	<xsl:attribute name="space-after.maximum">2em</xsl:attribute>
</xsl:attribute-set>




</xsl:stylesheet>




More information about the publican-list mailing list