Using XSL:FO to create business cards or name-tags

Here should go questions about transforming XML with XSLT and FOP.
kypen
Posts: 1
Joined: Thu May 18, 2006 9:59 pm

Using XSL:FO to create business cards or name-tags

Post by kypen »

Howdy guys,
I have several XML sheets with approximetely two or three hundred names, e-mail adresses, etc in each one like so:

Code: Select all


<peopleset>
<department>DEPT NAME</department>
<person>
<id>0123456789</id>
<lastname>SMITH</lastname>
<firstname>JOHN</firstname>
<sortname>SMITH, JOHN</sortname>
<officenumber>123</officenumber>
<phone>(123)456-7890</phone>
<email>SMITHJ@abc.com</email>
</person>
<person>
.
.
.
</peopleset>
My boss has given me a test assignment of making name tags or business cards from this data. I am using XSL:FO to transform the data into a pdfs so users can do it as the faculty list is updated. There are 6 cards on 1 sheet, top/bottom margin 1", left/right margins of 1/4". There are 2 columns and 3 rows of cards on a sheet that is 8.5"x11". Hence, each card is 4"x3". I'm trying to do this using tables, but can't get it so it works as follows (dashes are spaces):
_____________________________
|--------PERSON A|------PERSON B |
|______________|______________|
|-------PERSON C |------PERSON D |
|______________|______________|
etc

All I can do is either:
_____________________________
|-------PERSON A |------PERSON A |
|______________|______________|
|-------PERSON B |------PERSON B |
|______________|______________|
using the same data for both cells

or
_____________________________
|-------------------|PERSON A------|
|______________|______________|
|PERSON B------ |------------------|
|______________|______________|
using if statements and modulus 2 on the id (useless)

Here is my current XSL:FO:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master margin-bottom="1in" margin-left="0.25in"
margin-right="0.25in" margin-top="1in" master-name="Avery 5384"
page-height="11in" page-width="8.5in">
<fo:region-body margin-bottom="0" margin-left="0" margin-right="0"
margin-top="0"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence initial-page-number="1" master-reference="Avery 5384">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="peopleset"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="peopleset">
<fo:table border="0.5pt solid black" text-align="center">
<fo:table-column column-width="4in"/>
<fo:table-column column-width="4in"/>
<fo:table-body>
<xsl:apply-templates select="person"/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="//person">
<fo:table-row height="3in">
<fo:table-cell border="0.5pt solid black" vertical-align="middle">
<fo:block display-align="center" font-family="sans-serif" font-size="12pt"
padding="10px" text-align="center" vertical-align="middle">
<xsl:value-of select="sortname"/>
<fo:block/>
<xsl:value-of select="email"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border="0.5pt solid black" vertical-align="middle">
<fo:block display-align="center" font-family="sans-serif" font-size="12pt"
padding="10px" text-align="center" vertical-align="middle">
<xsl:value-of select="sortname"/>
<fo:block/>
<xsl:value-of select="email"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
Sorry for the long post...
Please help!
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

Replace the template matching person with the one below. This matches person elements that are on odd positions, that is 1, 3, 5, etc. and adds information in a row for that person and for the following sibling person, that is for 2, 4, 6, etc.

Code: Select all


<xsl:template match="person[position() mod 2=1]">
<fo:table-row height="3in">
<fo:table-cell border="0.5pt solid black" vertical-align="middle">
<fo:block display-align="center" font-family="sans-serif" font-size="12pt"
padding="10px" text-align="center" vertical-align="middle">
<xsl:value-of select="sortname"/>
<fo:block/>
<xsl:value-of select="email"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border="0.5pt solid black" vertical-align="middle">
<fo:block display-align="center" font-family="sans-serif" font-size="12pt"
padding="10px" text-align="center" vertical-align="middle">
<xsl:value-of select="following-sibling::person[1]/sortname"/>
<fo:block/>
<xsl:value-of select="following-sibling::person[1]/email"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
Best Regards,
George
Post Reply