krysalis-barcode/examples/xsl-fo invoice2xsl-fo.xsl,NONE,1.1 invoice.xml,NONE,1.1
[email protected] Fri, 07 Nov 2003 03:24:16 -0800
Newsgroups
gmane.comp.krysalis.cvs
Message-ID
<[email protected] >
Update of /cvsroot/krysalis/krysalis-barcode/examples/xsl-fo
In directory sc8-pr-cvs1:/tmp/cvs-serv6768/examples/xsl-fo
Added Files:
invoice2xsl-fo.xsl invoice.xml
Log Message:
A simple "real-life" example for using the Barcode extension for Xalan-J.
--- NEW FILE: invoice2xsl-fo.xsl ---
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:barcode="org.krysalis.barcode.xalan.BarcodeExt" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="barcode date">
<xsl:output method="xml" indent="yes"/>
<xsl:decimal-format name="std" decimal-separator="." grouping-separator="'" infinity="#x221E" minus-sign="-"/>
<xsl:template match="/">
<fo:root>
<!-- defines the layout master -->
<fo:layout-master-set>
<fo:simple-page-master master-name="normal_page" page-height="29.7cm" page-width="21cm" margin-top="3cm" margin-bottom="2.5cm" margin-left="3cm" margin-right="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- starts actual layout -->
<fo:page-sequence master-reference="normal_page">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="Helvetica" font-size="11pt" font-weight="normal">
<fo:table table-layout="fixed" space-after="2cm">
<fo:table-column column-width="8cm"/>
<fo:table-column column-width="8cm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell text-align="start">
<fo:block>
<fo:external-graphic src="url(http://www.krysalis.org/barcode/images/group-logo.gif)" width="4cm"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="end">
<fo:block>
<fo:external-graphic src="url(http://www.krysalis.org/barcode/resources/images/krysalis-barcode-logo.gif)" width="3.5cm"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:table table-layout="fixed" space-after="1cm">
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="5cm"/>
<fo:table-column column-width="6.5cm"/>
<fo:table-body>
<fo:table-row height="3.0cm">
<!-- should have: height="3.0cm" -->
<fo:table-cell padding-top="1cm"/>
<fo:table-cell/>
<fo:table-cell padding-top="1cm">
<xsl:apply-templates select="/invoice/header/client"/>
</fo:table-cell>
</fo:table-row>
<fo:table-row height="1.5cm"/>
<fo:table-row>
<fo:table-cell>
<fo:block>Invoice date:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block><xsl:value-of select="date:format-date(/invoice/header/invoicedate, 'EEE, d MMM yyyy')"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>For questions about this invoice:</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>Invoice number:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block><xsl:value-of select="/invoice/header/invoicenr"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Hotline:<xsl:text> 555 5555</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>Client number:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block><xsl:value-of select="/invoice/header/client/id"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>e-mail:<xsl:text> [email protected] </xsl:text></fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell/>
<fo:table-cell>
<fo:block>
<fo:instream-foreign-object>
<!-- ================================================================= -->
<!-- ====================== THE BARCODE IS HERE ====================== -->
<!-- ================================================================= -->
<xsl:variable name="barcode-cfg">
<barcode>
<code128>
<human-readable>none</human-readable>
<height>5mm</height>
<quiet-zone enabled="false"/>
</code128>
</barcode>
</xsl:variable>
<xsl:copy-of select="barcode:generate($barcode-cfg, /invoice/header/invoicenr)"/>
<!-- ================================================================= -->
<!-- ====================== THE BARCODE IS HERE ====================== -->
<!-- ================================================================= -->
</fo:instream-foreign-object>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Page<xsl:text> </xsl:text>
<fo:page-number/>
<xsl:text> </xsl:text>of<xsl:text> </xsl:text>
<fo:page-number-citation ref-id="endofdoc"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<xsl:apply-templates select="/invoice/details"/>
<fo:block id="endofdoc"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="details">
<fo:table table-layout="fixed" space-before="2mm">
<fo:table-column column-width="13cm"/>
<fo:table-column column-width="3cm"/>
<fo:table-header padding-bottom="1mm">
<fo:table-row border-bottom-style="solid" border-bottom-width="0.5pt">
<fo:table-cell border-bottom="solid 0.5pt">
<fo:block font-weight="bold">Article</fo:block>
</fo:table-cell>
<fo:table-cell border-bottom="solid 0.5pt">
<fo:block font-weight="bold" text-align="end">Amount</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:apply-templates/>
<fo:table-row height="1mm"/>
<fo:table-row border-top-style="solid" border-top-width="0.5pt" border-bottom-style="solid" border-bottom-width="1.5pt">
<fo:table-cell border-top="solid 0.5pt" border-bottom="solid 1.5pt" padding-top="1mm">
<fo:block font-weight="bold">Total</fo:block>
</fo:table-cell>
<fo:table-cell border-top="solid 0.5pt" border-bottom="solid 1.5pt" padding-top="1mm">
<fo:block font-weight="bold" text-align="end">
<xsl:value-of select="format-number(sum(position/@amount), '0.00', 'std')"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="position">
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
<xsl:if test="@count != ''">
<fo:table-cell>
<fo:block text-align="end">
<xsl:value-of select="@count"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="end">
<xsl:value-of select="format-number(number(@unitprice), '0.00', 'std')"/>
</fo:block>
</fo:table-cell>
</xsl:if>
<fo:table-cell>
<fo:block text-align="end">
<xsl:value-of select="format-number(number(@amount), '0.00', 'std')"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<!-- ===== adress formatting ===== -->
<xsl:template match="client">
<xsl:call-template name="address-private-salutation"/>
</xsl:template>
<xsl:template name="address-private-salutation">
<fo:block>
<xsl:value-of select="@salutation"/>
</fo:block>
<xsl:call-template name="address-private"/>
</xsl:template>
<xsl:template name="address-private">
<fo:block>
<xsl:call-template name="name-private-with-title"/>
</fo:block>
<xsl:apply-templates select="postal"/>
</xsl:template>
<xsl:template name="name-private-with-title">
<xsl:if test="@title!=''">
<xsl:value-of select="@title"/>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:call-template name="name-private"/>
</xsl:template>
<xsl:template name="name-private">
<xsl:value-of select="firstname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="name"/>
</xsl:template>
<xsl:template match="postal">
<fo:block>
<xsl:value-of select="street"/>
</fo:block>
<fo:block>
<xsl:value-of select="pobox"/>
</fo:block>
<fo:block>
<xsl:value-of select="zip/@countrycode"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="zip"/>
<xsl:text> </xsl:text>
<xsl:value-of select="place"/>
</fo:block>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: invoice.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<invoice lang="en">
<header>
<client salutation="Mr.">
<id>843759</id>
<name>Smith</name>
<firstname>John</firstname>
<postal>
<street>Business Road 2</street>
<zip countrycode="DE">23046</zip>
<place>Hannover</place>
</postal>
</client>
<invoicenr>6465-8896</invoicenr>
<invoicedate>2001-02-09</invoicedate>
<due>2001-03-31</due>
<currency>USD</currency>
</header>
<details>
<position amount="22.95">Mousepad "Fancy"</position>
<position amount="13277.00">GeekyScreen TFT Display 36"</position>
</details>
</invoice>
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/