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 2025/03/04 08:39:32 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing implementation of xpath 3.1 unary lookup operation on xdm map & array references, along with a working related test case
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
new 1b84b9d4c committing implementation of xpath 3.1 unary lookup operation on xdm map & array references, along with a working related test case
1b84b9d4c is described below
commit 1b84b9d4c27bb8f862ca5259867257331998b9ae
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue Mar 4 14:09:22 2025 +0530
committing implementation of xpath 3.1 unary lookup operation on xdm map & array references, along with a working related test case
---
README | 4 +-
.../org/apache/xpath/compiler/XPathParser.java | 31 ++++++++++++++
.../apache/xalan/tests/xpath3/XPathMapTests.java | 10 +++++
src/test/resources/xpath_maps/gold/test31.out | 12 ++++++
src/test/resources/xpath_maps/test31.xsl | 49 ++++++++++++++++++++++
5 files changed, 104 insertions(+), 2 deletions(-)
diff --git a/README b/README
index e7e540a65..3565b7d8d 100644
--- a/README
+++ b/README
@@ -57,11 +57,11 @@ This produces Maven build output with trailing information like following:
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.xalan.tests.main.AllXsl3Tests
-[INFO] Tests run: 908, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 42.899 s - in org.apache.xalan.tests.main.AllXsl3Tests
+[INFO] Tests run: 909, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 17 s - in org.apache.xalan.tests.main.AllXsl3Tests
[INFO]
[INFO] Results:
[INFO]
-[INFO] Tests run: 908, Failures: 0, Errors: 0, Skipped: 0
+[INFO] Tests run: 909, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
diff --git a/src/main/java/org/apache/xpath/compiler/XPathParser.java b/src/main/java/org/apache/xpath/compiler/XPathParser.java
index b68e43d4a..c8cb0aa63 100644
--- a/src/main/java/org/apache/xpath/compiler/XPathParser.java
+++ b/src/main/java/org/apache/xpath/compiler/XPathParser.java
@@ -3518,6 +3518,37 @@ public class XPathParser
matchFound = true;
}
+ else if ((m_tokenChar == '$') && (lookahead('?', 2))) {
+ // XPath parse for unary lookup operation on map & array references.
+
+ // e.g, $map1?'a' (get map's entry value for key 'a'),
+ // $array1?3 (get xdm item at array index 3).
+
+ // We translate these XPath expression syntax, to a
+ // compiled form of XPath dynamic function call.
+
+ appendOp(2, OpCodes.OP_DYNAMIC_FUNCTION_CALL);
+
+ nextToken(); // consume '$'
+
+ String funcRefVarName = m_token;
+ List<String> argList = new ArrayList<>();
+
+ nextToken();
+ consumeExpected('?');
+
+ argList.add(m_token);
+ nextToken();
+
+ m_dynamicFunctionCall = new XPathDynamicFunctionCall();
+ m_dynamicFunctionCall.setFuncRefVarName(funcRefVarName);
+ m_dynamicFunctionCall.setArgList(argList);
+
+ m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
+ m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
+
+ matchFound = true;
+ }
else if (m_tokenChar == '$')
{
nextToken(); // consume '$'
diff --git a/src/test/java/org/apache/xalan/tests/xpath3/XPathMapTests.java b/src/test/java/org/apache/xalan/tests/xpath3/XPathMapTests.java
index e7c76833f..221ba2738 100644
--- a/src/test/java/org/apache/xalan/tests/xpath3/XPathMapTests.java
+++ b/src/test/java/org/apache/xalan/tests/xpath3/XPathMapTests.java
@@ -347,5 +347,15 @@ public class XPathMapTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslMapTest31() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test31.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test31.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test31.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/src/test/resources/xpath_maps/gold/test31.out b/src/test/resources/xpath_maps/gold/test31.out
new file mode 100644
index 000000000..aab637cfe
--- /dev/null
+++ b/src/test/resources/xpath_maps/gold/test31.out
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <mapValues>
+ <one>2.1</one>
+ <two>3.1</two>
+ <three>4.1</three>
+ <four>105</four>
+ </mapValues>
+ <arrayValues>
+ <one>2</one>
+ <two>4</two>
+ </arrayValues>
+</result>
diff --git a/src/test/resources/xpath_maps/test31.xsl b/src/test/resources/xpath_maps/test31.xsl
new file mode 100644
index 000000000..ad67c561a
--- /dev/null
+++ b/src/test/resources/xpath_maps/test31.xsl
@@ -0,0 +1,49 @@
+<?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 -->
+
+ <!-- An XSL 3 stylesheet test case, to test XDM map & array information
+ lookup with unary operation syntax. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="map1" select="map {'a':2.1, 'b':3.1, 'c':4.1, 'd1':105}" as="map(xs:string, xs:decimal)"/>
+ <mapValues>
+ <one><xsl:value-of select="$map1?'a'"/></one>
+ <two><xsl:value-of select="$map1?'b'"/></two>
+ <three><xsl:value-of select="$map1?'c'"/></three>
+ <four><xsl:value-of select="$map1?'d1'"/></four>
+ </mapValues>
+ <xsl:variable name="array1" select="[2, 3, 4, 5]" as="array(xs:integer)"/>
+ <arrayValues>
+ <one><xsl:value-of select="$array1?1"/></one>
+ <two><xsl:value-of select="$array1?3"/></two>
+ </arrayValues>
+ </result>
+ </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>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org