views:

167

answers:

2

I have a huge xml file. And it's being transformed to html table with xsl. In browser it's a single page with vertical scrollbar.

But when I want to print the document I can see about 10 pages. I want to add table headers to every printed page.

Sample xml:

<page>
   <document>
      <id>100</id>
      <name>SomeName</name>
      <date>02.02.2009</date>
   </document>
   ...
</page>

And xsl for it:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

<xsl:template match="/page">
   <table border="1">
      <tr>
         <th>Id</th><th>Name</th><th>Date</th>  <!-- I want to see this on every page -->
      </tr>
      <xsl:apply-templates/>
   </table>
</xsl:template>

<xsl:template match="document">
   <tr>
      <td>
         <xsl:value-of select="id"/>
      </td>
      <td>
         <xsl:value-of select="name"/>
      </td>
      <td>
         <xsl:value-of select="date"/>
      </td>
   </tr>
</xsl:template>
</xsl:stylesheet>

I'm thinking about XSL-FO as an instrument to print headers on every page but as I understand it's not supported by browsers and we need some special software to process XSL-FO documents.

So, what is the correct way to add headers to the print version of a web-page?

+1  A: 

You don't want to pre-paginate your content for the browser, because you will inevitably end up with browsers that print at a slightly different scale than you expect, and then it will look bad. Your absolute best option is to provide a PDF of your content that specifies how it is to be printed, but that doesn't fit with what you're doing.

Unfortunately, there's not any standardized way to provide paginated headers as you request on printed pages rendered as HTML.

Paul McMillan
A: 

You can do this by using a combination of <thead> sections and CSS. You're missing the <thead> section. Check out this link.

Chris Gow