Martin Honnen created XALANJ-2716:
-------------------------------------
Summary: XSLT 3 for-each-group group-by and group-adjacent should
support XSLT 3 feature of composite grouping key
Key: XALANJ-2716
URL: https://issues.apache.org/jira/browse/XALANJ-2716
Project: XalanJ2
Issue Type: Wish
Security Level: No security risk; visible to anyone (Ordinary problems in
Xalan projects. Anybody can view the issue.)
Components: transformation, Xalan, Xalan-CmdLine
Affects Versions: The Latest Development Code
Reporter: Martin Honnen
Assignee: Gary D. Gregory
Attachments: cities2.xml, composite-grouping-key1.xsl
This is a suggestion/feature request for the XSLT 3.0 development branch of
XalanJ at [https://github.com/apache/xalan-java/tree/xalan-j_xslt3.0.]
The XSLT 3 spec introduced a new feature of a "composite" grouping key for
group-by and group-adjacent of the XSLT 3 for-each-group instruction.
[Definition: If either of the {{group-by}} or {{group-adjacent}} attributes is
present, then for each item in the
[population|https://www.w3.org/TR/xslt-30/#dt-population] a set of *grouping
keys* is calculated, as follows: the expression contained in the {{group-by}}
or {{group-adjacent}} attribute is evaluated; the result is atomized; and any
{{xs:untypedAtomic}} values are cast to {{{}xs:string{}}}. If
{{composite="yes"}} is specified, there is a single grouping key whose value is
the resulting sequence;
So far it seems Xalan's XSLT 3.0 branch doesn't support that as I get an error
trying it.
Test case:
Input sample:
{code:java}
<cities>
<city name="Milano" country="Italia" year="1950" pop="5.23"/>
<city name="Milano" country="Italia" year="1960" pop="5.29"/>
<city name="Padova" country="Italia" year="1950" pop="0.69"/>
<city name="Padova" country="Italia" year="1960" pop="0.93"/>
<city name="Paris" country="France" year="1951" pop="7.2"/>
<city name="Paris" country="France" year="1961" pop="7.6"/>
</cities>{code}
XSLT sample:
{code:java}
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:template match="/">
<html>
<head>
<title>XSLT 3.0 composite grouping key example</title>
</head>
<body>
<xsl:for-each-group select="cities/city" group-by="@name, @country"
composite="yes">
<p>
<xsl:value-of select="current-grouping-key()[1] || ', ' ||
current-grouping-key()[2] || ': ' ||
avg(current-group()/@pop)"/>
</p>
</xsl:for-each-group>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
{code}
Error from Xalan:
{code:java}
file:///C:/Users/foo/xslt30-spec-examples/composite-grouping-key1.xsl;
Zeilennummer13; Spaltennummer93; Zusõtzliche nicht zulõssige Token: ',', '@',
'country'
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XSLT 3.0 composite grouping key example</title>
</head>
<body>file:///C:/Users/foo/xslt30-spec-examples/composite-grouping-key1.xsl;
Zeilennummer17; Spaltennumme
r56; java.lang.ClassCastException: class org.apache.xpath.objects.XString
cannot be cast to class org.apache.xpath.objects.XNodeSet
(org.apache.xpath.objects.XString and org.apache.xpath.objects.XNodeSet are in
unnamed module of loader 'app'){code}
Expected output:
{code:java}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XSLT 3.0 composite grouping key example</title>
</head>
<body>
<p>Milano, Italia: 5.26</p>
<p>Padova, Italia: 0.81</p>
<p>Paris, France: 7.4</p>
</body>
</html>{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]