1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
3
<xsl:variable name="page_width"><xsl:value-of select="/addresses/page_width"/></xsl:variable>
4
<xsl:variable name="page_height"><xsl:value-of select="/addresses/page_height"/></xsl:variable>
5
<xsl:variable name="initial_bottom_pos"><xsl:value-of select="/addresses/initial_bottom_pos"/></xsl:variable>
6
<xsl:variable name="initial_left_pos"><xsl:value-of select="/addresses/initial_left_pos"/></xsl:variable>
7
<xsl:variable name="height_increment"><xsl:value-of select="/addresses/height_incr"/></xsl:variable>
8
<xsl:variable name="width_increment"><xsl:value-of select="/addresses/width_incr"/></xsl:variable>
9
<xsl:variable name="frame_height"><xsl:value-of select="/addresses/label_height"/></xsl:variable>
10
<xsl:variable name="frame_width"><xsl:value-of select="/addresses/label_width"/></xsl:variable>
11
<xsl:variable name="number_columns"><xsl:value-of select="/addresses/cols"/></xsl:variable>
12
<xsl:variable name="max_frames"><xsl:value-of select="/addresses/rows * /addresses/cols"/></xsl:variable>
13
<xsl:variable name="printer_top"><xsl:value-of select="/addresses/printer_top"/></xsl:variable>
14
<xsl:variable name="printer_bottom"><xsl:value-of select="/addresses/printer_bottom"/></xsl:variable>
15
<xsl:variable name="printer_left"><xsl:value-of select="/addresses/printer_left"/></xsl:variable>
16
<xsl:variable name="printer_right"><xsl:value-of select="/addresses/printer_right"/></xsl:variable>
18
<xsl:template match="/">
19
<xsl:apply-templates select="addresses"/>
22
<xsl:template match="addresses">
24
<template leftMargin="2.0cm" rightMargin="2.0cm" topMargin="2.0cm" bottomMargin="2.0cm" title="Address list" author="Generated by Tiny ERP">
25
<xsl:attribute name="pageSize">
26
<xsl:value-of select="page_width"/><xsl:text>cm,</xsl:text><xsl:value-of select="page_height"/><xsl:text>cm</xsl:text>
28
<pageTemplate id="all">
30
<xsl:apply-templates select="address" mode="frames"/>
34
<paraStyle name="nospace" spaceBefore="0" spaceAfter="0">
35
<xsl:attribute name="fontName">
36
<xsl:value-of select="font_type"/>
38
<xsl:attribute name="fontSize">
39
<xsl:value-of select="font_size"/>
44
<xsl:apply-templates select="address" mode="story">
45
<xsl:sort select="contact/country"/>
46
<xsl:sort select="contact/zip"/>
47
<xsl:sort select="company-name"/>
48
</xsl:apply-templates>
53
<xsl:template match="address" mode="frames">
54
<xsl:if test="position() < $max_frames + 1">
55
<xsl:variable name="width"><xsl:value-of select="$frame_width"/></xsl:variable>
56
<xsl:variable name="height"><xsl:value-of select="$frame_height"/></xsl:variable>
57
<xsl:variable name="x1"><xsl:value-of select="$initial_left_pos + ((position()-1) mod $number_columns) * $width_increment"/></xsl:variable>
58
<xsl:variable name="y1"><xsl:value-of select="$initial_bottom_pos - floor((position()-1) div $number_columns) * $height_increment"/></xsl:variable>
61
<!--Left labels over the left printer margin-->
62
<xsl:when test="$x1 < $printer_left">
63
<xsl:attribute name="x1">
64
<xsl:value-of select="$printer_left"/>
65
<xsl:text>cm</xsl:text>
67
<xsl:attribute name="width">
68
<xsl:value-of select="$width - ($printer_left - $x1)"/>
69
<xsl:text>cm</xsl:text>
72
<!--Right labels over the right printer margin-->
73
<xsl:when test="$page_width - ($x1 + $width) < $printer_right">
74
<xsl:attribute name="x1">
75
<xsl:value-of select="$x1"/>
76
<xsl:text>cm</xsl:text>
78
<xsl:attribute name="width">
79
<xsl:value-of select="$page_width - ($x1 + $printer_right)"/>
80
<xsl:text>cm</xsl:text>
84
<xsl:attribute name="x1">
85
<xsl:value-of select="$x1"/>
86
<xsl:text>cm</xsl:text>
88
<xsl:attribute name="width">
89
<xsl:value-of select="$width"/>
90
<xsl:text>cm</xsl:text>
95
<!--Bottom labels over the bottom printer margin-->
96
<xsl:when test="$y1 < $printer_bottom">
97
<xsl:attribute name="y1">
98
<xsl:value-of select="$printer_bottom"/>
99
<xsl:text>cm</xsl:text>
101
<xsl:attribute name="height">
102
<xsl:value-of select="$height - ($printer_bottom - $y1)"/>
103
<xsl:text>cm</xsl:text>
106
<!--Top labels over the top printer margin-->
107
<xsl:when test="$page_height - ($y1 + $height) < $printer_top">
108
<xsl:attribute name="y1">
109
<xsl:value-of select="$y1"/>
110
<xsl:text>cm</xsl:text>
112
<xsl:attribute name="height">
113
<xsl:value-of select="$page_height - ($y1 + $printer_top)"/>
114
<xsl:text>cm</xsl:text>
118
<xsl:attribute name="y1">
119
<xsl:value-of select="$y1"/>
120
<xsl:text>cm</xsl:text>
122
<xsl:attribute name="height">
123
<xsl:value-of select="$height"/>
124
<xsl:text>cm</xsl:text>
132
<xsl:template match="address" mode="story">
133
<para style="nospace">
134
<!--<xsl:value-of select="position()"/> -->
135
<xsl:value-of select="company-name"/><xsl:text> </xsl:text><xsl:value-of select="company-title"/></para>
137
<xsl:when test="count(contact[type='default']) >= 1">
138
<!-- apply the first 'contact' node with the type 'default' -->
139
<xsl:apply-templates select="contact[type='default'][1]"/>
141
<xsl:when test="count(contact[type='']) >= 1">
142
<!-- apply the first 'contact' node with an empty type -->
143
<xsl:apply-templates select="contact[type=''][1]"/>
146
<!-- apply the first 'contact' node -->
147
<xsl:apply-templates select="contact[1]"/>
153
<xsl:template match="contact">
154
<para style="nospace"><xsl:value-of select="title"/><xsl:text> </xsl:text><xsl:value-of select="name"/></para>
155
<para style="nospace"><xsl:value-of select="street"/></para>
156
<para style="nospace"><xsl:value-of select="street2"/></para>
157
<para style="nospace"><xsl:value-of select="zip"/><xsl:text> </xsl:text><xsl:value-of select="city"/></para>
158
<para style="nospace"><xsl:value-of select="state"/></para>
159
<para style="nospace"><xsl:value-of select="country"/></para>