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/15 09:54:13 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: committing fixes for xalanj jira issue XALANJ-2717, along with few minor changes to codebase comments. committing few related working test cases as well.
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 bcfeb552 committing fixes for xalanj jira issue XALANJ-2717, along with few minor changes to codebase comments. committing few related working test cases as well.
new 893dd19f Merge pull request #140 from mukulga/xalan-j_xslt3.0_mukul
bcfeb552 is described below
commit bcfeb552cd7d1fe036585ce35239417ed51f4476
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Dec 15 15:16:56 2023 +0530
committing fixes for xalanj jira issue XALANJ-2717, along with few minor changes to codebase comments. committing few related working test cases as well.
---
.../apache/xalan/templates/ElemApplyTemplates.java | 64 ++++++++--------------
src/org/apache/xpath/compiler/XPathParser.java | 6 --
.../xpath/composite/SimpleSequenceConstructor.java | 5 --
tests/org/apache/xalan/xslt3/TemplateTests.java | 30 ++++++++++
tests/xsl_template/gold/test2.out | 3 +
tests/xsl_template/gold/test3.out | 3 +
tests/xsl_template/gold/test4.out | 4 ++
tests/xsl_template/test1_b.xml | 3 +
tests/xsl_template/test1_c.xml | 4 ++
tests/xsl_template/test2.xsl | 37 +++++++++++++
tests/xsl_template/test3.xsl | 39 +++++++++++++
tests/xsl_template/test4.xsl | 45 +++++++++++++++
12 files changed, 191 insertions(+), 52 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemApplyTemplates.java b/src/org/apache/xalan/templates/ElemApplyTemplates.java
index 2156cf72..7d4cf0ed 100644
--- a/src/org/apache/xalan/templates/ElemApplyTemplates.java
+++ b/src/org/apache/xalan/templates/ElemApplyTemplates.java
@@ -27,6 +27,7 @@ import javax.xml.transform.TransformerException;
import org.apache.xalan.transformer.StackGuard;
import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.serializer.SerializationHandler;
@@ -36,6 +37,7 @@ import org.apache.xpath.VariableStack;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.composite.SequenceTypeSupport;
+import org.apache.xpath.composite.SimpleSequenceConstructor;
import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XNodeSetForDOM;
@@ -88,12 +90,6 @@ public class ElemApplyTemplates extends ElemCallTemplate
*
*/
private boolean m_isDefaultTemplate = false;
-
-// /**
-// * List of namespace/localname IDs, for identification of xsl:with-param to
-// * xsl:params. Initialized in the compose() method.
-// */
-// private int[] m_paramIDs;
/**
* Set if this belongs to a default template,
@@ -157,10 +153,6 @@ public class ElemApplyTemplates extends ElemCallTemplate
try
{
- // %REVIEW% Do we need this check??
- // if (null != sourceNode)
- // {
- // boolean needToTurnOffInfiniteLoopCheck = false;
QName mode = transformer.getMode();
if (!m_isDefaultTemplate)
@@ -205,7 +197,20 @@ public class ElemApplyTemplates extends ElemCallTemplate
final XPathContext xctxt = transformer.getXPathContext();
final int sourceNode = xctxt.getCurrentNode();
- DTMIterator sourceNodes = m_selectExpression.asIterator(xctxt, sourceNode);
+
+ DTMIterator sourceNodes = null;
+
+ if (m_selectExpression instanceof SimpleSequenceConstructor) {
+ ResultSequence resultSeq = (ResultSequence)(((SimpleSequenceConstructor)
+ m_selectExpression).execute(xctxt));
+ XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence(
+ resultSeq, xctxt);
+ sourceNodes = nodeSet.asIterator(xctxt, sourceNode);
+ }
+ else {
+ sourceNodes = m_selectExpression.asIterator(xctxt, sourceNode);
+ }
+
VariableStack vars = xctxt.getVarStack();
int nParams = getParamElemCount();
int thisframe = vars.getStackFrame();
@@ -227,7 +232,7 @@ public class ElemApplyTemplates extends ElemCallTemplate
? null
: transformer.processSortKeys(this, sourceNode);
- // Sort if we need to.
+ // Sort if we need to
if (null != keys)
sourceNodes = sortNodes(xctxt, keys, sourceNodes);
@@ -239,12 +244,12 @@ public class ElemApplyTemplates extends ElemCallTemplate
}
final SerializationHandler rth = transformer.getSerializationHandler();
-// ContentHandler chandler = rth.getContentHandler();
final StylesheetRoot sroot = transformer.getStylesheet();
final TemplateList tl = sroot.getTemplateListComposed();
final boolean quiet = transformer.getQuietConflictWarnings();
- // Should be able to get this from the iterator but there must be a bug.
+ // Should be able to get this from the iterator
+ // but there might be a codebase issue.
DTM dtm = xctxt.getDTM(sourceNode);
int argsFrame = -1;
@@ -284,9 +289,7 @@ public class ElemApplyTemplates extends ElemCallTemplate
IntStack currentNodes = xctxt.getCurrentNodeStack();
- IntStack currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();
-
- // pushParams(transformer, xctxt);
+ IntStack currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();
int child;
while (DTM.NULL != (child = sourceNodes.nextNode()))
@@ -317,16 +320,12 @@ public class ElemApplyTemplates extends ElemCallTemplate
case DTM.DOCUMENT_FRAGMENT_NODE :
case DTM.ELEMENT_NODE :
template = sroot.getDefaultRule();
- // %OPT% direct faster?
break;
case DTM.ATTRIBUTE_NODE :
case DTM.CDATA_SECTION_NODE :
case DTM.TEXT_NODE :
- // if(rth.m_elemIsPending || rth.m_docPending)
- // rth.flushPending(true);
transformer.pushPairCurrentMatched(sroot.getDefaultTextRule(), child);
transformer.setCurrentElement(sroot.getDefaultTextRule());
- // dtm.dispatchCharactersEvents(child, chandler, false);
dtm.dispatchCharactersEvents(child, rth, false);
transformer.popCurrentMatched();
continue;
@@ -334,8 +333,6 @@ public class ElemApplyTemplates extends ElemCallTemplate
template = sroot.getDefaultRootRule();
break;
default :
-
- // No default rules for processing instructions and the like.
continue;
}
}
@@ -399,9 +396,9 @@ public class ElemApplyTemplates extends ElemCallTemplate
if (templateAsAttrVal != null) {
try {
- // The code within this 'try' block, checks whether the template's result contents
- // conform to the 'sequence type' expression specified as value of template's
- // 'as' attribute.
+ // The codebase logic within this 'try' block, checks whether an
+ // XSLT template's result contents conform to an XPath 'sequence type'
+ // expression specified as value of template's 'as' attribute.
int dtmNodeHandle = transformer.transformToGlobalRTF(template);
@@ -480,21 +477,6 @@ public class ElemApplyTemplates extends ElemCallTemplate
if(template.m_frameSize > 0)
{
- // See Frank Weiss bug around 03/19/2002 (no Bugzilla report yet).
- // While unlink will restore to the proper place, the real position
- // may have been changed for xsl:with-param, so that variables
- // can be accessed.
- // of right now.
- // More:
- // When we entered this function, the current
- // frame buffer (cfb) index in the variable stack may
- // have been manually set. If we just call
- // unlink(), however, it will restore the cfb to the
- // previous link index from the link stack, rather than
- // the manually set cfb. So,
- // the only safe solution is to restore it back
- // to the same position it was on entry, since we're
- // really not working in a stack context here. (Bug4218)
vars.unlink(currentFrameBottom);
xctxt.popRTFContext();
}
diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 80965107..9e654cc6 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -288,7 +288,6 @@ public class XPathParser
new Object[]{ extraTokens }); //"Extra illegal tokens: "+extraTokens);
}
- // Terminate for safety.
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);
@@ -2360,7 +2359,6 @@ public class XPathParser
}
- // Terminate for safety.
if (locationPathStarted)
{
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
@@ -2885,7 +2883,6 @@ public class XPathParser
consumeExpected(')');
- // Terminate for safety.
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
m_ops.setOp(OpMap.MAPINDEX_LENGTH,m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
@@ -2938,7 +2935,6 @@ public class XPathParser
}
}
- // Terminate for safety.
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
m_ops.setOp(OpMap.MAPINDEX_LENGTH,m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
@@ -3290,7 +3286,6 @@ public class XPathParser
appendOp(2, OpCodes.OP_PREDICATE);
Expr();
- // Terminate for safety.
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
@@ -3549,7 +3544,6 @@ public class XPathParser
}
}
- // Terminate for safety.
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
diff --git a/src/org/apache/xpath/composite/SimpleSequenceConstructor.java b/src/org/apache/xpath/composite/SimpleSequenceConstructor.java
index 49c285e4..4f60cc49 100644
--- a/src/org/apache/xpath/composite/SimpleSequenceConstructor.java
+++ b/src/org/apache/xpath/composite/SimpleSequenceConstructor.java
@@ -48,11 +48,6 @@ import xml.xpath31.processor.types.XSNumericType;
* comma operator.
*
* Ref : https://www.w3.org/TR/xpath-31/#construct_seq
- *
- * The XPath grammar fragment, for such a sequence constructor
- * is following,
- *
- * Expr ::= ExprSingle ("," ExprSingle)*
*
* @author Mukul Gandhi <mu...@apache.org>
*
diff --git a/tests/org/apache/xalan/xslt3/TemplateTests.java b/tests/org/apache/xalan/xslt3/TemplateTests.java
index e143624c..6fa4448a 100644
--- a/tests/org/apache/xalan/xslt3/TemplateTests.java
+++ b/tests/org/apache/xalan/xslt3/TemplateTests.java
@@ -56,5 +56,35 @@ public class TemplateTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslTemplateTest2() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_b.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslTemplateTest3() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_b.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslTemplateTest4() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_c.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/tests/xsl_template/gold/test2.out b/tests/xsl_template/gold/test2.out
new file mode 100644
index 00000000..167255ad
--- /dev/null
+++ b/tests/xsl_template/gold/test2.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><root>
+ <p>This is a test</p>
+</root>
\ No newline at end of file
diff --git a/tests/xsl_template/gold/test3.out b/tests/xsl_template/gold/test3.out
new file mode 100644
index 00000000..167255ad
--- /dev/null
+++ b/tests/xsl_template/gold/test3.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><root>
+ <p>This is a test</p>
+</root>
\ No newline at end of file
diff --git a/tests/xsl_template/gold/test4.out b/tests/xsl_template/gold/test4.out
new file mode 100644
index 00000000..d534a441
--- /dev/null
+++ b/tests/xsl_template/gold/test4.out
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?><root>
+ <p>This is a test</p>
+ <q1 attr1="123">hello there</q1>
+</root>
\ No newline at end of file
diff --git a/tests/xsl_template/test1_b.xml b/tests/xsl_template/test1_b.xml
new file mode 100644
index 00000000..5f8e7aca
--- /dev/null
+++ b/tests/xsl_template/test1_b.xml
@@ -0,0 +1,3 @@
+<root>
+ <p>This is a test</p>
+</root>
\ No newline at end of file
diff --git a/tests/xsl_template/test1_c.xml b/tests/xsl_template/test1_c.xml
new file mode 100644
index 00000000..5ccca18e
--- /dev/null
+++ b/tests/xsl_template/test1_c.xml
@@ -0,0 +1,4 @@
+<root>
+ <p>This is a test</p>
+ <q attr1="123">hello there</q>
+</root>
diff --git a/tests/xsl_template/test2.xsl b/tests/xsl_template/test2.xsl
new file mode 100644
index 00000000..564053a8
--- /dev/null
+++ b/tests/xsl_template/test2.xsl
@@ -0,0 +1,37 @@
+<?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 test1_b.xml -->
+
+ <!-- An XSLT 1.0 compatible identity transform -->
+
+ <xsl:template match="@* | node()">
+ <xsl:copy>
+ <xsl:apply-templates select="@* | node()"/>
+ </xsl:copy>
+ </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/xsl_template/test3.xsl b/tests/xsl_template/test3.xsl
new file mode 100644
index 00000000..27b7b1aa
--- /dev/null
+++ b/tests/xsl_template/test3.xsl
@@ -0,0 +1,39 @@
+<?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 test1_b.xml -->
+
+ <!-- An XSLT stylesheet test case, for XalanJ
+ jira issue XALANJ-2717.
+ -->
+
+ <xsl:template match="@* | node()">
+ <xsl:copy>
+ <xsl:apply-templates select="(@*, node())"/>
+ </xsl:copy>
+ </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/xsl_template/test4.xsl b/tests/xsl_template/test4.xsl
new file mode 100644
index 00000000..c83044b4
--- /dev/null
+++ b/tests/xsl_template/test4.xsl
@@ -0,0 +1,45 @@
+<?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 test1_c.xml -->
+
+ <!-- An XSLT stylesheet test case, for XalanJ
+ jira issue XALANJ-2717.
+ -->
+
+ <xsl:template match="@* | node()">
+ <xsl:copy>
+ <xsl:apply-templates select="(@*, node())"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="q">
+ <q1>
+ <xsl:apply-templates select="(@*, node())"/>
+ </q1>
+ </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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org