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/10/02 12:25:12 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: committing improvements to implementation of xpath 3.1 node combination 'intersect' and 'except' operators along with few conformance tests
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 49eb088b8 committing improvements to implementation of xpath 3.1 node combination 'intersect' and 'except' operators along with few conformance tests
49eb088b8 is described below
commit 49eb088b88df16b12aa563ae36ac18b586930967
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Wed Oct 2 17:54:58 2024 +0530
committing improvements to implementation of xpath 3.1 node combination 'intersect' and 'except' operators along with few conformance tests
---
src/org/apache/xpath/XPathVisitor.java | 18 -
.../xpath/axes/NodeSequenceExceptIterator.java | 583 --------------------
.../xpath/axes/NodeSequenceIntersectIterator.java | 595 ---------------------
src/org/apache/xpath/compiler/Compiler.java | 46 +-
src/org/apache/xpath/operations/Except.java | 174 ++++++
src/org/apache/xpath/operations/Intersect.java | 189 +++++++
tests/node_sequence_combination/gold/test10.out | 6 +
tests/node_sequence_combination/gold/test11.out | 8 +
tests/node_sequence_combination/gold/test12.out | 8 +
tests/node_sequence_combination/gold/test13.out | 6 +
tests/node_sequence_combination/gold/test9.out | 6 +
.../{test5.xsl => test10.xsl} | 8 +-
.../{test5.xsl => test11.xsl} | 8 +-
.../{test5.xsl => test12.xsl} | 8 +-
.../{test5.xsl => test13.xsl} | 8 +-
tests/node_sequence_combination/test5.xsl | 2 +-
.../{test5.xsl => test9.xsl} | 10 +-
.../xpath3/XPathNodeSequenceCombinationTests.java | 50 ++
18 files changed, 491 insertions(+), 1242 deletions(-)
diff --git a/src/org/apache/xpath/XPathVisitor.java b/src/org/apache/xpath/XPathVisitor.java
index 16c3040db..ee0b55605 100644
--- a/src/org/apache/xpath/XPathVisitor.java
+++ b/src/org/apache/xpath/XPathVisitor.java
@@ -21,8 +21,6 @@
package org.apache.xpath;
import org.apache.xpath.axes.LocPathIterator;
-import org.apache.xpath.axes.NodeSequenceExceptIterator;
-import org.apache.xpath.axes.NodeSequenceIntersectIterator;
import org.apache.xpath.axes.UnionPathIterator;
import org.apache.xpath.functions.Function;
import org.apache.xpath.objects.XNumber;
@@ -76,22 +74,6 @@ public class XPathVisitor
return true;
}
- /**
- * Visit an IntersectPath.
- */
- public boolean visitIntersectPath(ExpressionOwner owner, NodeSequenceIntersectIterator path)
- {
- return true;
- }
-
- /**
- * Visit an ExceptPath.
- */
- public boolean visitExceptPath(ExpressionOwner owner, NodeSequenceExceptIterator path)
- {
- return true;
- }
-
/**
* Visit a step within a location path.
* @param owner The owner of the expression, to which the expression can
diff --git a/src/org/apache/xpath/axes/NodeSequenceExceptIterator.java b/src/org/apache/xpath/axes/NodeSequenceExceptIterator.java
deleted file mode 100644
index e02f04c84..000000000
--- a/src/org/apache/xpath/axes/NodeSequenceExceptIterator.java
+++ /dev/null
@@ -1,583 +0,0 @@
-/*
- * 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.
- */
-/*
- * $Id$
- */
-package org.apache.xpath.axes;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xpath.Expression;
-import org.apache.xpath.ExpressionOwner;
-import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.OpCodes;
-import org.apache.xpath.compiler.OpMap;
-
-/**
- * This class provides an iterator view of evaluation
- * result of XPath 'except' operator.
- *
- * @author Mukul Gandhi <mu...@apache.org>
- *
- * @xsl.usage advanced
- */
-public class NodeSequenceExceptIterator extends LocPathIterator implements Cloneable,
- DTMIterator, java.io.Serializable, PathComponent
-{
-
- private static final long serialVersionUID = 5190935486033583929L;
-
- private PredicatedNodeTest[] m_nodeTests = null;
-
- private Iterator<Integer> m_NodeRefIter = null;
-
- /**
- * Constructor to create an instance which you can add
- * location paths to.
- */
- public NodeSequenceExceptIterator()
- {
- super();
- m_iterators = null;
- m_exprs = null;
- }
-
- /**
- * Initialize the context values for this expression
- * after it is cloned.
- *
- * @param context The XPath runtime context for this
- * transformation.
- */
- public void setRoot(int context, Object environment)
- {
- super.setRoot(context, environment);
-
- try
- {
- if (m_exprs != null)
- {
- int n = m_exprs.length;
- DTMIterator newIters[] = new DTMIterator[n];
-
- for (int i = 0; i < n; i++)
- {
- DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
- newIters[i] = iter;
- }
- m_iterators = newIters;
- }
- }
- catch(Exception e)
- {
- throw new org.apache.xml.utils.WrappedRuntimeException(e);
- }
- }
-
- /**
- * Add DTMIterator object instance to an array of DTMIterator objects,
- * representing node sequences whose set difference needs to be found.
- */
- public void addIterator(DTMIterator expr)
- {
-
- // Increase array size by one
- if (m_iterators == null) {
- m_iterators = new DTMIterator[1];
- m_iterators[0] = expr;
- }
- else {
- DTMIterator[] exprs = m_iterators;
- int len = m_iterators.length;
-
- m_iterators = new DTMIterator[len + 1];
-
- System.arraycopy(exprs, 0, m_iterators, 0, len);
-
- m_iterators[len] = expr;
- }
- expr.nextNode();
- if(expr instanceof Expression) {
- ((Expression)expr).exprSetParent(this);
- }
- }
-
- /**
- * Detaches the iterator from the set which it iterated over, releasing
- * any computational resources and placing the iterator in the INVALID
- * state. After<code>detach</code> has been invoked, calls to
- * <code>nextNode</code> or<code>previousNode</code> will raise the
- * exception INVALID_STATE_ERR.
- */
- public void detach()
- {
- if(m_allowDetach && null != m_iterators){
- int n = m_iterators.length;
- for(int i = 0; i < n; i++)
- {
- m_iterators[i].detach();
- }
- m_iterators = null;
- }
- }
-
-
- /**
- * Create a NodeSequenceExceptIterator object, including creation
- * of location path iterators from the opcode list, and call back
- * into the Compiler to create predicate expressions.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- * opcode list from the compiler.
- *
- * @throws javax.xml.transform.TransformerException
- */
- public NodeSequenceExceptIterator(Compiler compiler, int opPos)
- throws javax.xml.transform.TransformerException
- {
-
- super();
-
- opPos = OpMap.getFirstChildPos(opPos);
-
- loadLocationPaths(compiler, opPos, 0);
- }
-
- /**
- * This will return an iterator capable of handling the
- * set difference of XPath paths given.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- * opcode list from the compiler.
- *
- * @return Object that is derived from LocPathIterator.
- *
- * @throws javax.xml.transform.TransformerException
- */
- public static LocPathIterator createExceptIterator(Compiler compiler, int opPos)
- throws javax.xml.transform.TransformerException
- {
- NodeSequenceExceptIterator nodeSeqExceptIter = new NodeSequenceExceptIterator(compiler, opPos);
- int nPaths = nodeSeqExceptIter.m_exprs.length;
-
- for(int i = 0; i < nPaths; i++)
- {
- PredicatedNodeTest lpi = nodeSeqExceptIter.m_exprs[i];
- nodeSeqExceptIter.addNodeTest(lpi);
- }
-
- return nodeSeqExceptIter;
- }
-
- private void addNodeTest(PredicatedNodeTest test)
- {
-
- // Increase array size by 1
- if (m_nodeTests == null)
- {
- m_nodeTests = new PredicatedNodeTest[1];
- m_nodeTests[0] = test;
- }
- else
- {
- PredicatedNodeTest[] tests = m_nodeTests;
- int len = m_nodeTests.length;
-
- m_nodeTests = new PredicatedNodeTest[len + 1];
-
- System.arraycopy(tests, 0, m_nodeTests, 0, len);
-
- m_nodeTests[len] = test;
- }
-
- test.exprSetParent(this);
- }
-
- /**
- * Get the analysis bits for this walker, as defined in the WalkerFactory.
- * @return One of WalkerFactory#BIT_DESCENDANT, etc.
- */
- public int getAnalysisBits()
- {
- int bits = 0;
-
- if (m_exprs != null)
- {
- int n = m_exprs.length;
-
- for (int i = 0; i < n; i++)
- {
- int bit = m_exprs[i].getAnalysisBits();
- bits |= bit;
- }
- }
-
- return bits;
- }
-
- /**
- * Read the object from a serialization stream.
- *
- * @param stream Input stream to read from
- *
- * @throws java.io.IOException
- * @throws javax.xml.transform.TransformerException
- */
- private void readObject(java.io.ObjectInputStream stream)
- throws java.io.IOException, javax.xml.transform.TransformerException
- {
- try
- {
- stream.defaultReadObject();
- m_clones = new IteratorPool(this);
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new javax.xml.transform.TransformerException(cnfe);
- }
- }
-
- /**
- * Get a cloned LocPathIterator that holds the same
- * position as this iterator.
- *
- * @return A clone of this iterator that holds the same node position.
- *
- * @throws CloneNotSupportedException
- */
- public Object clone() throws CloneNotSupportedException
- {
-
- NodeSequenceExceptIterator clone = (NodeSequenceExceptIterator) super.clone();
- if (m_iterators != null)
- {
- int n = m_iterators.length;
-
- clone.m_iterators = new DTMIterator[n];
-
- for (int i = 0; i < n; i++)
- {
- clone.m_iterators[i] = (DTMIterator)m_iterators[i].clone();
- }
- }
-
- return clone;
- }
-
-
- /**
- * Create a new location path iterator.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- *
- * @return New location path iterator.
- *
- * @throws javax.xml.transform.TransformerException
- */
- protected LocPathIterator createDTMIterator(
- Compiler compiler, int opPos) throws javax.xml.transform.TransformerException
- {
- LocPathIterator lpi = (LocPathIterator)WalkerFactory.newDTMIterator(compiler, opPos,
- (compiler.getLocationPathDepth() <= 0));
- return lpi;
- }
-
- /**
- * Initialize the location path iterators. Recursive.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- * opcode list from the compiler.
- * @param count The insert position of the iterator.
- *
- * @throws javax.xml.transform.TransformerException
- */
- protected void loadLocationPaths(Compiler compiler, int opPos, int count)
- throws javax.xml.transform.TransformerException
- {
-
- // TODO: Handle unwrapped FilterExpr
- int steptype = compiler.getOp(opPos);
-
- if (steptype == OpCodes.OP_LOCATIONPATH)
- {
- loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
-
- m_exprs[count] = createDTMIterator(compiler, opPos);
- m_exprs[count].exprSetParent(this);
- }
- else
- {
-
- // Have to check for unwrapped functions, which the LocPathIterator
- // doesn't handle.
- switch (steptype)
- {
- case OpCodes.OP_VARIABLE :
- case OpCodes.OP_CONSTRUCTOR_STYLESHEET_EXT_FUNCTION :
- case OpCodes.OP_FUNCTION :
- case OpCodes.OP_GROUP :
- loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
-
- WalkingIterator iter =
- new WalkingIterator(compiler.getNamespaceContext());
- iter.exprSetParent(this);
-
- if(compiler.getLocationPathDepth() <= 0)
- iter.setIsTopLevel(true);
-
- iter.m_firstWalker = new org.apache.xpath.axes.FilterExprWalker(iter);
-
- iter.m_firstWalker.init(compiler, opPos, steptype);
-
- m_exprs[count] = iter;
- break;
- default :
- m_exprs = new LocPathIterator[count];
- }
- }
- }
-
- /**
- * Returns the next node in the set and advances the
- * position of the iterator in the set.
- */
- public int nextNode()
- {
-
- int result = DTM.NULL;
-
- if (m_iterators != null) {
- if (m_lastFetched == DTM.NULL) {
- int n = m_iterators.length;
- List<List<Integer>> memberLists = new ArrayList<List<Integer>>();
- for (int i = 0; i < n; i++) {
- List<Integer> memberList = new ArrayList<Integer>();
- DTMIterator dtmIter = m_iterators[i];
- int node = DTM.NULL;
- while ((node = dtmIter.nextNode()) != DTM.NULL) {
- memberList.add(Integer.valueOf(node));
- }
- memberLists.add(memberList);
- }
-
- List<Integer> exceptResultList = null;
-
- for (int idx = 0; idx < memberLists.size(); idx++) {
- List<Integer> nodeRefList1 = null;
- List<Integer> nodeRefList2 = null;
- if (exceptResultList == null) {
- nodeRefList1 = memberLists.get(idx);
- if ((idx + 1) < memberLists.size()) {
- nodeRefList2 = memberLists.get(idx + 1);
- nodeRefList1.removeAll(nodeRefList2);
- exceptResultList = new ArrayList<Integer>();
- exceptResultList.addAll(nodeRefList1);
- idx++;
- continue;
- }
- else {
- exceptResultList = new ArrayList<Integer>();
- exceptResultList.addAll(nodeRefList1);
- }
- }
- else {
- nodeRefList1 = exceptResultList;
- nodeRefList2 = memberLists.get(idx);
- nodeRefList1.removeAll(nodeRefList2);
- exceptResultList = new ArrayList<Integer>();
- exceptResultList.addAll(nodeRefList1);
- idx++;
- continue;
- }
- }
-
- exceptResultList.sort(null);
-
- m_NodeRefIter = exceptResultList.iterator();
- if (m_NodeRefIter.hasNext()) {
- result = m_NodeRefIter.next();
- }
- else {
- result = DTM.NULL;
- }
-
- m_lastFetched = result;
- }
- else {
- if (m_NodeRefIter.hasNext()) {
- result = m_NodeRefIter.next();
- }
- else {
- result = DTM.NULL;
- }
-
- m_lastFetched = result;
- }
- }
-
- return result;
- }
-
- /**
- * This function is used to fixup variables from QNames to stack frame
- * indexes at stylesheet build time.
- * @param vars List of QNames that correspond to variables. This list
- * should be searched backwards for the first qualified name that
- * corresponds to the variable reference qname. The position of the
- * QName in the vector from the start of the vector will be its position
- * in the stack frame (but variables above the globalsTop value will need
- * to be offset to the current stack frame).
- */
- public void fixupVariables(java.util.Vector vars, int globalsSize)
- {
- for (int i = 0; i < m_exprs.length; i++)
- {
- m_exprs[i].fixupVariables(vars, globalsSize);
- }
-
- }
-
- /**
- * An array of LocPathIterator object instances, one for
- * each location path contained in the except expression.
- */
- protected LocPathIterator[] m_exprs;
-
-
- /**
- * An array of DTMIterator object instances, one for each
- * location path contained in the except expression.
- */
- protected DTMIterator[] m_iterators;
-
- /**
- * Returns the axis being iterated, if it is known.
- *
- * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
- * types.
- */
- public int getAxis()
- {
- // Could be smarter.
- return -1;
- }
-
- class iterOwner implements ExpressionOwner
- {
- int m_index;
-
- iterOwner(int index)
- {
- m_index = index;
- }
-
- /**
- * @see ExpressionOwner#getExpression()
- */
- public Expression getExpression()
- {
- return m_exprs[m_index];
- }
-
- /**
- * @see ExpressionOwner#setExpression(Expression)
- */
- public void setExpression(Expression exp)
- {
-
- if(!(exp instanceof LocPathIterator))
- {
- WalkingIterator wi = new WalkingIterator(getPrefixResolver());
- FilterExprWalker few = new FilterExprWalker(wi);
- wi.setFirstWalker(few);
- few.setInnerExpression(exp);
- wi.exprSetParent(NodeSequenceExceptIterator.this);
- few.exprSetParent(wi);
- exp.exprSetParent(few);
- exp = wi;
- }
- else
- exp.exprSetParent(NodeSequenceExceptIterator.this);
- m_exprs[m_index] = (LocPathIterator)exp;
- }
-
- }
-
- /**
- * @see org.apache.xpath.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
- */
- public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
- {
- if(visitor.visitExceptPath(owner, this))
- {
- if(m_exprs != null)
- {
- int n = m_exprs.length;
- for(int i = 0; i < n; i++)
- {
- m_exprs[i].callVisitors(new iterOwner(i), visitor);
- }
- }
- }
- }
-
- /**
- * @see Expression#deepEquals(Expression)
- */
- public boolean deepEquals(Expression expr)
- {
- if (!super.deepEquals(expr))
- return false;
-
- NodeSequenceExceptIterator upi = (NodeSequenceExceptIterator) expr;
-
- if (m_exprs != null)
- {
- int n = m_exprs.length;
-
- if((null == upi.m_exprs) || (upi.m_exprs.length != n))
- return false;
-
- for (int i = 0; i < n; i++)
- {
- if(!m_exprs[i].deepEquals(upi.m_exprs[i]))
- return false;
- }
- }
- else if (null != upi.m_exprs)
- {
- return false;
- }
-
- return true;
- }
-
-}
diff --git a/src/org/apache/xpath/axes/NodeSequenceIntersectIterator.java b/src/org/apache/xpath/axes/NodeSequenceIntersectIterator.java
deleted file mode 100644
index 737134fb3..000000000
--- a/src/org/apache/xpath/axes/NodeSequenceIntersectIterator.java
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
- * 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.
- */
-/*
- * $Id$
- */
-package org.apache.xpath.axes;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xpath.Expression;
-import org.apache.xpath.ExpressionOwner;
-import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.OpCodes;
-import org.apache.xpath.compiler.OpMap;
-
-/**
- * This class provides an iterator view of evaluation
- * result of XPath 'intersect' operator.
- *
- * @author Mukul Gandhi <mu...@apache.org>
- *
- * @xsl.usage advanced
- */
-public class NodeSequenceIntersectIterator extends LocPathIterator implements Cloneable,
- DTMIterator, java.io.Serializable, PathComponent
-{
-
- private static final long serialVersionUID = -764531646697520864L;
-
- private PredicatedNodeTest[] m_nodeTests = null;
-
- private Iterator<Integer> m_NodeRefIter = null;
-
- /**
- * Constructor to create an instance which you can add
- * location paths to.
- */
- public NodeSequenceIntersectIterator()
- {
- super();
- m_iterators = null;
- m_exprs = null;
- }
-
- /**
- * Initialize the context values for this expression
- * after it is cloned.
- *
- * @param context The XPath runtime context for this
- * transformation.
- */
- public void setRoot(int context, Object environment)
- {
- super.setRoot(context, environment);
-
- try
- {
- if (m_exprs != null)
- {
- int n = m_exprs.length;
- DTMIterator newIters[] = new DTMIterator[n];
-
- for (int i = 0; i < n; i++)
- {
- DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
- newIters[i] = iter;
- }
- m_iterators = newIters;
- }
- }
- catch(Exception e)
- {
- throw new org.apache.xml.utils.WrappedRuntimeException(e);
- }
- }
-
- /**
- * Add DTMIterator object instance to an array of DTMIterator objects,
- * representing node sequences whose intersection needs to be found.
- */
- public void addIterator(DTMIterator expr)
- {
-
- // Increase array size by one
- if (m_iterators == null) {
- m_iterators = new DTMIterator[1];
- m_iterators[0] = expr;
- }
- else {
- DTMIterator[] exprs = m_iterators;
- int len = m_iterators.length;
-
- m_iterators = new DTMIterator[len + 1];
-
- System.arraycopy(exprs, 0, m_iterators, 0, len);
-
- m_iterators[len] = expr;
- }
- expr.nextNode();
- if(expr instanceof Expression) {
- ((Expression)expr).exprSetParent(this);
- }
- }
-
- /**
- * Detaches the iterator from the set which it iterated over, releasing
- * any computational resources and placing the iterator in the INVALID
- * state. After<code>detach</code> has been invoked, calls to
- * <code>nextNode</code> or<code>previousNode</code> will raise the
- * exception INVALID_STATE_ERR.
- */
- public void detach()
- {
- if(m_allowDetach && null != m_iterators){
- int n = m_iterators.length;
- for(int i = 0; i < n; i++)
- {
- m_iterators[i].detach();
- }
- m_iterators = null;
- }
- }
-
-
- /**
- * Create a NodeSequenceIntersectIterator object, including creation
- * of location path iterators from the opcode list, and call back
- * into the Compiler to create predicate expressions.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- * opcode list from the compiler.
- *
- * @throws javax.xml.transform.TransformerException
- */
- public NodeSequenceIntersectIterator(Compiler compiler, int opPos)
- throws javax.xml.transform.TransformerException
- {
-
- super();
-
- opPos = OpMap.getFirstChildPos(opPos);
-
- loadLocationPaths(compiler, opPos, 0);
- }
-
- /**
- * This will return an iterator capable of handling the
- * intersection of XPath paths given.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- * opcode list from the compiler.
- *
- * @return Object that is derived from LocPathIterator.
- *
- * @throws javax.xml.transform.TransformerException
- */
- public static LocPathIterator createIntersectIterator(Compiler compiler, int opPos)
- throws javax.xml.transform.TransformerException
- {
- NodeSequenceIntersectIterator nodeSeqIntersectIter = new NodeSequenceIntersectIterator(compiler, opPos);
- int nPaths = nodeSeqIntersectIter.m_exprs.length;
-
- for(int i = 0; i < nPaths; i++)
- {
- PredicatedNodeTest lpi = nodeSeqIntersectIter.m_exprs[i];
- nodeSeqIntersectIter.addNodeTest(lpi);
- }
-
- return nodeSeqIntersectIter;
- }
-
- private void addNodeTest(PredicatedNodeTest test)
- {
-
- // Increase array size by 1
- if (m_nodeTests == null)
- {
- m_nodeTests = new PredicatedNodeTest[1];
- m_nodeTests[0] = test;
- }
- else
- {
- PredicatedNodeTest[] tests = m_nodeTests;
- int len = m_nodeTests.length;
-
- m_nodeTests = new PredicatedNodeTest[len + 1];
-
- System.arraycopy(tests, 0, m_nodeTests, 0, len);
-
- m_nodeTests[len] = test;
- }
-
- test.exprSetParent(this);
- }
-
- /**
- * Get the analysis bits for this walker, as defined in the WalkerFactory.
- * @return One of WalkerFactory#BIT_DESCENDANT, etc.
- */
- public int getAnalysisBits()
- {
- int bits = 0;
-
- if (m_exprs != null)
- {
- int n = m_exprs.length;
-
- for (int i = 0; i < n; i++)
- {
- int bit = m_exprs[i].getAnalysisBits();
- bits |= bit;
- }
- }
-
- return bits;
- }
-
- /**
- * Read the object from a serialization stream.
- *
- * @param stream Input stream to read from
- *
- * @throws java.io.IOException
- * @throws javax.xml.transform.TransformerException
- */
- private void readObject(java.io.ObjectInputStream stream)
- throws java.io.IOException, javax.xml.transform.TransformerException
- {
- try
- {
- stream.defaultReadObject();
- m_clones = new IteratorPool(this);
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new javax.xml.transform.TransformerException(cnfe);
- }
- }
-
- /**
- * Get a cloned LocPathIterator that holds the same
- * position as this iterator.
- *
- * @return A clone of this iterator that holds the same node position.
- *
- * @throws CloneNotSupportedException
- */
- public Object clone() throws CloneNotSupportedException
- {
-
- NodeSequenceIntersectIterator clone = (NodeSequenceIntersectIterator) super.clone();
- if (m_iterators != null)
- {
- int n = m_iterators.length;
-
- clone.m_iterators = new DTMIterator[n];
-
- for (int i = 0; i < n; i++)
- {
- clone.m_iterators[i] = (DTMIterator)m_iterators[i].clone();
- }
- }
-
- return clone;
- }
-
-
- /**
- * Create a new location path iterator.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- *
- * @return New location path iterator.
- *
- * @throws javax.xml.transform.TransformerException
- */
- protected LocPathIterator createDTMIterator(
- Compiler compiler, int opPos) throws javax.xml.transform.TransformerException
- {
- LocPathIterator lpi = (LocPathIterator)WalkerFactory.newDTMIterator(compiler, opPos,
- (compiler.getLocationPathDepth() <= 0));
- return lpi;
- }
-
- /**
- * Initialize the location path iterators. Recursive.
- *
- * @param compiler The Compiler which is creating
- * this expression.
- * @param opPos The position of this iterator in the
- * opcode list from the compiler.
- * @param count The insert position of the iterator.
- *
- * @throws javax.xml.transform.TransformerException
- */
- protected void loadLocationPaths(Compiler compiler, int opPos, int count)
- throws javax.xml.transform.TransformerException
- {
-
- // TODO: Handle unwrapped FilterExpr
- int steptype = compiler.getOp(opPos);
-
- if (steptype == OpCodes.OP_LOCATIONPATH)
- {
- loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
-
- m_exprs[count] = createDTMIterator(compiler, opPos);
- m_exprs[count].exprSetParent(this);
- }
- else
- {
-
- // Have to check for unwrapped functions, which the LocPathIterator
- // doesn't handle.
- switch (steptype)
- {
- case OpCodes.OP_VARIABLE :
- case OpCodes.OP_CONSTRUCTOR_STYLESHEET_EXT_FUNCTION :
- case OpCodes.OP_FUNCTION :
- case OpCodes.OP_GROUP :
- loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
-
- WalkingIterator iter =
- new WalkingIterator(compiler.getNamespaceContext());
- iter.exprSetParent(this);
-
- if(compiler.getLocationPathDepth() <= 0)
- iter.setIsTopLevel(true);
-
- iter.m_firstWalker = new org.apache.xpath.axes.FilterExprWalker(iter);
-
- iter.m_firstWalker.init(compiler, opPos, steptype);
-
- m_exprs[count] = iter;
- break;
- default :
- m_exprs = new LocPathIterator[count];
- }
- }
- }
-
- /**
- * Returns the next node in the set and advances the
- * position of the iterator in the set.
- */
- public int nextNode()
- {
-
- int result = DTM.NULL;
-
- if (m_iterators != null) {
- if (m_lastFetched == DTM.NULL) {
- int n = m_iterators.length;
- List<List<Integer>> memberLists = new ArrayList<List<Integer>>();
- for (int i = 0; i < n; i++) {
- List<Integer> memberList = new ArrayList<Integer>();
- DTMIterator dtmIter = m_iterators[i];
- int node = DTM.NULL;
- while ((node = dtmIter.nextNode()) != DTM.NULL) {
- memberList.add(Integer.valueOf(node));
- }
- memberLists.add(memberList);
- }
-
- Set<Integer> intersectResultSet = null;
-
- // XPath 'intersect' operator result in document order
- List<Integer> intersectResultInDocOrder = null;
-
- for (int idx = 0; idx < memberLists.size(); idx++) {
- List<Integer> nodeRefList1 = null;
- List<Integer> nodeRefList2 = null;
- if (intersectResultSet == null) {
- nodeRefList1 = memberLists.get(idx);
- if ((idx + 1) < memberLists.size()) {
- nodeRefList2 = memberLists.get(idx + 1);
- intersectResultSet = nodeRefList1.stream()
- .distinct()
- .filter(nodeRefList2::contains)
- .collect(Collectors.toSet());
- idx++;
- continue;
- }
- else {
- intersectResultSet = new HashSet<Integer>();
- intersectResultSet.addAll(nodeRefList1);
- }
- }
- else {
- nodeRefList1 = Arrays.asList(intersectResultSet.toArray(new Integer[0]));
- nodeRefList2 = memberLists.get(idx);
- intersectResultSet = nodeRefList1.stream()
- .distinct()
- .filter(nodeRefList2::contains)
- .collect(Collectors.toSet());
- idx++;
- continue;
- }
- }
-
- List<Integer> list = Arrays.asList(intersectResultSet.toArray(new Integer[0]));
-
- list.sort(null);
- intersectResultInDocOrder = list;
-
- m_NodeRefIter = intersectResultInDocOrder.iterator();
- if (m_NodeRefIter.hasNext()) {
- result = m_NodeRefIter.next();
- }
- else {
- result = DTM.NULL;
- }
-
- m_lastFetched = result;
- }
- else {
- if (m_NodeRefIter.hasNext()) {
- result = m_NodeRefIter.next();
- }
- else {
- result = DTM.NULL;
- }
-
- m_lastFetched = result;
- }
- }
-
- return result;
- }
-
- /**
- * This function is used to fixup variables from QNames to stack frame
- * indexes at stylesheet build time.
- * @param vars List of QNames that correspond to variables. This list
- * should be searched backwards for the first qualified name that
- * corresponds to the variable reference qname. The position of the
- * QName in the vector from the start of the vector will be its position
- * in the stack frame (but variables above the globalsTop value will need
- * to be offset to the current stack frame).
- */
- public void fixupVariables(java.util.Vector vars, int globalsSize)
- {
- for (int i = 0; i < m_exprs.length; i++)
- {
- m_exprs[i].fixupVariables(vars, globalsSize);
- }
-
- }
-
- /**
- * An array of LocPathIterator object instances, one for
- * each location path contained in the intersect expression.
- */
- protected LocPathIterator[] m_exprs;
-
-
- /**
- * An array of DTMIterator object instances, one for each
- * location path contained in the intersect expression.
- */
- protected DTMIterator[] m_iterators;
-
- /**
- * Returns the axis being iterated, if it is known.
- *
- * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
- * types.
- */
- public int getAxis()
- {
- // Could be smarter.
- return -1;
- }
-
- class iterOwner implements ExpressionOwner
- {
- int m_index;
-
- iterOwner(int index)
- {
- m_index = index;
- }
-
- /**
- * @see ExpressionOwner#getExpression()
- */
- public Expression getExpression()
- {
- return m_exprs[m_index];
- }
-
- /**
- * @see ExpressionOwner#setExpression(Expression)
- */
- public void setExpression(Expression exp)
- {
-
- if(!(exp instanceof LocPathIterator))
- {
- WalkingIterator wi = new WalkingIterator(getPrefixResolver());
- FilterExprWalker few = new FilterExprWalker(wi);
- wi.setFirstWalker(few);
- few.setInnerExpression(exp);
- wi.exprSetParent(NodeSequenceIntersectIterator.this);
- few.exprSetParent(wi);
- exp.exprSetParent(few);
- exp = wi;
- }
- else
- exp.exprSetParent(NodeSequenceIntersectIterator.this);
- m_exprs[m_index] = (LocPathIterator)exp;
- }
-
- }
-
- /**
- * @see org.apache.xpath.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
- */
- public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
- {
- if(visitor.visitIntersectPath(owner, this))
- {
- if(m_exprs != null)
- {
- int n = m_exprs.length;
- for(int i = 0; i < n; i++)
- {
- m_exprs[i].callVisitors(new iterOwner(i), visitor);
- }
- }
- }
- }
-
- /**
- * @see Expression#deepEquals(Expression)
- */
- public boolean deepEquals(Expression expr)
- {
- if (!super.deepEquals(expr))
- return false;
-
- NodeSequenceIntersectIterator upi = (NodeSequenceIntersectIterator) expr;
-
- if (m_exprs != null)
- {
- int n = m_exprs.length;
-
- if((null == upi.m_exprs) || (upi.m_exprs.length != n))
- return false;
-
- for (int i = 0; i < n; i++)
- {
- if(!m_exprs[i].deepEquals(upi.m_exprs[i]))
- return false;
- }
- }
- else if (null != upi.m_exprs)
- {
- return false;
- }
-
- return true;
- }
-
-}
diff --git a/src/org/apache/xpath/compiler/Compiler.java b/src/org/apache/xpath/compiler/Compiler.java
index a5f30c1bf..e03d2c507 100644
--- a/src/org/apache/xpath/compiler/Compiler.java
+++ b/src/org/apache/xpath/compiler/Compiler.java
@@ -34,8 +34,6 @@ import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.QName;
import org.apache.xml.utils.SAXSourceLocator;
import org.apache.xpath.Expression;
-import org.apache.xpath.axes.NodeSequenceExceptIterator;
-import org.apache.xpath.axes.NodeSequenceIntersectIterator;
import org.apache.xpath.axes.UnionPathIterator;
import org.apache.xpath.axes.WalkerFactory;
import org.apache.xpath.compiler.XPathParser.XPathArrayConsFuncArgs;
@@ -43,10 +41,10 @@ import org.apache.xpath.compiler.XPathParser.XPathSequenceConsFuncArgs;
import org.apache.xpath.composite.XPathArrayConstructor;
import org.apache.xpath.composite.XPathForExpr;
import org.apache.xpath.composite.XPathSequenceConstructor;
-import org.apache.xpath.functions.XSLConstructorStylesheetOrExtensionFunction;
import org.apache.xpath.functions.FuncExtFunctionAvailable;
import org.apache.xpath.functions.Function;
import org.apache.xpath.functions.WrongNumberArgsException;
+import org.apache.xpath.functions.XSLConstructorStylesheetOrExtensionFunction;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XString;
import org.apache.xpath.operations.And;
@@ -55,9 +53,11 @@ import org.apache.xpath.operations.CastAs;
import org.apache.xpath.operations.CastableAs;
import org.apache.xpath.operations.Div;
import org.apache.xpath.operations.Equals;
+import org.apache.xpath.operations.Except;
import org.apache.xpath.operations.Gt;
import org.apache.xpath.operations.Gte;
import org.apache.xpath.operations.InstanceOf;
+import org.apache.xpath.operations.Intersect;
import org.apache.xpath.operations.Lt;
import org.apache.xpath.operations.Lte;
import org.apache.xpath.operations.Minus;
@@ -951,35 +951,41 @@ public class Compiler extends OpMap
}
/**
- * Compile a node sequence combination 'intersect' operator.
+ * Compile an XPath node sequence 'intersect' operator.
*/
protected Expression intersect(int opPos) throws TransformerException
{
locPathDepth++;
- try
- {
- return NodeSequenceIntersectIterator.createIntersectIterator(this, opPos);
- }
- finally
- {
- locPathDepth--;
+
+ Expression result = null;
+
+ try {
+ result = compileOperation(new Intersect(), opPos);
}
+ finally {
+ locPathDepth--;
+ }
+
+ return result;
}
/**
- * Compile a node sequence combination 'except' operator.
+ * Compile an XPath node sequence 'except' operator.
*/
protected Expression except(int opPos) throws TransformerException
{
- locPathDepth++;
- try
- {
- return NodeSequenceExceptIterator.createExceptIterator(this, opPos);
- }
- finally
- {
- locPathDepth--;
+ locPathDepth++;
+
+ Expression result = null;
+
+ try {
+ result = compileOperation(new Except(), opPos);
}
+ finally {
+ locPathDepth--;
+ }
+
+ return result;
}
private int locPathDepth = -1;
diff --git a/src/org/apache/xpath/operations/Except.java b/src/org/apache/xpath/operations/Except.java
new file mode 100644
index 000000000..01628d3b9
--- /dev/null
+++ b/src/org/apache/xpath/operations/Except.java
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+/*
+ * $Id$
+ */
+package org.apache.xpath.operations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * An implementation of XPath 'except' operation.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class Except extends Operation
+{
+
+ private static final long serialVersionUID = 4245891832019437588L;
+
+ /**
+ * Method to find result of XPath 'except' operation.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ XObject expr1 = m_left.execute(xctxt);
+ XObject expr2 = m_right.execute(xctxt);
+
+ if ((expr1 instanceof XNodeSet) && (expr2 instanceof XNodeSet)) {
+ DTMIterator dtmIter = ((XNodeSet)expr1).iterRaw();
+ int nextNode;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList1.add(Integer.valueOf(nextNode));
+ }
+
+ dtmIter = ((XNodeSet)expr2).iterRaw();
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList2.add(Integer.valueOf(nextNode));
+ }
+
+ nodeHandleList1.removeAll(nodeHandleList2);
+
+ nodeHandleList1.sort(null);
+ result = new XNodeSet(nodeHandleList1, xctxt.getDTMManager());
+ }
+ else if ((expr1 instanceof ResultSequence) && (expr2 instanceof ResultSequence)) {
+ ResultSequence seq1 = (ResultSequence)expr1;
+ ResultSequence seq2 = (ResultSequence)expr2;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ for (int idx = 0; idx < seq1.size(); idx++) {
+ XObject xObj = seq1.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList1.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'except' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ for (int idx = 0; idx < seq2.size(); idx++) {
+ XObject xObj = seq2.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList2.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'except' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ nodeHandleList1.removeAll(nodeHandleList2);
+
+ nodeHandleList1.sort(null);
+ result = new XNodeSet(nodeHandleList1, xctxt.getDTMManager());
+ }
+ else if ((expr1 instanceof XNodeSet) && (expr2 instanceof ResultSequence)) {
+ DTMIterator dtmIter = ((XNodeSet)expr1).iterRaw();
+ int nextNode;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList1.add(Integer.valueOf(nextNode));
+ }
+
+ ResultSequence seq2 = (ResultSequence)expr2;
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ for (int idx = 0; idx < seq2.size(); idx++) {
+ XObject xObj = seq2.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList2.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'except' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ nodeHandleList1.removeAll(nodeHandleList2);
+
+ nodeHandleList1.sort(null);
+ result = new XNodeSet(nodeHandleList1, xctxt.getDTMManager());
+ }
+ else if ((expr1 instanceof ResultSequence) && (expr2 instanceof XNodeSet)) {
+ ResultSequence seq1 = (ResultSequence)expr1;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ for (int idx = 0; idx < seq1.size(); idx++) {
+ XObject xObj = seq1.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList1.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'except' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ DTMIterator dtmIter = ((XNodeSet)expr2).iterRaw();
+ int nextNode;
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList2.add(Integer.valueOf(nextNode));
+ }
+
+ nodeHandleList1.removeAll(nodeHandleList2);
+
+ nodeHandleList1.sort(null);
+ result = new XNodeSet(nodeHandleList1, xctxt.getDTMManager());
+ }
+
+ return result;
+
+ }
+
+}
diff --git a/src/org/apache/xpath/operations/Intersect.java b/src/org/apache/xpath/operations/Intersect.java
new file mode 100644
index 000000000..f22a1888d
--- /dev/null
+++ b/src/org/apache/xpath/operations/Intersect.java
@@ -0,0 +1,189 @@
+/*
+ * 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.
+ */
+/*
+ * $Id$
+ */
+package org.apache.xpath.operations;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * An implementation of XPath 'intersect' operation.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class Intersect extends Operation
+{
+
+ private static final long serialVersionUID = 5559048164177617210L;
+
+ /**
+ * Method to find result of XPath 'intersect' operation.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ XObject expr1 = m_left.execute(xctxt);
+ XObject expr2 = m_right.execute(xctxt);
+
+ if ((expr1 instanceof XNodeSet) && (expr2 instanceof XNodeSet)) {
+ DTMIterator dtmIter = ((XNodeSet)expr1).iterRaw();
+ int nextNode;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList1.add(Integer.valueOf(nextNode));
+ }
+
+ dtmIter = ((XNodeSet)expr2).iterRaw();
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList2.add(Integer.valueOf(nextNode));
+ }
+
+ Set<Integer> intersectResultSet = nodeHandleList1.stream()
+ .distinct().filter(nodeHandleList2::contains)
+ .collect(Collectors.toSet());
+ List<Integer> list = Arrays.asList(intersectResultSet.toArray(new Integer[0]));
+
+ list.sort(null);
+ result = new XNodeSet(list, xctxt.getDTMManager());
+ }
+ else if ((expr1 instanceof ResultSequence) && (expr2 instanceof ResultSequence)) {
+ ResultSequence seq1 = (ResultSequence)expr1;
+ ResultSequence seq2 = (ResultSequence)expr2;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ for (int idx = 0; idx < seq1.size(); idx++) {
+ XObject xObj = seq1.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList1.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'intersect' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ for (int idx = 0; idx < seq2.size(); idx++) {
+ XObject xObj = seq2.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList2.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'intersect' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ Set<Integer> intersectResultSet = nodeHandleList1.stream()
+ .distinct().filter(nodeHandleList2::contains)
+ .collect(Collectors.toSet());
+ List<Integer> list = Arrays.asList(intersectResultSet.toArray(new Integer[0]));
+
+ list.sort(null);
+ result = new XNodeSet(list, xctxt.getDTMManager());
+ }
+ else if ((expr1 instanceof XNodeSet) && (expr2 instanceof ResultSequence)) {
+ DTMIterator dtmIter = ((XNodeSet)expr1).iterRaw();
+ int nextNode;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList1.add(Integer.valueOf(nextNode));
+ }
+
+ ResultSequence seq2 = (ResultSequence)expr2;
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ for (int idx = 0; idx < seq2.size(); idx++) {
+ XObject xObj = seq2.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList2.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'intersect' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ Set<Integer> intersectResultSet = nodeHandleList1.stream()
+ .distinct().filter(nodeHandleList2::contains)
+ .collect(Collectors.toSet());
+ List<Integer> list = Arrays.asList(intersectResultSet.toArray(new Integer[0]));
+
+ list.sort(null);
+ result = new XNodeSet(list, xctxt.getDTMManager());
+ }
+ else if ((expr1 instanceof ResultSequence) && (expr2 instanceof XNodeSet)) {
+ ResultSequence seq1 = (ResultSequence)expr1;
+ List<Integer> nodeHandleList1 = new ArrayList<Integer>();
+ for (int idx = 0; idx < seq1.size(); idx++) {
+ XObject xObj = seq1.item(idx);
+ if (xObj instanceof XNodeSet) {
+ int nodeDtmHandle = ((XNodeSet)xObj).nextNode();
+ nodeHandleList1.add(Integer.valueOf(nodeDtmHandle));
+ }
+ else {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An item in left operand of XPath 'intersect' "
+ + "operation evaluation is not a node.", srcLocator);
+ }
+ }
+
+ DTMIterator dtmIter = ((XNodeSet)expr2).iterRaw();
+ int nextNode;
+ List<Integer> nodeHandleList2 = new ArrayList<Integer>();
+ while ((nextNode = dtmIter.nextNode()) != DTM.NULL) {
+ nodeHandleList2.add(Integer.valueOf(nextNode));
+ }
+
+ Set<Integer> intersectResultSet = nodeHandleList1.stream()
+ .distinct().filter(nodeHandleList2::contains)
+ .collect(Collectors.toSet());
+ List<Integer> list = Arrays.asList(intersectResultSet.toArray(new Integer[0]));
+
+ list.sort(null);
+ result = new XNodeSet(list, xctxt.getDTMManager());
+ }
+
+ return result;
+
+ }
+
+}
diff --git a/tests/node_sequence_combination/gold/test10.out b/tests/node_sequence_combination/gold/test10.out
new file mode 100644
index 000000000..bffa41833
--- /dev/null
+++ b/tests/node_sequence_combination/gold/test10.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <abc>
+ <x>1</x>
+ </abc>
+ <mno>hello</mno>
+</result>
diff --git a/tests/node_sequence_combination/gold/test11.out b/tests/node_sequence_combination/gold/test11.out
new file mode 100644
index 000000000..69f57c9dc
--- /dev/null
+++ b/tests/node_sequence_combination/gold/test11.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <abc>
+ <x>2</x>
+ </abc>
+ <abc>
+ <x>3</x>
+ </abc>
+</result>
diff --git a/tests/node_sequence_combination/gold/test12.out b/tests/node_sequence_combination/gold/test12.out
new file mode 100644
index 000000000..69f57c9dc
--- /dev/null
+++ b/tests/node_sequence_combination/gold/test12.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <abc>
+ <x>2</x>
+ </abc>
+ <abc>
+ <x>3</x>
+ </abc>
+</result>
diff --git a/tests/node_sequence_combination/gold/test13.out b/tests/node_sequence_combination/gold/test13.out
new file mode 100644
index 000000000..ad88e11fc
--- /dev/null
+++ b/tests/node_sequence_combination/gold/test13.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <abc>
+ <x>3</x>
+ </abc>
+ <mno>hello</mno>
+</result>
diff --git a/tests/node_sequence_combination/gold/test9.out b/tests/node_sequence_combination/gold/test9.out
new file mode 100644
index 000000000..bffa41833
--- /dev/null
+++ b/tests/node_sequence_combination/gold/test9.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <abc>
+ <x>1</x>
+ </abc>
+ <mno>hello</mno>
+</result>
diff --git a/tests/node_sequence_combination/test5.xsl b/tests/node_sequence_combination/test10.xsl
similarity index 85%
copy from tests/node_sequence_combination/test5.xsl
copy to tests/node_sequence_combination/test10.xsl
index f6e850d8f..9f6db7eca 100644
--- a/tests/node_sequence_combination/test5.xsl
+++ b/tests/node_sequence_combination/test10.xsl
@@ -1,7 +1,5 @@
<?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 -->
@@ -15,9 +13,9 @@
<xsl:template match="/info">
<result>
- <xsl:for-each select="* intersect abc[xs:integer(x) gt 1] intersect abc[2]">
- <xsl:copy-of select="."/>
- </xsl:for-each>
+ <xsl:variable name="seq1" select="(abc[1], abc[2], abc[3], mno[1])" as="element()*"/>
+ <xsl:variable name="seq2" select="abc[1] | mno[1]" as="element()*"/>
+ <xsl:copy-of select="$seq1 intersect $seq2"/>
</result>
</xsl:template>
diff --git a/tests/node_sequence_combination/test5.xsl b/tests/node_sequence_combination/test11.xsl
similarity index 85%
copy from tests/node_sequence_combination/test5.xsl
copy to tests/node_sequence_combination/test11.xsl
index f6e850d8f..e046f3a52 100644
--- a/tests/node_sequence_combination/test5.xsl
+++ b/tests/node_sequence_combination/test11.xsl
@@ -1,7 +1,5 @@
<?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 -->
@@ -15,9 +13,9 @@
<xsl:template match="/info">
<result>
- <xsl:for-each select="* intersect abc[xs:integer(x) gt 1] intersect abc[2]">
- <xsl:copy-of select="."/>
- </xsl:for-each>
+ <xsl:variable name="seq1" select="(abc[1], abc[2], abc[3], mno[1])" as="element()*"/>
+ <xsl:variable name="seq2" select="(abc[1], mno[1])" as="element()*"/>
+ <xsl:copy-of select="$seq1 except $seq2"/>
</result>
</xsl:template>
diff --git a/tests/node_sequence_combination/test5.xsl b/tests/node_sequence_combination/test12.xsl
similarity index 85%
copy from tests/node_sequence_combination/test5.xsl
copy to tests/node_sequence_combination/test12.xsl
index f6e850d8f..76eea7fdd 100644
--- a/tests/node_sequence_combination/test5.xsl
+++ b/tests/node_sequence_combination/test12.xsl
@@ -1,7 +1,5 @@
<?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 -->
@@ -15,9 +13,9 @@
<xsl:template match="/info">
<result>
- <xsl:for-each select="* intersect abc[xs:integer(x) gt 1] intersect abc[2]">
- <xsl:copy-of select="."/>
- </xsl:for-each>
+ <xsl:variable name="seq1" select="(abc[1], abc[2], abc[3], mno[1])" as="element()*"/>
+ <xsl:variable name="seq2" select="abc[1] | mno[1]" as="element()*"/>
+ <xsl:copy-of select="$seq1 except $seq2"/>
</result>
</xsl:template>
diff --git a/tests/node_sequence_combination/test5.xsl b/tests/node_sequence_combination/test13.xsl
similarity index 83%
copy from tests/node_sequence_combination/test5.xsl
copy to tests/node_sequence_combination/test13.xsl
index f6e850d8f..22aa20c40 100644
--- a/tests/node_sequence_combination/test5.xsl
+++ b/tests/node_sequence_combination/test13.xsl
@@ -9,15 +9,15 @@
<!-- An XSL 3 test case, to test XPath 3.1 node combination
operator 'intersect'. -->
- <!-- use with test1.xml -->
+ <!-- use with test1.xml -->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/info">
<result>
- <xsl:for-each select="* intersect abc[xs:integer(x) gt 1] intersect abc[2]">
- <xsl:copy-of select="."/>
- </xsl:for-each>
+ <xsl:variable name="seq1" select="(abc[1], abc[2], abc[3], mno[1])" as="element()*"/>
+ <xsl:variable name="seq2" select="(abc[xs:integer(x) gt 2], mno[1])" as="element()*"/>
+ <xsl:copy-of select="$seq1 intersect $seq2"/>
</result>
</xsl:template>
diff --git a/tests/node_sequence_combination/test5.xsl b/tests/node_sequence_combination/test5.xsl
index f6e850d8f..11bf40a4d 100644
--- a/tests/node_sequence_combination/test5.xsl
+++ b/tests/node_sequence_combination/test5.xsl
@@ -15,7 +15,7 @@
<xsl:template match="/info">
<result>
- <xsl:for-each select="* intersect abc[xs:integer(x) gt 1] intersect abc[2]">
+ <xsl:for-each select="* intersect (abc[xs:integer(x) gt 1] intersect abc[2])">
<xsl:copy-of select="."/>
</xsl:for-each>
</result>
diff --git a/tests/node_sequence_combination/test5.xsl b/tests/node_sequence_combination/test9.xsl
similarity index 83%
copy from tests/node_sequence_combination/test5.xsl
copy to tests/node_sequence_combination/test9.xsl
index f6e850d8f..1a675c841 100644
--- a/tests/node_sequence_combination/test5.xsl
+++ b/tests/node_sequence_combination/test9.xsl
@@ -1,7 +1,5 @@
<?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 -->
@@ -9,15 +7,15 @@
<!-- An XSL 3 test case, to test XPath 3.1 node combination
operator 'intersect'. -->
- <!-- use with test1.xml -->
+ <!-- use with test1.xml -->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/info">
<result>
- <xsl:for-each select="* intersect abc[xs:integer(x) gt 1] intersect abc[2]">
- <xsl:copy-of select="."/>
- </xsl:for-each>
+ <xsl:variable name="seq1" select="(abc[1], abc[2], abc[3], mno[1])" as="element()*"/>
+ <xsl:variable name="seq2" select="(abc[1], mno[1])" as="element()*"/>
+ <xsl:copy-of select="$seq1 intersect $seq2"/>
</result>
</xsl:template>
diff --git a/tests/org/apache/xalan/tests/xpath3/XPathNodeSequenceCombinationTests.java b/tests/org/apache/xalan/tests/xpath3/XPathNodeSequenceCombinationTests.java
index 606d8bec1..49d4a32d1 100644
--- a/tests/org/apache/xalan/tests/xpath3/XPathNodeSequenceCombinationTests.java
+++ b/tests/org/apache/xalan/tests/xpath3/XPathNodeSequenceCombinationTests.java
@@ -126,5 +126,55 @@ public class XPathNodeSequenceCombinationTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslNodeseqCombinationTest9() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslNodeseqCombinationTest10() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test10.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslNodeseqCombinationTest11() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test11.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test11.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslNodeseqCombinationTest12() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test12.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test12.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslNodeseqCombinationTest13() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test13.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test13.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