remove table cell in xsl-fo - xslt

I have this problem where I need to remove table cells when they are empty. But they always leave a small gap.
If the user fills out every option, the table is normal. If the user only fills out some fields then the table generates this dark horizontal line.
I suspect it is the empty cells bunching up.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" media-type="text/html" />
<xsl:template match="fwcF17Part35Page">
<xsl:apply-templates select="part35Details"/>
</xsl:template>
<xsl:template match="part35Details">
<fo:block keep-together.within-page="always">
<fo:block padding="5pt"/>
<fo:block font-size="16pt" text-align="left">
Upload Documents - test
</fo:block>
<fo:block>
<fo:leader leader-pattern="rule" leader-length="100%" rule-style="solid" rule-thickness="2pt"/>
</fo:block>
<fo:block padding="8pt"/>
<fo:block background-color="#ebe8e8" font-size="10pt" font-weight="bold">
Document(s)
</fo:block>
<fo:block padding="4px" font-size="8pt" font-weight="normal" text-align="center">
<fo:table>
<fo:table-column column-width="50%" />
<fo:table-column column-width="50%" />
<fo:table-header>
<fo:table-row>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block font-weight="bold">Document Name</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block font-weight="bold">Document Type</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="/root/pages/page_12/sections/fwcF17DocumentUpload/data">
<fo:table-row>
<xsl:choose>
<xsl:when test="size > 0">
<fo:table-cell border-style="solid" padding="2pt">
<fo:block>
<xsl:value-of select="name" />
</fo:block>
</fo:table-cell>
</xsl:when>
<xsl:otherwise>
<fo:table-cell>
<fo:block>
</fo:block>
</fo:table-cell>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="size > 0">
<fo:table-cell border-style="solid" padding="2pt">
<fo:block>
<xsl:value-of select="documentType" />
</fo:block>
</fo:table-cell>
</xsl:when>
<xsl:otherwise>
<fo:table-cell>
<fo:block>
</fo:block>
</fo:table-cell>
</xsl:otherwise>
</xsl:choose>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:block>
</xsl:template>
</xsl:stylesheet>
I have tried putting in:
<fo:table-cell visilibity="hidden">
<fo:table-cell display="none">
<fo:table-cell height="0px">
Wrong output when there are empty cells:
Correct output when there are no empty cells:

Only create fo:table-row if your data fulfills the filter size > 0
You can do that by adding a predicate to your for-each.
In addition you can use that same predicate in the match, te ensure that there will be not a invalid fo:table constructed.
The xslt would then look like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" media-type="text/html" />
<xsl:template match="fwcF17Part35Page">
<xsl:apply-templates select="part35Details"/>
</xsl:template>
<xsl:template match="part35Details[/root/pages/page_12/sections/fwcF17DocumentUpload/data[size > 0]]">
<fo:block keep-together.within-page="always">
<fo:block padding="5pt"/>
<fo:block font-size="16pt" text-align="left">
Upload Documents - test
</fo:block>
<fo:block>
<fo:leader leader-pattern="rule" leader-length="100%" rule-style="solid" rule-thickness="2pt"/>
</fo:block>
<fo:block padding="8pt"/>
<fo:block background-color="#ebe8e8" font-size="10pt" font-weight="bold">
Document(s)
</fo:block>
<fo:block padding="4px" font-size="8pt" font-weight="normal" text-align="center">
<fo:table>
<fo:table-column column-width="50%" />
<fo:table-column column-width="50%" />
<fo:table-header>
<fo:table-row>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block font-weight="bold">Document Name</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block font-weight="bold">Document Type</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="/root/pages/page_12/sections/fwcF17DocumentUpload/data[size > 0]">
<fo:table-row>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block>
<xsl:value-of select="name" />
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block>
<xsl:value-of select="documentType" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:block>
</xsl:template>
</xsl:stylesheet>
It would be really helpful if you would add a minimal xml-source-sample to your question to better understand your xslt.
I.e: your template match: <xsl:template match="part35Details"> looks somewhat strange. The template does not use the context.

Related

xsl:choose find the first position of elements but not the second

I would like to code an XSLT to convert an XML document to an XML-FO document, in order to generate a PDF.
This Image shows the current Output
So my Table has 3 columns. In the first 4 lines the second and third columns are merged.
My XML document looks like this:
<WS-Standards>
<tags>
<tag category = "parameters" > <!-- WS_Beer_Type -->
<tag_name>WS_Beer_TypeX</tag_name> <!-- browsename -->
<tag_number>30004</tag_number>
<datatype>Unsigned32</datatype>
<accessrights>RW</accessrights>
<names>
<name language="DE">Biersorte</name>
<name language="EN">Beer Type</name>
</names>
</tag>
</tags>
</WS-Standards>
My current XSLT document:
<?xml version="1.0" encoding="UTF-8" ?>
<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" version="1.0" indent="yes"/>
<xsl:template match="WS-Standards">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master page-height="297mm" page-width="210mm"
margin="5mm 25mm 5mm 25mm" master-name="PageMaster">
<fo:region-body margin="20mm 0mm 20mm 0mm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="PageMaster">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:apply-templates select="tags"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="tags">
<fo:block>
<xsl:apply-templates select="tag"/>
</fo:block>
</xsl:template>
<xsl:template match="tag">
<fo:block space-before="6pt" border-top="3pt solid green">
<fo:table>
<fo:table-column column-number="1" column-width="20%" border-style="solid"
border-width="1pt"/>
<fo:table-column column-number="2" column-width="10%" border-style="solid"
border-width="1pt"/>
<fo:table-column column-number="3" column-width="70%" border-style="solid"
border-width="1pt"/>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
<xsl:template match="tag_name">
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block> Tag Name </fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" number-columns-spanned="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="tag_number">
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block> Tag-Nummer </fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" number-columns-spanned="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="datatype">
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block> Datentyp </fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" number-columns-spanned="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="accessrights">
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block> Zugriffsrechte </fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" number-columns-spanned="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="names">
<xsl:choose>
<xsl:when test="number(./name/position()) = 1">
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block> Name </fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="./name/#language"/>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="3" border="1pt solid black">
<fo:block>
<xsl:value-of select="./name"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:when>
<xsl:otherwise>
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block> NameXXX </fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="./name/#language"/>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="3" border="1pt solid black">
<fo:block>
<xsl:value-of select="./name"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="p">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="b">
<fo:inline font-weight="bold">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
</xsl:stylesheet>
My question is about the names element for different languages.
So the first Line in the table of the names element looks like this:
-----------------------------
|Name | DE | Biersorte |
-----------------------------
But I`m missing the second line:
-----------------------------
| | EN | beer type |
-----------------------------
What am I doing wrong with the xsl:choose->when->otherwise function?
I would be happy about a tip.
The relevant code is in a template matching names, but there is only one such element in your XSLT and so it will only be called once.
The expression number(./name/position()) = 1 in this context is simply asking "For this names element, is there a name element in position 1", which is true, and so the xsl:when gets executed.
Your code really needs to be in a block where name is selected. Try this XSLT (which also removes the code duplication).
<xsl:template match="names">
<xsl:for-each select="name">
<fo:table-row>
<fo:table-cell column-number="1" border="1pt solid black">
<fo:block>
<xsl:if test="position() = 1">Name</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="2" border="1pt solid black">
<fo:block>
<xsl:value-of select="#language"/>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="3" border="1pt solid black">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</xsl:template>

show list as table in xsl-fo

I'm trying to render this list as a table in xsl-fo
<ul class="tablelist">
<li class="a">A</li>
<li class="a">A
</li>
<li class="b">B
</li>
<li class="b">B
</li>
<li class="a">A</li>
<li class="b">B</li>
<li class="a">A</li>
</ul>
All the ones with class A in the left column, all the ones with class B in the right column.
My current solution:
<fo:table>
<fo:table-column column-number="1" column-width="30mm"/>
<fo:table-column column-number="2" />
<fo:table-body>
<xsl:for-each select="li[#class='a']">
<fo:table-row>
<fo:table-cell column-number="1">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
<xsl:for-each select="li[#class='b']">
<fo:table-row>
<fo:table-cell column-number="2">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
... doesnt work, of course. What would I need to change?
Thanks for help!
EDIT:
Desired output in this case would be:
<fo:table>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>
A
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
B
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
A
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
B
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
A
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
B
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
A
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block/
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
because there are four class="a" and three class="b"elements. So, 4 rows in total, in 4 rows the left cell is A and in three of those rows, the right column is B.
Hope, it is a bit clearer now!
Here's another way you could look at it:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<table>
<xsl:call-template name="generate-rows">
<xsl:with-param name="left" select="ul/li[#class='a']"/>
<xsl:with-param name="right" select="ul/li[#class='b']"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="generate-rows">
<xsl:param name="left"/>
<xsl:param name="right"/>
<xsl:param name="i" select="1"/>
<xsl:if test="$i <= count($left) or $i <= count($right)">
<row>
<cell><xsl:value-of select="$left[$i]"/></cell>
<cell><xsl:value-of select="$right[$i]"/></cell>
</row>
<xsl:call-template name="generate-rows">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="right" select="$right"/>
<xsl:with-param name="i" select="$i + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
One option is to use position() to apply-templates to the element with the opposite class that's in the same position.
If you know that there will always be more a class elements than b class elements (or if you don't care what happens to the remaining b class elements), you could do something like this:
<xsl:template match="ul[#class='tablelist']">
<fo:table>
<fo:table-column column-number="1" column-width="30mm"/>
<fo:table-column column-number="2" />
<fo:table-body>
<xsl:for-each select="li[#class='a']">
<xsl:variable name="pos" select="position()"/>
<fo:table-row>
<fo:table-cell column-number="1">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="2">
<fo:block>
<xsl:apply-templates select="../li[#class='b'][position()=$pos]"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
If you do care about those b class elements, when there are more b than a, you could do something like this:
<xsl:template match="ul[#class='tablelist']">
<fo:table>
<fo:table-column column-number="1" column-width="30mm"/>
<fo:table-column column-number="2" />
<fo:table-body>
<xsl:choose>
<xsl:when test="count(li[#class='a']) >= count(li[#class='a'])">
<xsl:apply-templates select="li[#class='a']" mode="createRow"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="li[#class='b']" mode="createRow"/>
</xsl:otherwise>
</xsl:choose>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="li[#class='a']" mode="createRow">
<xsl:variable name="pos" select="position()"/>
<fo:table-row>
<fo:table-cell column-number="1">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="2">
<fo:block>
<xsl:apply-templates select="../li[#class='b'][position()=$pos]"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="li[#class='b']" mode="createRow">
<xsl:variable name="pos" select="position()"/>
<fo:table-row>
<fo:table-cell column-number="1">
<fo:block>
<xsl:apply-templates select="../li[#class='a'][position()=$pos]"/>
</fo:block>
</fo:table-cell>
<fo:table-cell column-number="2">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

how to do zebra stripe in xslt

I'm trying do zebra stripe for my pdf file. The XML like as below:
<root>
<order>
<attribute1>1</attribute1>
<attribute2>2</attribute2>
<attribute3>0</attribute3>
<attribute4>4</attribute4>
<attribute5/>
</order>
</root>
The attribute3 isn't appeared if the value is '0'. Also attribute5 isn't appear if there is no value for it. So I cannot do zebra stripe like as below:
<fo:table-row (colored)>
<fo:table-cell>
<fo:block>
<xsl:text>Attribute1</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>...</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row (non colored)>
<fo:table-cell>
<fo:block>
<xsl:text>Attribute2</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>...</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
Because attribute3 and attribute5 is not always appeared in pdf file. How can I do it?
What you need to do here, is first use xsl:apply-templates to select only the child nodes you wish to output (This assumes you are currently positioned on the order element:
<xsl:apply-templates select="*[normalize-space()][. != '0']" />
Then you have a template to match child elements of order elements, like so:
Within this template, you can then output the table-row, and to do the 'coloured' attribute, you can test the 'position' of the current attribute, to see if it is odd or even:
<fo:table-row>
<xsl:if test="position() mod 2 = 0">
<xsl:attribute name="colour">zebra</xsl:attribute>
</xsl:if>
Try this XSLT as a start
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="order">
<fo:table>
<xsl:apply-templates select="*[normalize-space()][. != '0']" />
</fo:table>
</xsl:template>
<xsl:template match="order/*">
<fo:table-row>
<xsl:if test="position() mod 2 = 0">
<xsl:attribute name="colour">zebra</xsl:attribute>
</xsl:if>
<fo:table-cell>
<fo:block>
<xsl:value-of select="local-name()" />
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>...</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
Obviously you would use the correct xsl-fo styling here, and not literally the 'colour=zebra' attribute as shown here....

Wrap within table-cell with long word in FOP

I have a table in FOP and it is working nicely until I get a very long word. The word then overwrites the cell ending in the table. I tried the wrap-option="wrap" within the table-cell and/or the block of the cell but it doesn't work
**Total Edit**
since I guess it is to complicated to just show bits here is the complete xsl file:
<?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:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" />
<xsl:param name="tableCell" select="'1.0'" />
<!-- Globale Variablen START -->
<xsl:param name="tabbgcolor" select="'#EEEEEE'" />
<!-- Globale Variablen ENDE -->
<xsl:template match="/datasheet">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<fo:layout-master-set>
<fo:simple-page-master page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm" master-name="first">
<fo:region-body margin-top="20mm" margin-bottom="20mm" />
<fo:region-before extent="15mm" />
<fo:region-after extent="15mcm" />
</fo:simple-page-master>
<fo:simple-page-master master-name="new" margin-right="1.0cm" margin-left="1.0cm" margin-bottom="1cm" margin-top="1cm" page-height="21cm" page-width="29.7cm">
<fo:region-body margin-top="30mm" margin-bottom="20mm" />
<fo:region-before extent="30mm" />
<fo:region-after extent="15mm" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence language="de" country="DE" master-reference="new" initial-page-number="1">
<fo:static-content flow-name="xsl-region-before">
<fo:block text-align="center" font-size="12pt" padding="5pt" font-weight="bold">
<xsl:value-of select="title" />
</fo:block>
<fo:block text-align="right" font-size="12pt" padding="5pt" font-weight="bold">
<xsl:value-of select="date" />
</fo:block>
<fo:block text-align="right" font-size="12pt" padding="0pt" font-weight="bold">
<xsl:value-of select="time" />
</fo:block>
<fo:block>
<fo:leader leader-length="100%" leader-pattern="rule" rule-thickness="2pt" color="black" />
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block text-align="center">
Seite
<fo:page-number />
von
<fo:page-number-citation ref-id="TheVeryLastPage" />
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:leader />
</fo:block>
<fo:block>
<fo:leader />
</fo:block>
<fo:block>
<fo:leader />
</fo:block>
<fo:block font-weight="bold" padding="5pt" padding-top="25pt">
Jahre <xsl:value-of select="fromYear" /> bis <xsl:value-of select="toYear" />
</fo:block>
<fo:block text-align="center">
<xsl:choose>
<xsl:when test="dataList != ''">
<fo:table table-layout="fixed" width="100%" border-style="solide" border-width="1pt">
<fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
<fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
<fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
<fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
<fo:table-header>
<fo:table-row>
<fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
<fo:block>
Cell1
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
<fo:block>
Cell2
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
<fo:block>
Cell3
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
<fo:block>
Cell4
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="dataList">
<fo:table-row>
<fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
<fo:block text-align="left">
<xsl:value-of select="data1" />
</fo:block>
</fo:table-cell>
<fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
<fo:block text-align="left">
<xsl:value-of select="data2" />
</fo:block>
</fo:table-cell>
<fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
<fo:block text-align="left">
<xsl:value-of select="data3" />
</fo:block>
</fo:table-cell>
<fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
<fo:block text-align="left">
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="data4"/>
</xsl:call-template>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:when>
<xsl:otherwise>
<fo:block padding="6cm" text-align="center" font-weight="bold" font-size="16pt">No data.
</fo:block>
</xsl:otherwise>
</xsl:choose>
</fo:block>
<fo:block id="TheVeryLastPage">
</fo:block>
</fo:flow>
</fo:page-sequence>
<!-- ___________________________________________________________________________________________________________ -->
</fo:root>
</xsl:template>
<xsl:template name="intersperse-with-zero-spaces">
<xsl:param name="str"/>
<xsl:variable name="spacechars">
      
     ​
</xsl:variable>
<xsl:if test="string-length($str) > 0">
<xsl:variable name="c1" select="substring($str, 1, 1)"/>
<xsl:variable name="c2" select="substring($str, 2, 1)"/>
<xsl:value-of select="$c1"/>
<xsl:if test="$c2 != '' and
not(contains($spacechars, $c1) or
contains($spacechars, $c2))">
<xsl:text>​</xsl:text>
</xsl:if>
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="substring($str, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The cell data4 is the one with the problems.... like 255 digits or characters at once with no hyphen oder space.
The input is from a database but could be like:
<datasheet>
<dataList>
<data1>intro</data1>
<data2>section</data2>
<data3>cutters</data3>
<data4>743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348</data4>
</dataList>
</datasheet>
the result should be a table like:
|cell1 |cell2 |cell3 |cell4 |
_________________________________
|intro |section|cutters|7435767|
|4687635|
|7467569|
|3846576|
_________________________________
and so on in cell 4
Now the above works
<xsl:template name="intersperse-with-zero-spaces">
<xsl:param name="str"/>
<xsl:variable name="spacechars">
      
     ​
</xsl:variable>
<xsl:if test="string-length($str) > 0">
<xsl:variable name="c1" select="substring($str, 1, 1)"/>
<xsl:variable name="c2" select="substring($str, 2, 1)"/>
<xsl:value-of select="$c1"/>
<xsl:if test="$c2 != '' and
not(contains($spacechars, $c1) or
contains($spacechars, $c2))">
<xsl:text>​</xsl:text>
</xsl:if>
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="substring($str, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
calling place use to call like below:
<fo:block text-align="left">
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="data4"/>
</xsl:call-template>
</fo:block>
I tested, it's working fine.
One option would be for you to break up the long number/word in XSLT while you're transforming to FO. You'd have to decide where you want it to break.
See also:
XSL-FO fop. Long text flows into adjacent cells/block, obscuring stuff there
Update (copied from comment):
There must be copy/paste errors in the stylesheet... there is an <xsl:param>, which is only supposed to occur at the beginning of a template, in the middle of the template. The stylesheet is therefore invalid. Are there supposed to be two templates? Also, I don't yet see the template named intersperse-with-zero-spaces; but maybe you're still adding it.
Update 2:
The above has been fixed in the Question.
I had assumed the second template couldn't be intersperse-with-zero-spaces, since it was calling that template. It didn't occur to me that it was supposed to be a recursive template!
By the way, if you have the option of using XSLT 2.0, the intersperse-with-zero-spaces template could be replaced by a much more efficient regexp replace.
Add hyphenate="true", then it will automatically adjust the spaces in the table cell.
<fo:table-cell border-bottom-width="0px" border-left-width="0px"
border-right-width="0px" border-top-width="0px" font-size="9px"
padding-left="0px" border-style="solid" border-width="1pt"
border-color="white" padding-start="0px" padding-end="2px"
padding-before="0px" padding-after="0px" width="16%" display-align="center"
text-align="start" hyphenate="true">

xsl:for-each Split Records

I'm not sure if this is even possible but here we go.
I have an xml file:
<ROOT>
<MEM-STMT>
<COUNTRY>co</COUNTRY>
<CURRENCY>cu</CURRENCY>
<STMT>
<ST-NO>1</ST-NO>
<ST-DATE>21-JUL-11</ST-DATE>
<CC>21</CC>
<YY>11</YY>
<MM>07</MM>
<DD>21</DD>
</STMT>
<MEM-DET>
<MEM-NO>9</MEM-NO>
<MEM-PROD-LEV>24</MEM-PROD-LEV>
<MEM-OPTION>option</MEM-OPTION>
<MEM-EMP-NO/>
<MEM-EMP-NAME>name</MEM-EMP-NAME>
</MEM-DET>
<MEM-ADDR>
<MEM-NAME>name</MEM-NAME>
<MEM-ADDR1> Addr1</MEM-ADDR1>
<MEM-ADDR2> Addr2</MEM-ADDR2>
<MEM-ADDR3> Addr3</MEM-ADDR3>
<MEM-SUB> Sub</MEM-SUB>
<MEM-CITY> +2</MEM-CITY>
<MEM-REG> Employer:reg</MEM-REG>
<MEM-CNTRY/>
<MEM-PCODE/>
<MEM-EMPCODE/>
</MEM-ADDR>
<ACC>
<PROV>
<PR-NO>1</PR-NO>
<PR-NAME> pr</PR-NAME>
<REF-NO>1</REF-NO>
<CLM>
<REF>1</REF>
<CL-DEP-NO>04</CL-DEP-NO>
<CL-DEP-NAME>dep</CL-DEP-NAME>
<CL-DOS>10-APR-11</CL-DOS>
<CC>21</CC>
<YY>11</YY>
<MM>04</MM>
<DD>10</DD>
<CL-TAR-DRUG-CD>1 </CL-TAR-DRUG-CD>
<CL-TAR-DRUG-DESC>desc </CL-TAR-DRUG-DESC>
<CL-NO>1</CL-NO>
<CL-LINE>2</CL-LINE>
<CL-AMT>16.8</CL-AMT>
<CL-TAR-AMT>16.8</CL-TAR-AMT>
<CL-PAID-PROV>16.8</CL-PAID-PROV>
<CL-PAID-MEM>0</CL-PAID-MEM>
<CL-RSN/>
</CLM>
<CLM>
<REF>1</REF>
<CL-DEP-NO>04</CL-DEP-NO>
<CL-DEP-NAME>dep </CL-DEP-NAME>
<CL-DOS>20-APR-11</CL-DOS>
<CC>21</CC>
<YY>11</YY>
<MM>04</MM>
<DD>20</DD>
<CL-TAR-DRUG-CD>1 </CL-TAR-DRUG-CD>
<CL-TAR-DRUG-DESC>desc </CL-TAR-DRUG-DESC>
<CL-NO>1</CL-NO>
<CL-LINE>2</CL-LINE>
<CL-AMT>50.4</CL-AMT>
<CL-TAR-AMT>50.4</CL-TAR-AMT>
<CL-PAID-PROV>50.4</CL-PAID-PROV>
<CL-PAID-MEM>0</CL-PAID-MEM>
<CL-RSN/>
</CLM>
<TOTALS>
<TOT-AMT>67.2</TOT-AMT>
<TOT-TAR-AMT>67.2</TOT-TAR-AMT>
<TOT-PAID-PROV>67.2</TOT-PAID-PROV>
<TOT-PAID-MEM>0</TOT-PAID-MEM>
</TOTALS>
</PROV>
<PROV>
<PR-NO>2</PR-NO>
<PR-NAME> pr</PR-NAME>
<REF-NO>1</REF-NO>
<CLM>
<REF>1</REF>
<CL-DEP-NO>04</CL-DEP-NO>
<CL-DEP-NAME>dep</CL-DEP-NAME>
<CL-DOS>10-APR-11</CL-DOS>
<CC>21</CC>
<YY>11</YY>
<MM>04</MM>
<DD>10</DD>
<CL-TAR-DRUG-CD>1</CL-TAR-DRUG-CD>
<CL-TAR-DRUG-DESC>desc </CL-TAR-DRUG-DESC>
<CL-NO>1</CL-NO>
<CL-LINE>2</CL-LINE>
<CL-AMT>15</CL-AMT>
<CL-TAR-AMT>0</CL-TAR-AMT>
<CL-PAID-PROV>15</CL-PAID-PROV>
<CL-PAID-MEM>0</CL-PAID-MEM>
<CL-RSN/>
</CLM>
<TOTALS>
<TOT-AMT>15</TOT-AMT>
<TOT-TAR-AMT>0</TOT-TAR-AMT>
<TOT-PAID-PROV>15</TOT-PAID-PROV>
<TOT-PAID-MEM>0</TOT-PAID-MEM>
</TOTALS>
</PROV>
<PROV>
<PR-NO>1</PR-NO>
<PR-NAME> pr</PR-NAME>
<REF-NO>I0428202</REF-NO>
<CLM>
<REF>I0428202</REF>
<CL-DEP-NO>03</CL-DEP-NO>
<CL-DEP-NAME>dep</CL-DEP-NAME>
<CL-DOS>10-APR-11</CL-DOS>
<CC>21</CC>
<YY>11</YY>
<MM>04</MM>
<DD>10</DD>
<CL-TAR-DRUG-CD>2</CL-TAR-DRUG-CD>
<CL-TAR-DRUG-DESC>desc</CL-TAR-DRUG-DESC>
<CL-NO>112153</CL-NO>
<CL-LINE>217615</CL-LINE>
<CL-AMT>31.58</CL-AMT>
<CL-TAR-AMT>0</CL-TAR-AMT>
<CL-PAID-PROV>31.58</CL-PAID-PROV>
<CL-PAID-MEM>0</CL-PAID-MEM>
<CL-RSN/>
</CLM>
<TOTALS>
<TOT-AMT>31.58</TOT-AMT>
<TOT-TAR-AMT>0</TOT-TAR-AMT>
<TOT-PAID-PROV>31.58</TOT-PAID-PROV>
<TOT-PAID-MEM>0</TOT-PAID-MEM>
</TOTALS>
</PROV>
<PROV>
<PR-NO>1</PR-NO>
<PR-NAME> pr</PR-NAME>
<REF-NO>0027579</REF-NO>
<CLM>
<REF>1</REF>
<CL-DEP-NO>04</CL-DEP-NO>
<CL-DEP-NAME>dep</CL-DEP-NAME>
<CL-DOS>09-JUN-11</CL-DOS>
<CC>21</CC>
<YY>11</YY>
<MM>06</MM>
<DD>09</DD>
<CL-TAR-DRUG-CD>99200 </CL-TAR-DRUG-CD>
<CL-TAR-DRUG-DESC>desc</CL-TAR-DRUG-DESC>
<CL-NO>1</CL-NO>
<CL-LINE>1</CL-LINE>
<CL-AMT>12</CL-AMT>
<CL-TAR-AMT>0</CL-TAR-AMT>
<CL-PAID-PROV>12</CL-PAID-PROV>
<CL-PAID-MEM>0</CL-PAID-MEM>
<CL-RSN/>
</CLM>
<TOTALS>
<TOT-AMT>12</TOT-AMT>
<TOT-TAR-AMT>0</TOT-TAR-AMT>
<TOT-PAID-PROV>12</TOT-PAID-PROV>
<TOT-PAID-MEM>0</TOT-PAID-MEM>
</TOTALS>
</PROV>
</ACC>
<RSN-LIST>
<RSN-ERR>????</RSN-ERR>
<RSN-DESC/>
</RSN-LIST>
<FIN-OTHER>
<FIN-DATE/>
<FIN-AMT>0</FIN-AMT>
<FIN-TT/>
</FIN-OTHER>
<GTOTALS>
<GTOT-AMT>125.78</GTOT-AMT>
<GTOT-TAR-AMT>67.2</GTOT-TAR-AMT>
<GTOT-PAID-PROV>125.78</GTOT-PAID-PROV>
<GTOT-PAID-MEM>0</GTOT-PAID-MEM>
</GTOTALS>
<MEM-GTOT>
<M-MESSAGE/>
<M-TOT-PAID-MEM>0</M-TOT-PAID-MEM>
<M-PMT-METH/>
</MEM-GTOT>
<FIN-BAL>
<FIN-BDATE>21-JUL-11</FIN-BDATE>
<FIN-BAMT>0</FIN-BAMT>
<FIN-BTT/>
</FIN-BAL>
</MEM-STMT>
</ROOT>
& I'd like to split the records returned from it using the logic below:
If the xml file has 30 or more PROV-or-CLM-or-TOTATALS nodes then process only 30 PROV-or-CLM-or-TOTATALS nodes. Do this for the entire xml file in case where the number of remaining nodes is less than 30 process them to complete the transformation.
I'm using the following xsl to do this:
<xsl:template name="PROVIDER">
<fo:page-sequence master-reference="global">
<fo:flow flow-name="xsl-region-body">
<fo:wrapper font-size="7pt" font-family="Helvetica">
<fo:block-container >
<xsl:variable name="CURRENCYSYMBOL"><xsl:value-of select="ROOT/MEM-STMT/CURRENCY"/></xsl:variable>
<xsl:for-each select="ROOT/MEM-STMT/ACC/PROV">
<xsl:if test="(position() mod 30 = 1)">
<fo:block >
<fo:table table-layout="fixed" width="190mm" border-style="solid">
<fo:table-column column-width="22mm"/>
<fo:table-column column-width="16mm"/>
<fo:table-column column-width="18mm"/>
<fo:table-column column-width="39mm"/>
<!-- <fo:table-column column-width="15mm"/> -->
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="15mm"/>
<fo:table-header border="solid" >
<fo:table-row border-style="solid">
<fo:table-cell background-color="{$HeaderGray}" number-columns-spanned="9" padding="2pt">
<fo:block font-size="7pt" text-align="left" font-weight="bold">Provider:
<xsl:value-of select="PR-NO"/>-
<xsl:value-of select="PR-NAME"/>
<xsl:text>  </xsl:text> Ref No:
<xsl:value-of select="REF-NO"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row border-style="solid">
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Patient</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Serv Date</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Tariff/Drug</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Description</fo:block>
</fo:table-cell>
<!-- <fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Claim No</fo:block>
</fo:table-cell> -->
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Claim Amount</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Tariff Amount</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Paid Provider</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Paid Member</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Reason</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<xsl:for-each select="./CLM">
<xsl:if test="(position() mod 30 = 1)">
<fo:table-body font-size="7pt">
<fo:table-row>
<fo:table-cell padding="2pt" >
<fo:block>
<xsl:value-of select="CL-DEP-NAME"/><xsl:text>  </xsl:text>
<xsl:value-of select="CL-DEP-NO"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" >
<fo:block>
<xsl:value-of select="CL-DOS"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" >
<fo:block>
<xsl:value-of select="CL-TAR-DRUG-CD"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" >
<fo:block>
<xsl:value-of select="CL-TAR-DRUG-DESC"/>
</fo:block>
</fo:table-cell>
<!-- <fo:table-cell padding="2pt">
<fo:block>
<xsl:value-of select="CL-NO"/>
</fo:block>
</fo:table-cell> -->
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-AMT != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(CL-AMT,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-TAR-AMT != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(CL-TAR-AMT,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" >
<fo:block text-align="right">
<xsl:if test="CL-PAID-PROV != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(CL-PAID-PROV,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-PAID-MEM != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(CL-PAID-MEM,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-RSN != '????'">
<xsl:value-of select="CL-RSN"/>
</xsl:if>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="./TOTALS">
<xsl:if test="(position() mod 30 = 1)">
<fo:table-body font-size="7pt">
<fo:table-row border-style="solid">
<fo:table-cell padding="2pt" number-columns-spanned="4" >
<fo:block >Totals for Invoice</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" >
<fo:block text-align="right">
<!-- <xsl:if test="TOT-AMT != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(TOT-AMT,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell >
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-TAR-AMT != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(TOT-TAR-AMT,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-PAID-PROV != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(TOT-PAID-PROV,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-PAID-MEM != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of select="format-number(TOT-PAID-MEM,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</xsl:if>
</xsl:for-each>
</fo:table>
</fo:block>
</xsl:if>
</xsl:for-each>
</fo:block-container>
</fo:wrapper>
</fo:flow>
</fo:page-sequence>
My current scenario is such that the split doesn't work & I get the exception: Exception in thread "AWT-EventQueue-2" java.lang.OutOfMemoryError: Java heap space despite allocating -Xms/-Xmx2G memory.
Kamza, you had part of it right, but there are a few flaws in your approach. You start with a for-each on PROV elements, and within the for-each you have an if that causes output to be written only for PROV elements 1, 31, 61, etc. The nested for-each loops have a similar problem. Only CLM element 1, 31, 61, .. is written, like only TOTALS 1, 31, 61, ..
(Actually, I suspect there will only be one TOTALS within each PROV, so that would ok in your code.)
Furthermore, from what I understand from your description and the comments is that you are trying to write out 30 rows at a time, and start a new table, or even a new page after that, with another 30 rows, or what is left. Since no rows are written for the PROV element itself, I presume that it is just about CLM and TOTALS rows, where the count of 30 should include both.
What you need for that is an outer for-each loop that walks along all CLM and TOTALS elements. You can use this expression for that:
<xsl:for-each select="ROOT/MEM-STMT/ACC/PROV/*[self::CLM or self::TOTALS]">
Then use the if you already have to create a new table for row 1, 31, 61, ...
To fill the table with the first-next 30 items, you will need to look forward 30 positions. The PROV element is a bit of a problem here. Assuming CLM and TOTALS only occur within PROV, and PROV is not used elsewhere, you can reasonably safely use the following axis for that:
<xsl:for-each select="(following::*[self::CLM or self::TOTALS])[30 >= position()]">
That returns 30 items, both CLM and TOTALS mixed, but in document order. You need two extra if's (or a choose) to distinguish between these two, and output the appropriate table row:
<xsl:if test="self::CLM">
...
</xsl:if>
<xsl:if test="self::TOTALS">
...
</xsl:if>
In your code you have fo:table-body within the inner for-each loops, causing each table-row to be wrapped in a new table-body. That is unnecessary. Move the table-body to outside the inner loops. You would need only one wrapping both rows of CLM and TOTALS.
Finally, you write a new table for each 30th item. I think you want to start a new page-sequence as well. That will cause each table to be shown on a separate page. Putting things together, you get an XSLT similar to this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="HeaderGray" select="'gray'"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="global">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates select="/" mode="PROVIDER"/>
</fo:root>
</xsl:template>
<xsl:template match="/" mode="PROVIDER">
<xsl:variable name="CURRENCYSYMBOL" select="string(ROOT/MEM-STMT/CURRENCY)"/>
<xsl:for-each select="ROOT/MEM-STMT/ACC/PROV/*[self::CLM or self::TOTALS]">
<xsl:if test="position() mod 30 = 1">
<fo:page-sequence master-reference="global">
<fo:flow flow-name="xsl-region-body">
<fo:wrapper font-size="7pt" font-family="Helvetica">
<fo:block-container>
<fo:block>
<fo:table table-layout="fixed" width="190mm"
border-style="solid">
<fo:table-column column-width="22mm"/>
<fo:table-column column-width="16mm"/>
<fo:table-column column-width="18mm"/>
<fo:table-column column-width="39mm"/>
<!-- <fo:table-column column-width="15mm"/> -->
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="20mm"/>
<fo:table-column column-width="15mm"/>
<fo:table-header border="solid">
<fo:table-row border-style="solid">
<fo:table-cell background-color="{$HeaderGray}"
number-columns-spanned="9" padding="2pt">
<fo:block font-size="7pt" text-align="left"
font-weight="bold">Provider: <xsl:value-of
select="PR-NO"/>- <xsl:value-of select="PR-NAME"/>
<xsl:text>  </xsl:text> Ref No:
<xsl:value-of select="REF-NO"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row border-style="solid">
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Patient</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Serv Date</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Tariff/Drug</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Description</fo:block>
</fo:table-cell>
<!-- <fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold">Claim No</fo:block>
</fo:table-cell> -->
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Claim Amount</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Tariff Amount</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Paid Provider</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Paid Member</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" padding="2pt">
<fo:block text-align="center" font-weight="bold"
>Reason</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body font-size="7pt">
<xsl:for-each
select="(following::*[self::CLM or self::TOTALS])[30 >= position()]">
<xsl:if test="self::CLM">
<fo:table-row>
<fo:table-cell padding="2pt">
<fo:block>
<xsl:value-of select="CL-DEP-NAME"/>
<xsl:text>  </xsl:text>
<xsl:value-of select="CL-DEP-NO"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block>
<xsl:value-of select="CL-DOS"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block>
<xsl:value-of select="CL-TAR-DRUG-CD"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block>
<xsl:value-of select="CL-TAR-DRUG-DESC"/>
</fo:block>
</fo:table-cell>
<!-- <fo:table-cell padding="2pt">
<fo:block>
<xsl:value-of select="CL-NO"/>
</fo:block>
</fo:table-cell> -->
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-AMT != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(CL-AMT,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-TAR-AMT != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(CL-TAR-AMT,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-PAID-PROV != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(CL-PAID-PROV,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-PAID-MEM != '0'">
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(CL-PAID-MEM,'#,##0.00')"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<xsl:if test="CL-RSN != '????'">
<xsl:value-of select="CL-RSN"/>
</xsl:if>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
<xsl:if test="self::TOTALS">
<fo:table-row border-style="solid">
<fo:table-cell padding="2pt"
number-columns-spanned="4">
<fo:block>Totals for Invoice</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-AMT != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(TOT-AMT,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-TAR-AMT != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(TOT-TAR-AMT,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-PAID-PROV != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(TOT-PAID-PROV,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt">
<fo:block text-align="right">
<!-- <xsl:if test="TOT-PAID-MEM != '0'"> -->
<xsl:value-of select="$CURRENCYSYMBOL"/>
<xsl:value-of
select="format-number(TOT-PAID-MEM,'#,##0.00')"/>
<!-- </xsl:if> -->
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block> </fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:block-container>
</fo:wrapper>
</fo:flow>
</fo:page-sequence>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Note: I am not entirely convinced this will prevent you from getting an exception. You gave the impression it is because of your for-each loops, but it may be caused by something else. A table that is simply to big, or an fo document that is too large to render might be the cause as well, for instance. The above code should be fairly efficient. If it is still giving you trouble, try processing things from the command-line, perhaps even using different parsers.
hm.. I don't have time to look at your xslt in detail, but your logic should be possible using something like this:
<xsl:template match="(//PROV | //CLM | //TOTALS)[position() <= 30]">
<xsl:if test="local-name() = 'PROV'">
<!-- do stuff with PROV node -->
</xsl:if>
<xsl:if test="local-name() = 'CLM'">
<!-- do stuff with CLM node -->
</xsl:if>
<xsl:if test="local-name() = 'TOTALS'">
<!-- do stuff with TOTALS node -->
</xsl:if>
</xsl:template>
You could modify your xsl:for-each statements, to restrict them to the first 30 items:
<xsl:for-each select="ROOT/MEM-STMT/ACC/PROV[position()<=30]">
Or you could extract the xsl:for-each logic out into templates and then select only the first 30 to apply templates to:
<xsl:apply-templates select="ROOT/MEM-STMT/ACC/PROV[position()<=30]"/>