1
votes

I am generating a PDF from an XML document via XSL using Java and I am getting the following error:

ERROR: 'Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:for-each-group''

Please find my below XSL stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0">

  <xsl:param name="rows-per-page" select="4"/>

  <xsl:output method="html" indent="yes" html-version="5"/>

    <xsl:template match="/receipt">
        <html>
            <head>
            <style>
                @page {size: a4 landscape;}
                tbody { page-break-after: always; }
            </style>
            </head>
            <body>

                <table >
                    <thead>
                        <tr >
                            <th >Line</th>
                            <th>Item Code</th>
                        </tr>
                    </thead>
                  <xsl:for-each-group select="order/page/line_number" group-adjacent="(position() - 1) idiv $rows-per-page">
                      <tbody>
                          <xsl:apply-templates select="current-group()"/>
                      </tbody>
                 </xsl:for-each-group>
                </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="line_number">
        <tr style="font-size: 9px;">
            <td><xsl:value-of select="." /></td>
            <td><xsl:value-of select="following-sibling::product_code[1]" /></td>
        </tr>
    </xsl:template>

</xsl:stylesheet>
1

1 Answers

6
votes

Your stylesheet is declared as version="3.0". You will need a processor that supports at least XSLT 2.0 in order to use xsl:for-each-group.

If you are using the default XSLT processor from the JRE, Xalan, then you are relegated to XSLT 1.0.

Update your code/config to use Saxon as your XSLT processor in order to execute XSLT 2.0 or 3.0 stylesheets. There are a number of ways in which to set Saxon as the XSLT processor in Java. This answer from @Wayne Burkett enumerates them and provides examples.