【发布时间】:2015-02-21 15:16:59
【问题描述】:
我正在尝试将 Saxon 与 XSLT 样式表一起使用,并使用 XSLT2 规范 (http://www.w3.org/TR/xslt20/#xsl-for-each-group) 中的代码示例
<table xsl:version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<tr>
<th>Position</th>
<th>Country</th>
<th>City List</th>
<th>Population</th>
</tr>
<xsl:for-each-group select="cities/city" group-by="@country">
<tr>
<td><xsl:value-of select="position()"/></td>
<td><xsl:value-of select="@country"/></td>
<td>
<xsl:value-of select="current-group()/@name" separator=", "/>
</td>
<td><xsl:value-of select="sum(current-group()/@pop)"/></td>
</tr>
</xsl:for-each-group>
</table>
我在 pom.xml 中使用以下内容
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>9.6.0-3</version>
</dependency>
运行它的代码是:
@Test
public void testSaxonXslt2GroupTest1() throws Exception {
File xml_file = Fixtures.XSLT2_TEST1_XML;
File xsl_file = Fixtures.XSLT2_TEST1_XSL;
TransformerFactory tfactory = net.sf.saxon.TransformerFactoryImpl.newInstance();
Transformer transformer = tfactory.newTransformer(new StreamSource(xsl_file));
File saxonDir = new File("target/saxon/");
saxonDir.mkdirs();
try {
transformer.transform(new StreamSource(xml_file),
new StreamResult(new FileOutputStream(new File(saxonDir, "test1.xml"))));
} catch (Throwable t) {
t.printStackTrace();
}
}
这会在输出控制台上引发错误
SystemId Unknown; Line #13; Column #70; Could not find function: current-group
SystemId Unknown; Line #13; Column #70; function token not found.
(Location of error unknown)java.lang.NullPointerException
我正在使用的 Saxon 版本中是否缺少此功能,还是我做错了什么?
【问题讨论】:
-
我不认为这会造成麻烦,但你为什么指定
version="1.0"? -
我认为这是一个转录错误,应该是 2.0。我会检查我的实际代码
-
我 am 使用 xsl:version="2.0" 在本地运行它
-
我正在尝试重现这一点,但由于 XSLT 具有
<xsl:value-of select="current-group()/@name" separator=",">,因此该示例甚至不是格式正确的。当我将代码更正为<xsl:value-of select="current-group()/@name" separator=","/>时,Saxon 会输出一个结果,至少从命令行运行它。 -
感谢您的耐心等待。我的代码具有良好的 XML/XSL 格式。我会重新粘贴...
标签: xml maven xslt-2.0 saxon xslt-grouping