I am facing a problem trying to print one line only for a set of identical nodes and I could not find a similar post for identical nodes.
I have an input xml file containing a set of identical nodes, for instance it looks like:
<BookDetails>
<BK ISBN="123362367127" Shelf="Y" />
<BK ISBN="123362367127" Shelf="Y" />
<BK ISBN="123362367127" Shelf="Y" />
<BK ISBN="123362367127" Shelf="Y" />
</BookDetails>
What I want, is to print this book's information only once. I am thinking that a solution to my problem could be muenchian grouping, for instance group by ISBN value and then from the group print only the first one.
Based on that my code looks like that:
<xsl:key name="UniqueBKs" match="BK" use="@ISBN"/>
<xsl:template name="BookDetails">
<fo:table width="160mm" table-layout="fixed">
<fo:table-column column-width="80mm" column-number="1"/>
<fo:table-column column-width="80mm" column-number="2"/>
<fo:table-body>
<xsl:for-each select="BK[generate-id() = generate-id(key('UniqueBKs', @ISBN)[1])]">
<fo:table-row>
<xsl:apply-templates select="."/>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
and:
<xsl:template match="BK">
<fo:table-cell>
<fo:block font-family="arial" font-size="8pt" text-align="left">
<xsl:text>ISBN:</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-family="arial" font-size="8pt" text-align="right">
<xsl:value-of select="@ISBN"/>
</fo:block>
</fo:table-cell>
</xsl:template>
if my input xml file consists only from one BK element the code works fine. If I have more than one as shown above, Apache FOP returns me an error related with table-cells: "The column-number or number of cells in the row overflows the number of fo:table-columns specified for the table."
The error indicates that I am trying to put more table cells in my table row, while: a) I would expect only 1 row to be printed for this example b) more rows to be generated in case of more ISBNs, not more table cells.
Any help would be appreciated, thanks!