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 2024/06/30 11:35:05 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: doing little bit of code refactoring, change in codebase comments at few places, and also adding a new working test case for xpath operator '='
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 1752a36b6 doing little bit of code refactoring, change in codebase comments at few places, and also adding a new working test case for xpath operator '='
1752a36b6 is described below
commit 1752a36b681b3b96f56f65031ba11bb67ebbea08
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sun Jun 30 17:04:46 2024 +0530
doing little bit of code refactoring, change in codebase comments at few places, and also adding a new working test case for xpath operator '='
---
src/org/apache/xalan/templates/ElemForEach.java | 6 +--
.../apache/xalan/templates/ElemForEachGroup.java | 4 +-
src/org/apache/xalan/templates/ElemValueOf.java | 6 +--
.../xslt/util/XslTransformEvaluationHelper.java | 10 ++---
src/org/apache/xpath/compiler/XPathParser.java | 28 ++++++------
.../composite/{ForExpr.java => XPathForExpr.java} | 13 ++----
.../composite/{IfExpr.java => XPathIfExpr.java} | 17 +++-----
...uantifiedExpr.java => XPathQuantifiedExpr.java} | 12 ++---
.../xpath3/XPathGeneralComparisonOpTests.java | 10 +++++
tests/xpath_general_comparison/gold/test7.out | 6 +++
tests/xpath_general_comparison/test7.xsl | 51 ++++++++++++++++++++++
11 files changed, 106 insertions(+), 57 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemForEach.java b/src/org/apache/xalan/templates/ElemForEach.java
index e72fa413d..abf59217a 100644
--- a/src/org/apache/xalan/templates/ElemForEach.java
+++ b/src/org/apache/xalan/templates/ElemForEach.java
@@ -38,7 +38,7 @@ import org.apache.xpath.Expression;
import org.apache.xpath.ExpressionOwner;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.composite.ForExpr;
+import org.apache.xpath.composite.XPathForExpr;
import org.apache.xpath.composite.XPathSequenceConstructor;
import org.apache.xpath.functions.XPathDynamicFunctionCall;
import org.apache.xpath.functions.Function;
@@ -402,8 +402,8 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
}
}
}
- else if (m_selectExpression instanceof ForExpr) {
- ForExpr forExpr = (ForExpr)m_selectExpression;
+ else if (m_selectExpression instanceof XPathForExpr) {
+ XPathForExpr forExpr = (XPathForExpr)m_selectExpression;
XObject evalResult = forExpr.execute(xctxt);
XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult,
diff --git a/src/org/apache/xalan/templates/ElemForEachGroup.java b/src/org/apache/xalan/templates/ElemForEachGroup.java
index 97d1f1bc4..b422b69c7 100644
--- a/src/org/apache/xalan/templates/ElemForEachGroup.java
+++ b/src/org/apache/xalan/templates/ElemForEachGroup.java
@@ -39,7 +39,7 @@ import org.apache.xpath.ExpressionOwner;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.axes.NodeSequence;
-import org.apache.xpath.composite.ForExpr;
+import org.apache.xpath.composite.XPathForExpr;
import org.apache.xpath.composite.XPathSequenceConstructor;
import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XBoolean;
@@ -465,7 +465,7 @@ public class ElemForEachGroup extends ElemTemplateElement
}
}
else if ((m_selectExpression instanceof XPathSequenceConstructor) ||
- (m_selectExpression instanceof ForExpr)) {
+ (m_selectExpression instanceof XPathForExpr)) {
XObject xObj = m_selectExpression.execute(xctxt);
ResultSequence resultSeq = (ResultSequence)xObj;
diff --git a/src/org/apache/xalan/templates/ElemValueOf.java b/src/org/apache/xalan/templates/ElemValueOf.java
index 500a3b7e8..5ffb5352f 100644
--- a/src/org/apache/xalan/templates/ElemValueOf.java
+++ b/src/org/apache/xalan/templates/ElemValueOf.java
@@ -33,7 +33,7 @@ import org.apache.xpath.Expression;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.axes.LocPathIterator;
-import org.apache.xpath.composite.IfExpr;
+import org.apache.xpath.composite.XPathIfExpr;
import org.apache.xpath.composite.LetExpr;
import org.apache.xpath.functions.XPathDynamicFunctionCall;
import org.apache.xpath.functions.FuncExtFunction;
@@ -578,8 +578,8 @@ public class ElemValueOf extends ElemTemplateElement {
(new XString(strValue)).dispatchCharactersEvents(rth);
}
- else if (expr instanceof IfExpr) {
- IfExpr ifExpr = (IfExpr)expr;
+ else if (expr instanceof XPathIfExpr) {
+ XPathIfExpr ifExpr = (XPathIfExpr)expr;
XObject evalResult = ifExpr.execute(xctxt);
String strValue = XslTransformEvaluationHelper.getStrVal(evalResult);
diff --git a/src/org/apache/xalan/xslt/util/XslTransformEvaluationHelper.java b/src/org/apache/xalan/xslt/util/XslTransformEvaluationHelper.java
index 4fb4a3ac4..3571e31af 100644
--- a/src/org/apache/xalan/xslt/util/XslTransformEvaluationHelper.java
+++ b/src/org/apache/xalan/xslt/util/XslTransformEvaluationHelper.java
@@ -36,7 +36,7 @@ import org.apache.xpath.Expression;
import org.apache.xpath.XPathCollationSupport;
import org.apache.xpath.XPathContext;
import org.apache.xpath.axes.LocPathIterator;
-import org.apache.xpath.composite.ForExpr;
+import org.apache.xpath.composite.XPathForExpr;
import org.apache.xpath.composite.XPathSequenceConstructor;
import org.apache.xpath.functions.Function;
import org.apache.xpath.objects.ResultSequence;
@@ -255,8 +255,8 @@ public class XslTransformEvaluationHelper {
sum = sumResultSequence(resultSeq);
}
}
- else if (expr instanceof ForExpr) {
- ForExpr forExpr = (ForExpr)expr;
+ else if (expr instanceof XPathForExpr) {
+ XPathForExpr forExpr = (XPathForExpr)expr;
ResultSequence forExprResult = (ResultSequence)(forExpr.execute(xctxt));
sum = sumResultSequence(forExprResult);
}
@@ -342,8 +342,8 @@ public class XslTransformEvaluationHelper {
ResultSequence resultSeq = (ResultSequence)(((Range)expr).execute(xctxt));
xdmSequenceSize = resultSeq.size();
}
- else if (expr instanceof ForExpr) {
- ResultSequence resultSeq = (ResultSequence)(((ForExpr)expr).execute(xctxt));
+ else if (expr instanceof XPathForExpr) {
+ ResultSequence resultSeq = (ResultSequence)(((XPathForExpr)expr).execute(xctxt));
xdmSequenceSize = resultSeq.size();
}
else {
diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 75852a1c3..80af33713 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -34,14 +34,14 @@ import javax.xml.transform.TransformerException;
import org.apache.xalan.res.XSLMessages;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xpath.XPathProcessorException;
-import org.apache.xpath.composite.ForExpr;
+import org.apache.xpath.composite.XPathForExpr;
import org.apache.xpath.composite.ForQuantifiedExprVarBinding;
-import org.apache.xpath.composite.IfExpr;
+import org.apache.xpath.composite.XPathIfExpr;
import org.apache.xpath.composite.LetExpr;
import org.apache.xpath.composite.LetExprVarBinding;
import org.apache.xpath.composite.XPathMapConstructor;
import org.apache.xpath.composite.XPathNamedFunctionReference;
-import org.apache.xpath.composite.QuantifiedExpr;
+import org.apache.xpath.composite.XPathQuantifiedExpr;
import org.apache.xpath.composite.SequenceTypeArrayTest;
import org.apache.xpath.composite.SequenceTypeData;
import org.apache.xpath.composite.SequenceTypeFunctionTest;
@@ -143,13 +143,13 @@ public class XPathParser
static XPathDynamicFunctionCall m_dynamicFunctionCall = null;
- static ForExpr m_forExpr = null;
+ static XPathForExpr m_forExpr = null;
static LetExpr m_letExpr = null;
- static QuantifiedExpr m_quantifiedExpr = null;
+ static XPathQuantifiedExpr m_quantifiedExpr = null;
- static IfExpr m_ifExpr = null;
+ static XPathIfExpr m_ifExpr = null;
static XPathSequenceConstructor m_xpathSequenceConstructor = null;
@@ -1586,7 +1586,7 @@ public class XPathParser
// function argument, or may be written within an XPath predicate).
String prevTokenStr = getTokenRelative(-2);
- m_quantifiedExpr = QuantifiedExpr(prevTokenStr, QuantifiedExpr.SOME);
+ m_quantifiedExpr = QuantifiedExpr(prevTokenStr, XPathQuantifiedExpr.SOME);
}
else if (tokenIs("every")) {
// To check, whether XPath quantified 'every' expression is a sub expression
@@ -1594,7 +1594,7 @@ public class XPathParser
// function argument, or may be written within an XPath predicate).
String prevTokenStr = getTokenRelative(-2);
- m_quantifiedExpr = QuantifiedExpr(prevTokenStr, QuantifiedExpr.EVERY);
+ m_quantifiedExpr = QuantifiedExpr(prevTokenStr, XPathQuantifiedExpr.EVERY);
}
else if (tokenIs("if")) {
m_ifExpr = IfExpr();
@@ -1681,7 +1681,7 @@ public class XPathParser
return count;
}
- protected ForExpr ForExpr(String prevTokenStrBeforeFor) throws javax.xml.transform.TransformerException
+ protected XPathForExpr ForExpr(String prevTokenStrBeforeFor) throws javax.xml.transform.TransformerException
{
int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
@@ -1689,7 +1689,7 @@ public class XPathParser
insertOp(opPos, 2, OpCodes.OP_FOR_EXPR);
- ForExpr forExpr = new ForExpr();
+ XPathForExpr forExpr = new XPathForExpr();
List<ForQuantifiedExprVarBinding> forExprVarBindingList = new
ArrayList<ForQuantifiedExprVarBinding>();
@@ -1863,7 +1863,7 @@ public class XPathParser
return letExpr;
}
- protected QuantifiedExpr QuantifiedExpr(String prevTokenStrBeforeQuantifier, int quantifierExprType)
+ protected XPathQuantifiedExpr QuantifiedExpr(String prevTokenStrBeforeQuantifier, int quantifierExprType)
throws javax.xml.transform.TransformerException
{
int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
@@ -1872,7 +1872,7 @@ public class XPathParser
insertOp(opPos, 2, OpCodes.OP_QUANTIFIED_EXPR);
- QuantifiedExpr quantifiedExpr = new QuantifiedExpr();
+ XPathQuantifiedExpr quantifiedExpr = new XPathQuantifiedExpr();
quantifiedExpr.setCurrentXPathQuantifier(quantifierExprType);
List<ForQuantifiedExprVarBinding> quantifiedExprVarBindingList = new
@@ -1958,7 +1958,7 @@ public class XPathParser
return quantifiedExpr;
}
- protected IfExpr IfExpr() throws javax.xml.transform.TransformerException
+ protected XPathIfExpr IfExpr() throws javax.xml.transform.TransformerException
{
int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
@@ -1966,7 +1966,7 @@ public class XPathParser
insertOp(opPos, 2, OpCodes.OP_IF_EXPR);
- IfExpr ifExpr = new IfExpr();
+ XPathIfExpr ifExpr = new XPathIfExpr();
consumeExpected('(');
diff --git a/src/org/apache/xpath/composite/ForExpr.java b/src/org/apache/xpath/composite/XPathForExpr.java
similarity index 95%
rename from src/org/apache/xpath/composite/ForExpr.java
rename to src/org/apache/xpath/composite/XPathForExpr.java
index cfd6cfd8c..43898dac7 100644
--- a/src/org/apache/xpath/composite/ForExpr.java
+++ b/src/org/apache/xpath/composite/XPathForExpr.java
@@ -41,22 +41,15 @@ import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XObject;
/*
- * The XalanJ XPath parser, creates and populates an object of this class,
- * as a representation of XPath 3.1 "for" expression.
- *
- * The XPath 3.1 spec, defines "for" expression with following grammar,
- *
- * ForExpr ::= SimpleForClause "return" ExprSingle
- * SimpleForClause ::= "for" SimpleForBinding ("," SimpleForBinding)*
- * SimpleForBinding ::= "$" VarName "in" ExprSingle
+ * An implementation of XPath 3.1 'for' expression.
*
- * Ref : https://www.w3.org/TR/xpath-31/#id-for-expressions
+ * Ref : https://www.w3.org/TR/xpath-31/#id-for-expressions
*
* @author Mukul Gandhi <mu...@apache.org>
*
* @xsl.usage advanced
*/
-public class ForExpr extends Expression {
+public class XPathForExpr extends Expression {
private static final long serialVersionUID = -7289739978026057248L;
diff --git a/src/org/apache/xpath/composite/IfExpr.java b/src/org/apache/xpath/composite/XPathIfExpr.java
similarity index 88%
rename from src/org/apache/xpath/composite/IfExpr.java
rename to src/org/apache/xpath/composite/XPathIfExpr.java
index ce07ea930..3c50da091 100644
--- a/src/org/apache/xpath/composite/IfExpr.java
+++ b/src/org/apache/xpath/composite/XPathIfExpr.java
@@ -33,12 +33,7 @@ import org.apache.xpath.XPathVisitor;
import org.apache.xpath.objects.XObject;
/*
- * The XalanJ XPath parser, creates and populates an object of this class,
- * as a representation of XPath 3.1 "if" conditional expression.
- *
- * The XPath 3.1 spec, defines "if" expression with following grammar,
- *
- * IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
+ * An implementation of XPath 3.1 'if' expression.
*
* Ref : https://www.w3.org/TR/xpath-31/#id-conditionals
*
@@ -46,7 +41,7 @@ import org.apache.xpath.objects.XObject;
*
* @xsl.usage advanced
*/
-public class IfExpr extends Expression {
+public class XPathIfExpr extends Expression {
private static final long serialVersionUID = 4057572946055830336L;
@@ -110,15 +105,15 @@ public class IfExpr extends Expression {
conditionalExprXPathStr, prefixTable);
}
- XPath conditionlExprXpath = new XPath(conditionalExprXPathStr, srcLocator, xctxt.getNamespaceContext(),
+ XPath ifConditionalXPath = new XPath(conditionalExprXPathStr, srcLocator, xctxt.getNamespaceContext(),
XPath.SELECT, null);
if (fVars != null) {
- conditionlExprXpath.fixupVariables(fVars, fGlobalsSize);
+ ifConditionalXPath.fixupVariables(fVars, fGlobalsSize);
}
- XObject conditionalXpathExprResult = conditionlExprXpath.execute(xctxt, contextNode, xctxt.getNamespaceContext());
+ XObject ifConditionalXPathResult = ifConditionalXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext());
- if (conditionalXpathExprResult.bool()) {
+ if (ifConditionalXPathResult.bool()) {
if (prefixTable != null) {
thenExprXPathStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
thenExprXPathStr, prefixTable);
diff --git a/src/org/apache/xpath/composite/QuantifiedExpr.java b/src/org/apache/xpath/composite/XPathQuantifiedExpr.java
similarity index 95%
rename from src/org/apache/xpath/composite/QuantifiedExpr.java
rename to src/org/apache/xpath/composite/XPathQuantifiedExpr.java
index f15e8b0a9..74a88e95e 100644
--- a/src/org/apache/xpath/composite/QuantifiedExpr.java
+++ b/src/org/apache/xpath/composite/XPathQuantifiedExpr.java
@@ -44,21 +44,15 @@ import org.apache.xpath.objects.XObject;
import xml.xpath31.processor.types.XSBoolean;
/*
- * The XalanJ XPath parser, creates and populates an object of this class,
- * as a representation of XPath 3.1 quantified expression.
- *
- * The XPath 3.1 spec, defines quantified expressions with following grammar,
- *
- * QuantifiedExpr ::= ("some" | "every") "$" VarName "in" ExprSingle ("," "$" VarName "in"
- * ExprSingle)* "satisfies" ExprSingle
+ * Implementation of XPath 3.1 quantified expressions.
*
- * Ref : https://www.w3.org/TR/xpath-31/#id-quantified-expressions
+ * Ref : https://www.w3.org/TR/xpath-31/#id-quantified-expressions
*
* @author Mukul Gandhi <mu...@apache.org>
*
* @xsl.usage advanced
*/
-public class QuantifiedExpr extends Expression {
+public class XPathQuantifiedExpr extends Expression {
private static final long serialVersionUID = -3073535420126040669L;
diff --git a/tests/org/apache/xalan/xpath3/XPathGeneralComparisonOpTests.java b/tests/org/apache/xalan/xpath3/XPathGeneralComparisonOpTests.java
index 6c7c450a4..2295ba82c 100644
--- a/tests/org/apache/xalan/xpath3/XPathGeneralComparisonOpTests.java
+++ b/tests/org/apache/xalan/xpath3/XPathGeneralComparisonOpTests.java
@@ -109,5 +109,15 @@ public class XPathGeneralComparisonOpTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xpathGeneralComparisonOpTest7() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test7.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test7.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test7.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/tests/xpath_general_comparison/gold/test7.out b/tests/xpath_general_comparison/gold/test7.out
new file mode 100644
index 000000000..0ba1632bd
--- /dev/null
+++ b/tests/xpath_general_comparison/gold/test7.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>abc</one>
+ <two>pqr1</two>
+ <three>abc2</three>
+ <four>pqr3</four>
+</result>
diff --git a/tests/xpath_general_comparison/test7.xsl b/tests/xpath_general_comparison/test7.xsl
new file mode 100644
index 000000000..5c4caf940
--- /dev/null
+++ b/tests/xpath_general_comparison/test7.xsl
@@ -0,0 +1,51 @@
+<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT test case, to test XPath general comparison
+ operator '=' within an 'if' expression. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <!-- user-defined function that does numerical square of the
+ function argument. -->
+ <xsl:variable name="func1" select="function($x) { $x*$x }"/>
+
+ <xsl:template match='/'>
+ <result>
+ <one>
+ <xsl:value-of select="if (1 = (1,2)) then 'abc' else 'pqr'"/>
+ </one>
+ <two>
+ <xsl:value-of select="if (1 = (2,3)) then 'abc1' else 'pqr1'"/>
+ </two>
+ <three>
+ <xsl:value-of select="if (16 = ($func1(2),$func1(4))) then 'abc2' else 'pqr2'"/>
+ </three>
+ <four>
+ <xsl:value-of select="if (10 = ($func1(2),$func1(4))) then 'abc3' else 'pqr3'"/>
+ </four>
+ </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