You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2023/12/28 12:00:37 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: improvements to xsl:for-each-group implementation, when grouping key is result of xpath function fn:node-name()
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
new ae74dd6a improvements to xsl:for-each-group implementation, when grouping key is result of xpath function fn:node-name()
new eed6d47f Merge pull request #145 from mukulga/xalan-j_xslt3.0_mukul
ae74dd6a is described below
commit ae74dd6a1c9479c0d616e78f7e2872b37b97b187
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Thu Dec 28 17:27:04 2023 +0530
improvements to xsl:for-each-group implementation, when grouping key is result of xpath function fn:node-name()
---
lib/xpath31_types.jar | Bin 51525 -> 51572 bytes
.../apache/xalan/templates/ElemForEachGroup.java | 10 ++++-
tests/grouping/gold/test29.out | 6 +++
tests/grouping/test29.xml | 4 ++
tests/grouping/test29.xsl | 41 +++++++++++++++++++++
tests/org/apache/xalan/xslt3/GroupingTests.java | 10 +++++
6 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/lib/xpath31_types.jar b/lib/xpath31_types.jar
index e142252e..7513b271 100644
Binary files a/lib/xpath31_types.jar and b/lib/xpath31_types.jar differ
diff --git a/src/org/apache/xalan/templates/ElemForEachGroup.java b/src/org/apache/xalan/templates/ElemForEachGroup.java
index 0bc49b66..6d88420d 100644
--- a/src/org/apache/xalan/templates/ElemForEachGroup.java
+++ b/src/org/apache/xalan/templates/ElemForEachGroup.java
@@ -806,15 +806,21 @@ public class ElemForEachGroup extends ElemTemplateElement
*
* For the purpose of, evaluating grouping key XPath expressions for xsl:for-each-group,
* the following data types are currently supported : string, number, boolean, xs:date,
- * xs:dateTime, xs:time. Any other data type for grouping key is converted to a
+ * xs:dateTime, xs:time, xs:QName. Any other data type for grouping key is converted to a
* string value.
*/
private Object getXPathEvaluationRawResult(XObject xpathEvalResult) {
Object xpathRawResult = null;
- if ((xpathEvalResult instanceof XString) || (xpathEvalResult instanceof XSQName)) {
+ if (xpathEvalResult instanceof XString) {
xpathRawResult = xpathEvalResult.str();
}
+ else if (xpathEvalResult instanceof XSQName) {
+ XSQName qName = (XSQName)xpathEvalResult;
+ String localName = qName.getLocalName();
+ String namespaceUri = qName.getNamespaceUri();
+ xpathRawResult = localName + ((namespaceUri == null) ? "" : ":" + namespaceUri);
+ }
else if (xpathEvalResult instanceof XSString) {
xpathRawResult = ((XSString)xpathEvalResult).stringValue();
}
diff --git a/tests/grouping/gold/test29.out b/tests/grouping/gold/test29.out
new file mode 100644
index 00000000..b2ec9006
--- /dev/null
+++ b/tests/grouping/gold/test29.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><groups>
+ <group node-name="p:http://www.w3.org/1999/xhtml">
+ <p xmlns="http://www.w3.org/1999/xhtml">Paragraph 1.</p>
+ <html:p xmlns:html="http://www.w3.org/1999/xhtml">Paragraph 2.</html:p>
+ </group>
+</groups>
diff --git a/tests/grouping/test29.xml b/tests/grouping/test29.xml
new file mode 100644
index 00000000..c3987066
--- /dev/null
+++ b/tests/grouping/test29.xml
@@ -0,0 +1,4 @@
+<root>
+ <p xmlns="http://www.w3.org/1999/xhtml">Paragraph 1.</p>
+ <html:p xmlns:html="http://www.w3.org/1999/xhtml">Paragraph 2.</html:p>
+</root>
diff --git a/tests/grouping/test29.xsl b/tests/grouping/test29.xsl
new file mode 100644
index 00000000..ab69a271
--- /dev/null
+++ b/tests/grouping/test29.xsl
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ exclude-result-prefixes="xs"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test29.xml -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/*">
+ <groups>
+ <xsl:for-each-group select="*" group-by="node-name()">
+ <group node-name="{current-grouping-key()}">
+ <xsl:sequence select="current-group()"/>
+ </group>
+ </xsl:for-each-group>
+ </groups>
+ </xsl:template>
+
+ <!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/org/apache/xalan/xslt3/GroupingTests.java b/tests/org/apache/xalan/xslt3/GroupingTests.java
index a137b398..d184703e 100644
--- a/tests/org/apache/xalan/xslt3/GroupingTests.java
+++ b/tests/org/apache/xalan/xslt3/GroupingTests.java
@@ -329,5 +329,15 @@ public class GroupingTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslGroupingTest29() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test29.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test29.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test29.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org