错误:'不支持的XSL元素'http://www.w3.org/1999/XSL/Transform:for-each-group''

Kar*_*yan 1 xml xslt xslt-1.0

我正在使用Java通过XSL从XML文档生成PDF,并且出现以下错误:

错误:“不支持的XSL元素” http://www.w3.org/1999/XSL/Transform:for-each-group

请在下面找到我的XSL样式表

<?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>
Run Code Online (Sandbox Code Playgroud)

Mad*_*sen 5

您的样式表声明为version="3.0"。为了使用,您将需要至少支持XSLT 2.0的处理器xsl:for-each-group

如果您使用的是JRE Xalan的默认XSLT处理器,那么您将被降级为XSLT 1.0。

更新您的代码/配置,以使用Saxon作为XSLT处理器,以执行XSLT 2.0或3.0样式表。在Java中,有多种方法可以将Saxon设置为XSLT处理器。这从@Wayne伯克特答案枚举它们并提供了示例。