I have an xml that lists calls made by a customer, which I need to display across two columns. Depending on the number of calls, the list can be in a single page - single column, single page - double column, or multi page - double column.
I have to use basic apace fop and do not have access to antenna house or similar libraries.
When I use for-each I can display the calls, but only on a single column. I cant for the life of me get to double column.
The closest I got to was this video below by @Eliot Kimber, but just could not get around doing it
https://www.youtube.com/watch?v=x6pe7KXicpA
I tried using column mod, but that again just list all the calls in a single column
My XML looks like below.
<CallsMade fromNumber="987654321">
<CallItem>
<DialledNumber>0123456789</DialledNumber>
<DateTime>2019-07-15 15:35:35</DateTime>
<Duration>00:04:23</Duration>
<Cost>$1.24</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456790</DialledNumber>
<DateTime>2019-07-15 15:36:35</DateTime>
<Duration>00:04:24</Duration>
<Cost>$1.25</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456791</DialledNumber>
<DateTime>2019-07-15 15:37:35</DateTime>
<Duration>>00:04:25</Duration>
<Cost>$1.26</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456792</DialledNumber>
<DateTime>2019-07-15 15:38:35</DateTime>
<Duration>>00:04:26</Duration>
<Cost>$1.27</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456793</DialledNumber>
<DateTime>2019-07-15 15:39:35</DateTime>
<Duration>>00:04:27</Duration>
<Cost>$1.28</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456794</DialledNumber>
<DateTime>2019-07-15 15:40:35</DateTime>
<Duration>>00:04:28</Duration>
<Cost>$1.29</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456795</DialledNumber>
<DateTime>2019-07-15 15:41:35</DateTime>
<Duration>>00:04:29</Duration>
<Cost>$1.30</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456931</DialledNumber>
<DateTime>2019-07-15 17:57:34</DateTime>
<Duration>00:06:45</Duration>
<Cost>$2.66</Cost>
</CallItem>
<CallsMade>`
XSL that goes multiple pages, but single column is below
<fo:block-container start-indent="0mm" left="5mm" width="48%" span="all">
<fo:table table-layout="fixed" width="100%" font-size="5pt" text-align="center" display-align="center" span="all">
<fo:table-column column-width="proportional-column-width(10)"/>
<fo:table-column column-width="proportional-column-width(15)"/>
<fo:table-column column-width="proportional-column-width(12)"/>
<fo:table-column column-width="proportional-column-width(8)"/>
<fo:table-body font-size="95%" >
<xsl:for-each select="CallItem">
<fo:table-row height="4mm" text-align="center" display-align="center">
<fo:table-cell>
<fo:block>
<xsl:value-of select="DialledNumber"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="DateTime"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Duration"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Cost"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block-container>
I was wondering if anyone could help me display the list as below
It seems that you really just need to know whether you have fewer than 60 CallItem
. If fewer than 60, make the table span both columns, and if not, make it span one column. Normal page breaking will take care of splitting the table across columns and pages.
<xsl:template match="/">
<fo:root xml:lang="en">
<fo:layout-master-set>
<fo:simple-page-master master-name="spm">
<fo:region-body column-count="2" margin="36pt" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="spm">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="CallsMade">
<fo:block span="all">
<xsl:value-of select="@fromNumber" />
</fo:block>
<fo:block-container>
<xsl:if test="count(CallItem) < 60">
<xsl:attribute name="span">all</xsl:attribute>
</xsl:if>
<fo:table table-layout="fixed" width="100%" font-size="5pt" text-align="center" display-align="center" span="all">
<fo:table-column column-width="proportional-column-width(10)"/>
<fo:table-column column-width="proportional-column-width(15)"/>
<fo:table-column column-width="proportional-column-width(12)"/>
<fo:table-column column-width="proportional-column-width(8)"/>
<fo:table-body font-size="95%" >
<xsl:apply-templates select="CallItem" />
</fo:table-body>
</fo:table>
</fo:block-container>
</xsl:template>
<xsl:template match="CallItem">
<fo:table-row height="4mm" text-align="center" display-align="center">
<fo:table-cell>
<fo:block>
<xsl:value-of select="DialledNumber"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="DateTime"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Duration"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Cost"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>