Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2005, 11:46 AM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old May 10th, 2005, 09:28 AM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reads all. I figured out a way of doing it by naming chunks of detail nodes, selecting which chunk to display on any given 'page' by passing a pass number from where the chunk was called; and then doing so for each line item.






Similar Threads
Thread Thread Starter Forum Replies Last Post
find number of lines in .txt file dgr7 Beginning VB 6 8 July 16th, 2014 05:11 AM
DropDownList and number of lines snufse1 ASP.NET 2.0 Basics 0 September 19th, 2008 02:52 PM
Need to Count number of lines in a file lawsoncobol Access VBA 2 July 19th, 2007 04:28 AM
Dynamic Detail section sudarshan73 Crystal Reports 1 January 20th, 2006 05:23 PM
Count the number of output lines joyces XSLT 7 July 6th, 2005 11:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.