This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XSL help required to display PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL help required to display PDF" Watch "XSL help required to display PDF" New topic
Author

XSL help required to display PDF

Deepa Natrajan
Greenhorn

Joined: Dec 14, 2003
Posts: 10
Hi All
I am using xsl to generate PDF reports from XML.
my XML file looks like
<?xml version="1.0" encoding="UTF-8"?>
<TRADEDATA>
<reportname>CurrencyOverLay New Trades as on 2003-12-22</reportname>
<RECORD>
<TradeDate1>2003-12-19 00:00:00.0</TradeDate1>
<Account>R002</Account>
<TradeDate>2003-12-19 00:00:00.0</TradeDate>
<Side>FBY</Side>
<PrimaryCcy>GBP</PrimaryCcy>
<SecondaryCcy>JPY</SecondaryCcy>
<TradeNumber>43TN295642001</TradeNumber>
<PrimaryAmount>1,720,000</PrimaryAmount>
<SecondaryAmount>324,078,960</SecondaryAmount>
<Rate>188.418</Rate>
<SettleDate>2004-04-06 00:00:00.0</SettleDate>
<BrokerName>MORGAN STANLEY SECURITIES</BrokerName>
<STATUS>NEW TRADE</STATUS>
</RECORD>
<RECORD>
<TradeDate1>2003-12-20 00:00:00.0</TradeDate1>
<Account>R002</Account>
<TradeDate>2003-12-19 00:00:00.0</TradeDate>
<Side>FBY</Side>
<PrimaryCcy>USD</PrimaryCcy>
<SecondaryCcy>JPY</SecondaryCcy>
<TradeNumber>43TN295677201</TradeNumber>
<PrimaryAmount>3,030,000</PrimaryAmount>
<SecondaryAmount>325,725,000</SecondaryAmount>
<Rate>107.5</Rate>
<SettleDate>2004-04-06 00:00:00.0</SettleDate>
<BrokerName>MORGAN STANLEY SECURITIES</BrokerName>
<STATUS>NEW TRADE</STATUS>
</RECORD>
<TRADEDATA>
i had written an xsl file to display this xml as pdf reports as below.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl utput method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<!-- ========================= -->
<!-- root element: TRADEDATA -->
<!-- ========================= -->
<xsl:template match="TRADEDATA">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="all-pages" page-height="28cm" page-width="40cm" margin-top="1cm" margin-bottom="1cm" margin-left="0.5cm" margin-right="0.5cm" >
<fo:region-body region-name="xsl-region-body" margin-top="2cm" margin-bottom="1cm" margin-left="0.2cm" margin-right="0.2cm" column-gap="0.2cm" padding="6pt" />
<fo:region-before region-name="xsl-region-before" extent="0.7in" display-align="after" padding="6pt 0.7in" />
<fo:region-after region-name="xsl-region-after" extent="0.3in" display-align="before" padding="6pt 0.7in" />
</fo:simple-page-master>
<fo age-sequence-master master-name="default-sequence">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="any" blank-or-not-blank="not-blank" master-reference="all-pages"/>
</fo:repeatable-page-master-alternatives>
</fo age-sequence-master>
</fo:layout-master-set>
<fo age-sequence master-reference="default-sequence">
<fo:static-content flow-name="xsl-region-before">
<fo:list-block font-size="8pt" font-family="Helvetica" font-weight="bold" provisional-distance-between-starts="5in" provisional-label-separation="0in">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block text-align="start" >
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" margin-top="3cm">
<fo:block text-align="end" >
<xsl:value-of select="currentdate"/>
</fo:block>
<fo:block font-size="12pt" text-align="end" >
<fo:wrapper >Bank</fo:wrapper>
</fo:block>
<fo:block font-size="12pt" text-align="end" >
<fo:wrapper >Japan Ltd.</fo:wrapper>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:list-block font-size="12pt" font-family="Times" provisional-distance-between-starts="3in" provisional-label-separation="0in">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block text-align="start" >
��
<fo:basic-link external-destination="url(http://www.nfo.com/)" color="#0000C0" text-decoration="underline">
nfo
</fo:basic-link>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block text-align="end" >
page <fo age-number/> of <fo age-number-citation ref-id="endofdoc"/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block text-align="center" font-size="16pt" font-weight="bold" space-after="5mm"><xsl:value-of select="reportname"/>
</fo:block>
<fo:block margin-top="1pt" font-size="12pt" keep-with-next.within-column="always" keep-together.within-column="always" >
<fo:table table-layout="fixed" >
<fo:table-column column-width="2cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-column column-width="2.5cm"/>
<fo:table-column column-width="2.5cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-column column-width="4.0cm"/>
<fo:table-column column-width="2.0cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-column column-width="3.5cm"/>
<fo:table-header >
<fo:table-row height="18pt" >
<fo:table-cell starts-row="true" text-align="center" display-align="center" padding="6pt" number-columns-spanned="0" >
<fo:block margin-top="1pt" font-size="6pt" font-weight="bold" space-before="6pt" space-after="6pt" keep-with-next.within-column="always" keep-together.within-column="always" text-align="center">
<fo:wrapper text-decoration="underline"><xsl:value-of select="projecttitle"/></fo:wrapper>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row height="15pt" padding-top="5pt">
<fo:table-cell text-align="center" column-width="2cm">
<fo:block>Account</fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" column-width="3.5cm">
<fo:block>TradeDate</fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" column-width="2.5cm">
<fo:block>Side</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="2.5cm">
<fo:block>PrimaryCcy</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>SecondaryCcy</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>TradeNumber</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>PrimaryAmount</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="4.5cm">
<fo:block>SecondaryAmount</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>Rate</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>SettleDate</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>BrokerCode</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" column-width="3.5cm">
<fo:block>Status</fo:block>
</fo:table-cell>
</fo:table-row>

<fo:table-row height="18pt" padding="4pt">
<fo:table-cell starts-row="true" text-align="center" display-align="center" padding="4pt" number-columns-spanned="12" >
<fo:block >
<fo:leader leader-pattern="rule" leader-length="100%" rule-thickness="1.0pt" rule-style="solid" color="black" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body >
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:block>
<fo:block id="endofdoc"/>
</fo:flow>
</fo age-sequence>
</fo:root>
</xsl:template>
<!-- ========================= -->
<!-- child element: member -->
<!-- ========================= -->
<xsl:template match="RECORD">
<fo:table-row height="1pt" padding-top="1pt">
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="Account"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="TradeDate"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="Side"/>
</fo:block>
</fo:table-cell>

<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="PrimaryCcy"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="SecondaryCcy"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="TradeNumber"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="PrimaryAmount"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="center">
<xsl:value-of select="SecondaryAmount"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="right">
<xsl:value-of select="Rate"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="right">
<xsl:value-of select="SettleDate"/>
</fo:block>
</fo:table-cell>

<fo:table-cell>
<fo:block text-align="right">
<xsl:value-of select="BrokerName"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="right">
<xsl:value-of select="STATUS"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
i am getting all the above details in a single PDF page.
i am trying to display in different pages based on TradeDate1 element of above XML.
I wanted to display all the records that have same TradeDate1 in one [page and move to next page when TradeDate1 changes.
If anybody has worked on this kind of application please let me know how to approach.
Regards
Deepa
[ December 25, 2003: Message edited by: Deepa Natrajan ]
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Two steps.
1. Identify using XPath what data shd go where according to TradeDate.
2. Create new fo age-sequence for every different Tradedate. This will help you to display different data in different pages.
If you are using apache fop,please check the docs folder for examples.
if you can't understand my reply please post back.


Spritle Software Blogs
 
Don't get me started about those stupid light bulbs.
 
subject: XSL help required to display PDF