views:

156

answers:

0

How can I create a table containing empty cells from data organized in rows and lines? To make things even more complicated, the lines should appear in the order given by a sequence. Here is a minimalistic example of input data:

<?xml version="1.0"?>
<matrix>
    <row>
        <line nr="1">A1</line>
        <line nr="2">B1</line>
    </row>
    <row>
        <line nr="3">C2</line>
    </row>
    <row>
        <line nr="1">A3</line>
        <line nr="2">B3</line>
        <line nr="3">C3</line>
    </row>
    <sequence>
        <element nr="3"/>
        <element nr="1"/>
        <element nr="2"/>
    </sequence>
</matrix>

The resulting table should look like this:

|  |C2|C3|
|A1|  |A3|
|B1|  |B3|

In XSL I can iterate over the sequence elements and use the current() function to select the desired line:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xsl:output version="1.0" omit-xml-declaration="yes" media-type="text/plain"/>
    <xsl:template match="/">
        <xsl:for-each select="matrix/sequence/element">
            <xsl:text>|</xsl:text><xsl:value-of select="/matrix/row[position()=1]/line[@nr=current()/@nr]"/>
            <xsl:text>|</xsl:text><xsl:value-of select="/matrix/row[position()=2]/line[@nr=current()/@nr]"/>
            <xsl:text>|</xsl:text><xsl:value-of select="/matrix/row[position()=3]/line[@nr=current()/@nr]"/>
            <xsl:text>|
</xsl:text>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Unfortunately, current() is a XSL-extension to XPath and cannot be used in Jasper Reports. I tried using temporary variables and sub-reports to no avail. A guru-hint to bend my mind in the right direction would be highly appreciated.

Thanks, Frank