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

时间:2018-05-08 01:15:01

标签: 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>

1 个答案:

答案 0 :(得分:4)

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

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

更新您的代码/配置以使用Saxon作为您的XSLT处理器,以便执行XSLT 2.0或3.0样式表。有许多方法可以将Saxon设置为Java中的XSLT处理器。这个answer from @Wayne Burkett列举了它们并提供了示例。