i have two for loops one is to print heading and the other loop is to print the corresponding values altogether in a tabular format.see the following code:
<fo:table>
<fo:table-body>
<xsl:for-each select="./list">
<xsl:if test="position()<= 1">
<fo:table-row>
<xsl:for-each select="./item">
<xsl:if test="position() = 1 " >
<fo:table-cell text-align="center" width="auto">
<fo:block color="#000000" font-family="Helvetica" font-size="11pt" font-weight="700" padding="5px" space-before="5px" space-after="5px"> <xsl:value-of select="val" /> </fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 2 or position() = 7 or position() = 12" >
<fo:table-cell text-align="center" width="auto">
<fo:block color="#541f84" font-family="Helvetica" font-size="11pt" font-weight="700" padding="5px" space-before="5px" space-after="5px"><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 3 or position() = 8 or position() = 13 or position() = 17" >
<fo:table-cell text-align="center" width="auto">
<fo:block color="#bd5b10" font-family="5px" font-size="11pt" font-weight="700" padding="5px" space-before="5px" space-after="5px"><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 4 or position() = 9 or position() = 14 or position() = 18" >
<fo:table-cell text-align="center" width="auto">
<fo:block color="#147993" font-family="5px" font-size="11pt" font-weight="900" padding="5px" space-before="5px" space-after="5px"><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 5 or position() = 10 or position() = 15 or position() = 19">
<fo:table-cell text-align="center" width="auto">
<fo:block color="#38441a" font-family="5px" font-size="11pt" font-weight="900" padding="5px" space-before="5px" space-after="5px"><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test=" position() = 6 or position() = 11 or position() = 16" >
<fo:table-cell text-align="center" >
<fo:block color="#656565" font-family="5px" font-size="11pt" font-weight="900" padding="5px" space-before="5px" space-after="5px"><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = last()" >
<xsl:variable name="count" select="position()" />
<fo:table-cell text-align="center" width="auto">
<fo:block color="#38441a" font-family="5px" font-size="11pt" font-weight="900" padding="5px" space-before="5px" space-after="5px"><xsl:value-of select="position()" /></fo:block>
</fo:table-cell>
</xsl:if>
</xsl:for-each>
</fo:table-row>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="./list">
<xsl:if test="position()!=1">
<fo:table-row>
<xsl:for-each select="./item">
<xsl:if test="position() = 1 or position() = 6 or position() = 11 or position() = 16">
<fo:table-cell border="1px" text-align="center" width="auto" background-color="#c0c0c0" border-color="#1d467b" border-width="1px" border-style="solid" >
<fo:block white-space-treatment="preserve" font-family="5px" font-size="9pt" > <xsl:value-of select="val" /> </fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 2 or position() = 7 or position() = 12 or position() = 17">
<fo:table-cell border="1px" text-align="center" width="auto" background-color="#b3a1c7" border-color="#1d467b" border-width="1px" border-style="solid" >
<fo:block font-family="5px" font-size="9pt" ><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 3 or position() = 8 or position() = 13">
<fo:table-cell border="1px" text-align="center" width="auto" background-color="#fabf8f" border-color="#1d467b" border-width="1px" border-style="solid" >
<fo:block font-family="5px" font-size="9pt" ><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 4 or position() = 9 or position() = 14">
<fo:table-cell border="1px" text-align="center" width="auto" background-color="#91cddb" border-color="#1d467b" border-width="1px" border-style="solid" >
<fo:block font-family="5px" font-size="9pt" ><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
<xsl:if test="position() = 5 or position() = 10 or position() = 15">
<fo:table-cell border="1px" text-align="center" width="auto" background-color="#c3d69b" border-color="#1d467b" border-width="1px" border-style="solid" >
<fo:block font-family="5px" font-size="9pt" ><xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:if>
</xsl:for-each>
</fo:table-row>
</xsl:if>
</xsl:for-each>
</fo:table-body>
</fo:table>
but here problem is some times in the first node the number of items coming from xsl is differ from the number of items in the rest of nodes.
now you can observe there is no tables cells appearing under v10 and v11,i know this happening because in the first node the no of items coming are 13 and for the rest of nodes no of items in each node are 11.. but any how even though the number of items differ from one node to another still i want table completely. like the number of columns should be equal to number of headings.
i thought to calculate number of iterations in first loop and then number of iterations in second loop and then by subtracting them together and then thought to execute same table cell the rest of times but i couldn't do.
and the xml input is as follows:
<records>
<end-date>28-Jan-2014</end-date>
<month>January</month>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>Subject</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V2</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V2</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V3</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V3</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V4</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V5</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V6</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V7</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V8</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V9</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V10</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>V11</val>
</item>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>999870017</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>01-Jan-2014 (6 Months after Day 1 +/- 4 Weeks)</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>999870018</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>01-Jan-2014 (6 Months after Day 1 +/- 4 Weeks)</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>999870020</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>01-Jan-2014 (6 Months after Day 1 +/- 4 Weeks)</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item"/>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val> </val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
<val>01-Jan-2014 (36 Months after Day 1 +/- 4 Weeks)</val>
</item>
</list>
<start-date>01-Jan-2014</start-date>
can any one help in this. thanks
Here is a different approach, using an iterator to count up to the number of items in the first list:
A simple solution is to iterate over the items in the heading list and create a cell for each - regardless of the list you are processing. Then get the value from the corresponding item in the current list - if it exists. Here is a simplified example, creating an HTML table: