Ok I am trying to create an XSL-FO out of an XML and an XSLT. And I also want to display a table of the data. The main goal is to output the XSL-FO to a PDF file in java. I already figured out how to do that step. I just need to get the XSL-FO file. Here is my xml file:
[code]
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<sectorList>
<sector>
<name>Technology</name>
<percentOfTotal>
<b>0.16</b>
<s>9.12</s>
<ss>0.80</ss>
<sse>0.00</sse>
</percentOfTotal>
<numberOfShares>
<b>250000</b>
<s>6052</s>
<ss>10100</ss>
<sse>0</sse>
</numberOfShares>
</sector>
<sector>
<name>Consumer Discretionary</name>
<percentOfTotal>
<b>250000</b>
<s>6052</s>
<ss>10100</ss>
<sse>0</sse>
</percentOfTotal>
<numberOfShares>
<b>250000</b>
<s>6052</s>
<ss>10100</ss>
<sse>0</sse>
</numberOfShares>
</sector>
</sectorList>
[/code]
Here is my XSLT file:
[code]
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:fo="
http://www.w3.org/1999/XSL/Format"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<fo:root xmlns:fo="
http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name ="simple" page-height ="29.7cm" page-width ="21cm" margin-left ="2.5cm" margin-right="2.5cm">
<fo:region-body margin-top="3cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body
">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="sectorList">
<fo:table-and-caption>
<fo:table>
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold">Sector<
/fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold">Side</f
o:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold">% of Total</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold">Total Shares</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="sector">
<fo:table-row>
<fo:table-cell number-rows-spanned="4">
<fo:block font-weight="bold"><xsl:va
lue-of select="name"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold">B</fo:b
lock>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="percentOfTotal/b"/
></fo:bloc
k>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="numberOfShares/b"/
></fo:bloc
k>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold">S</fo:b
lock>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="percentOfTotal/s"/
></fo:bloc
k>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="numberOfShares/s"/
></fo:bloc
k>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold">SS</fo:
block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="percentOfTotal/ss"
/></fo:blo
ck>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="numberOfShares/ss"
/></fo:blo
ck>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold">SSE</fo
:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="percentOfTotal/sse
"/></fo:bl
ock>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold"><xsl:va
lue-of select="numberOfShares/sse
"/></fo:bl
ock>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="4"
>
<fo:block font-weight="bold">-------
----------
-------</f
o:block>
</fo:table-cell>
</fo:table-row>
<!--</fo:table-row>-->
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:table-and-caption>
</xsl:template>
</xsl:stylesheet>
[/code]
I want the table to look like this...
Sector | Side | % of Total | Total Shares
--------------------------
----------
----------
-
| B | 0.23 | 100000
Tech | S | 0.12 | 5000
| SS | 12.3 | 1000
| SSE| 0.90 | 200
--------------------------
----------
----------
----------
----------
----------
----------
-------
| B | 0.23 | 100000
Cons | S | 0.12 | 5000
| SS | 12.3 | 1000
| SSE| 0.90 | 200
This data is just sample data but that layout is pretty much what I am looking for. So to summarize, first I need to fix my XML and XSLT files so that I get the correct table output then I need to be able to combine these files and generate a XSL-FO file. Thanks in advance
Start Free Trial