Martin Honnen created XALANJ-2715:
-------------------------------------

             Summary: for-each-group where group-by expression returns a 
sequence of more than one item gives wrong result
                 Key: XALANJ-2715
                 URL: https://issues.apache.org/jira/browse/XALANJ-2715
             Project: XalanJ2
          Issue Type: Bug
      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: group-by-to-multiple-groups.xsl, titles.xml

This is a bug report on the XSLT 3 branch 
[https://github.com/apache/xalan-java/tree/xalan-j_xslt3.0|https://github.com/apache/xalan-java/tree/xalan-j_xslt3.0.]

In XSLT 2/3, the group-by expression can evaluate to a sequence of more than 
one item, if, for a certain item in the grouping population, a sequence of more 
than item is returned by the group by expression, than that items has to be 
inserted in each group formed by one of the grouping keys returned by the 
group-by expression.

To cite [https://www.w3.org/TR/xslt-30/#xsl-for-each-group:]

If the {{group-by}} attribute is present, and if the {{composite}} attribute is 
omitted or takes the value {{{}no{}}}, then an item in the population may have 
multiple grouping keys: that is, the {{group-by}} expression evaluates to a 
sequence, and each item in the sequence is treated as a separate grouping key. 
The item is included in as many groups as there are distinct grouping keys 
(which may be zero).

 

The current XSLT 3 branch of Xalan doesn't seem to take that into account, it 
seems an item in the grouping population is put into exactly one group, even if 
its group-by expression returns a set of multiple, distinct grouping keys.

Test case (in parts taken from 
[https://www.w3.org/TR/xslt-30/#grouping-examples):]

Input XML:


{code:java}
<titles>
    <title>A Beginner's Guide to <ix>Java</ix></title>
    <title>Learning <ix>XML</ix></title>
    <title>Using <ix>XML</ix> with <ix>Java</ix></title>
</titles>{code}

XSLT code:

 

 
{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:output indent="yes"/>
<xsl:template match="/">
  <html>
    <head>
      <title>XSLT 3.0 group-by to multiple groups</title>
    </head>
    <body>
      <xsl:apply-templates/>
    </body>
  </html>
</xsl:template>
<xsl:template match="titles">
    <xsl:for-each-group select="title" group-by="ix">
      <h2><xsl:value-of select="current-grouping-key()"/></h2>
      <xsl:for-each select="current-group()">
        <p><xsl:value-of select="."/></p>
      </xsl:for-each>
    </xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
{code}
 



Result with Xalan XSLT 3.0 branch:


{code:java}
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XSLT 3.0 group-by to multiple groups</title>
</head>
<body>
<h2>Java</h2>
<p>A Beginner's Guide to Java</p>
<h2>XML</h2>
<p>Learning XML</p>
<p>Using XML with Java</p>
</body>
</html>{code}

Expected result:
{code:java}
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>XSLT 3.0 group-by to multiple groups</title>
   </head>
   <body>
      <h2>Java</h2>
      <p>A Beginner's Guide to Java</p>
      <p>Using XML with Java</p>
      <h2>XML</h2>
      <p>Learning XML</p>
      <p>Using XML with Java</p>
   </body>
</html>{code}
 

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xalan.apache.org
For additional commands, e-mail: dev-h...@xalan.apache.org

Reply via email to