XSL Templates for Creating Your CV


Introduction

If you've read my resume, you might be wondering how the HTML and the PDF versions are kept in sync. The answer is obvious: both are generated from a single source. This page explains the process in detail, and allows you to create your own CV using the same XML format.

Step 1: The XML source

The first step is creating the actual content. To do this, you use a simple XML format as you can see in this example. Here are a couple of lines to give you an example:

<cv uri="http://cactus.rulez.org/cv/">
  <data>
    <name>
      <firstname>Gergő</firstname>
      <lastname>Érdi</lastname>
      <title>Dr.</title>
    </name>
    <email smtp="cactus@cactus.rulez.org"/>
    <homepage uri="http://cactus.rulez.org/"/>
  </data>

  <section>
    <title>Motivation</title>
    <desc>
      After seven years of developing high-quality Free Software,
      contributing to projects with hundreds of developers from all
      around the globe, using a wide array of technologies, all the
      while keeping an eye on the bleeding edge, I am now ready to
      take a leap into commercial software development.
    </desc>
  </section>
</cv>

As you may have noticed from this small extract, this is actually two small languages merged into one: <section>, <title>, etc. are one language describing the contents of the CV, structured for presentation, while everything inside the <data> tag contains information about the author. I've created this second language because it contains data that's easy to structure in a semantic way, and can come in handy in later steps, when creating an e.g. PDF view of your CV.

Step 2: Including your contact details

Of course, in the final resume, you want a section displaying information from the <data> tag. You could repeat all those addresses and telephone numbers and whatnot inside a <section> tag, but that would be redundant. So we will create a very simple XSLT template that copies everything from both languages (i.e. the <data> tag is passed on, for later stages), but also creates a special section titled "Personal information". This is an important technique and you should take the time to understand its implications fully.

Step 3: Creating a presentation

After the previous step, you now have an XML file that should contain everything needed to create a CV for displaying or printing.

There are currently two presentations supported: XHTML and XSL:FO. The XHTML output is useful for including your resume in your home page, and the XSL:FO output can be rendered into printable file formats (as explained in the next step).

A common theme of both the XHTML and the XSL:FO output format is that they are both XML formats. This means we can use XSLT again to create them! And remember, the output of step 2 still contains the <data> part of the source as well, so you can do nice effects like including your name in the XHTML page's <title> tag.

About the HTML templates

The HTML templates are the more straightforward of the two. The templates work by creating a single two-column table for the whole document, and using cells spanning both columns for the section headers. A lot of the actual formatting is specified in the CSS file, so you can easily tune it to your liking.

About the XSL:FO templates

These templates create an XSL:FO file describing a printable resume for A/4 paper size. You might wonder why all those blind tables are generated that contain section headers in the first row, and normal items in the second. This is a workaround for the Apache FOP processor's limited support for the keep-with-next formatting attribute. Similarily, you need to hardcode your photograph's size into the stylesheet because of FOP's combination of no support for <fo:float> objects, and limited support for absolute positioning. In short, the separation of content and presentation breaks down a bit at the XSL:FO templates, which is something I hope to eventually get around to fix.

Step 4: Rendering the CV

If you're using the HTML templates, you're done: just upload the resulting HTML file and the included CSS, and leave the rendering to your readers' browser agents. However, if you want to print your resume, you need to render the XSL:FO file into a ready-to-print file format, practically Adobe PDF. To do this, you need an FO processor that typesets and paginates your document. A Free XSL:FO processor is the above-mentioned FOP, part of the Apache Project. FOP can do more than just PDF: you can use it to e.g. create an SVG file, which can be further processed by XML tools.