Paged Invoices - Dynamic Number Detail Lines
Hi all. Iâm an XML newbie who is trying to solve a printable invoice problem. The idea would be to be able to print invoices from XML data in something like the following format:
Header Information
Sales Line ID
However many detail lines as will fit on a particular 8.5 x 11 page, with detail line overflow printing on another page along with the Header, Sales Line, and Footer Information â when the number of detail lines is dynamic
Footer Information
Each Sales Line would need to print on a separate page. (For now I am only tasked with solving the problem in generalized terms, i.e, figuring out the âhowâ).
I had thought to set up separate tables for the Header, Sales Line ID, Line Item Details, and Footer, allocating a percentage of the page for each and then nesting these in a different DIV for each chunk of detail lines. However, as far as I can tell, doing so would require knowing what âpassâ is being made, so as to be able to match it with the appropriate âchunk.â (I had thought to solve instances where there are fewer chunks after solving âall chunks.â) However, I canât find a way to increment what would amount to a pass counter, since it seems an xsl:param cannot be reassigned a value outside of the match or call where it is used.
Hereâs my xsl code at the moment:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="pass" select="0"/>
<xsl:template match="/">
<html>
<head>
<title>KK Worksheet</title>
<style type="text/css">
@media screen, print
{
body {background-color: #999999; margin: 10%}
.T_Header{height: 30%; width: 100%; border-style: ridge; border: 2 px; background-color: #FFFFCC}
.T_SLine {height: 5%; width: 100%; border-style: ridge; border: 2 px; background-color: #FFFFCC}
.T_Options {height: 55%; width: 100%; border-style: ridge; border: 2 px; background-color: #FFFFFF}
.T_Footer {height: 5%; width: 100%; border-style: ridge; border: 2 px; background-color: #FFFFCC}
}
</style>
</head>
<body>
<xsl:apply-templates select="root"/>
</body>
</html>
</xsl:template>
<xsl:template match="root">
<xsl:if test="$pass=0">
<xsl:call-template name="Div1"/>
</xsl:if>
<xsl:if test="$pass=1">
<xsl:call-template name="Div2"/>
</xsl:if>
<xsl:if test="$pass=2">
<xsl:call-template name="Div3"/>
</xsl:if>
</xsl:template>
<xsl:template match="details/item">
<xsl:if test="$pass=0">
<xsl:call-template name="Chunk1">
<xsl:with-param name="pass" select="1"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$pass=1">
<xsl:call-template name="Chunk2">
<xsl:with-param name="pass" select="2"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$pass=2">
<xsl:call-template name="Chunk3">
<xsl:with-param name="pass" select="3"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="Div1">
<div>
<table id="table1" class="T_Header">
<tr>
<td>
<ol>
<xsl:for-each select="header/line">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ol>
</td>
</tr>
</table>
<table id="table2" class="T_SLine">
<tr>
<td>
<xsl:value-of select="salesLine/lineItem"/>
</td>
</tr>
</table>
<table id="table4" class="T_Options">
<tr>
<td>
<ol>
<xsl:apply-templates select="details/item"/>
</ol>
</td>
</tr>
</table>
<table id="table4" class="T_Footer">
<tr>
<td>
<ol>
<xsl:for-each select="footer/tootie">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ol>
</td>
</tr>
</table>
</div>
</xsl:template>
<xsl:template name="Div2">
<div>
<table id="table1" class="T_Header">
<tr>
<td>
<ol>
<xsl:for-each select="header/line">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ol>
</td>
</tr>
</table>
<table id="table2" class="T_SLine">
<tr>
<td>
<xsl:value-of select="salesLine/lineItem"/>
</td>
</tr>
</table>
<table id="table4" class="T_Options">
<tr>
<td>
<ol>
<xsl:apply-templates select="details/item"/>
</ol>
</td>
</tr>
</table>
<table id="table4" class="T_Footer">
<tr>
<td>
<ol>
<xsl:for-each select="footer/tootie">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ol>
</td>
</tr>
</table>
</div>
</xsl:template>
<xsl:template name="Div3">
<div>
<table id="table1" class="T_Header">
<tr>
<td>
<ol>
<xsl:for-each select="header/line">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ol>
</td>
</tr>
</table>
<table id="table2" class="T_SLine">
<tr>
<td>
<xsl:value-of select="salesLine/lineItem"/>
</td>
</tr>
</table>
<table id="table4" class="T_Options">
<tr>
<td>
<ol>
<xsl:apply-templates select="details/item"/>
</ol>
</td>
</tr>
</table>
<table id="table4" class="T_Footer">
<tr>
<td>
<ol>
<xsl:for-each select="footer/tootie">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ol>
</td>
</tr>
</table>
</div>
</xsl:template>
<xsl:template name="Chunk1">
<xsl:variable name="chunkNo">
<xsl:choose>
<xsl:when test="24 > position()">chunk1</xsl:when>
<xsl:when test="48 > position() and position() > 23">chunk2</xsl:when>
<xsl:when test="position() > 47">chunk3</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$chunkNo='chunk1'">
<li>
<xsl:value-of select="."/>
</li>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="Chunk2">
<xsl:variable name="chunkNo">
<xsl:choose>
<xsl:when test="24 > position()">chunk1</xsl:when>
<xsl:when test="48 > position() and position() > 23">chunk2</xsl:when>
<xsl:when test="position() > 47">chunk3</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$chunkNo='chunk2'">
<li>
<xsl:value-of select="."/>
</li>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="Chunk3">
<xsl:variable name="chunkNo">
<xsl:choose>
<xsl:when test="24 > position()">chunk1</xsl:when>
<xsl:when test="48 > position() and position() > 23">chunk2</xsl:when>
<xsl:when test="position() > 47">chunk3</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$chunkNo='chunk3'">
<li>
<xsl:value-of select="."/>
</li>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Hereâs an xml file I put together for development purposes:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="XML_Break_Control.xsl"?>
<root>
<header>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
<line>Header</line>
</header>
<salesLine>
<lineItem>Only One Sales Line per Invoice Page</lineItem>
</salesLine>
<details>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
<item>Item Detail</item>
</details>
<footer>
<tootie>footer stuff</tootie>
</footer>
</root>
Any ideas?
|