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/07/03 18:01:08 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing improvements to xpath 3.1 fn:for-each function implementation. minor enhancements to implementation of xsl:copy-of instruction for xslt 3.0. adding a related new working xslt 3.0 test case 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 936eb962 committing improvements to xpath 3.1 fn:for-each function implementation. minor enhancements to implementation of xsl:copy-of instruction for xslt 3.0. adding a related new working xslt 3.0 test case as well.
new c25003a2 Merge pull request #17 from mukulga/xalan-j_xslt3.0_mukul
936eb962 is described below
commit 936eb96260021222e580ea3421308ada3c76efd0
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Mon Jul 3 23:23:23 2023 +0530
committing improvements to xpath 3.1 fn:for-each function implementation. minor enhancements to implementation of xsl:copy-of instruction for xslt 3.0. adding a related new working xslt 3.0 test case as well.
---
src/org/apache/xalan/templates/ElemCopyOf.java | 10 ++-
src/org/apache/xpath/functions/FuncForEach.java | 19 ++---
tests/inline_function_expr/gold/test4.out | 32 +++++++++
tests/inline_function_expr/test1_a.xml | 15 ++++
tests/inline_function_expr/test4.xsl | 80 ++++++++++++++++++++++
.../xalan/xpath3/InlineFunctionItemExprTests.java | 10 +++
6 files changed, 156 insertions(+), 10 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemCopyOf.java b/src/org/apache/xalan/templates/ElemCopyOf.java
index 0c9876f3..d1dd523f 100644
--- a/src/org/apache/xalan/templates/ElemCopyOf.java
+++ b/src/org/apache/xalan/templates/ElemCopyOf.java
@@ -33,6 +33,7 @@ import org.apache.xml.serializer.SerializationHandler;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
/*
@@ -52,7 +53,7 @@ import org.apache.xpath.objects.XObject;
*/
public class ElemCopyOf extends ElemTemplateElement
{
- static final long serialVersionUID = -7433828829497411127L;
+ static final long serialVersionUID = -7433828829497411127L;
/**
* The required select attribute contains an expression.
@@ -213,6 +214,13 @@ public class ElemCopyOf extends ElemTemplateElement
handler.characters(spaceCharArr, 0, 1);
}
}
+ else if (sequenceItem.getType() == XObject.CLASS_NUMBER) {
+ String str = ((XNumber)sequenceItem).str();
+ handler.characters(str.toCharArray(), 0, str.length());
+ if (idx < (resultSequence.size() - 1)) {
+ handler.characters(spaceCharArr, 0, 1);
+ }
+ }
else if (sequenceItem.getType() == XObject.CLASS_NODESET) {
DTMIterator nl1 = sequenceItem.iter();
diff --git a/src/org/apache/xpath/functions/FuncForEach.java b/src/org/apache/xpath/functions/FuncForEach.java
index 15d6aeaa..53b03167 100644
--- a/src/org/apache/xpath/functions/FuncForEach.java
+++ b/src/org/apache/xpath/functions/FuncForEach.java
@@ -33,11 +33,10 @@ import org.apache.xpath.XPathContext;
import org.apache.xpath.axes.LocPathIterator;
import org.apache.xpath.objects.InlineFunction;
import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XObjectFactory;
import org.apache.xpath.operations.Variable;
import org.apache.xpath.res.XPATHErrorResources;
-import org.w3c.dom.Node;
/**
* Execute the for-each() function.
@@ -203,17 +202,19 @@ public class FuncForEach extends Function2Args {
}
else if (arg0DtmIterator != null) {
Map<QName, XObject> inlineFunctionVarMap = xctxt.getInlineFunctionVarMap();
-
+
+ final int contextNode = xctxt.getCurrentNode();
+
int dtmNodeHandle;
+
while (DTM.NULL != (dtmNodeHandle = arg0DtmIterator.nextNode())) {
- DTM dtm = xctxt.getDTM(dtmNodeHandle);
- Node node = dtm.getNode(dtmNodeHandle);
- XObject xObject = XObjectFactory.create(node, xctxt);
+ XNodeSet inpSeqItem = new XNodeSet(dtmNodeHandle, xctxt.getDTMManager());
if (varQname != null) {
- inlineFunctionVarMap.put(varQname, xObject);
+ inlineFunctionVarMap.put(varQname, inpSeqItem);
}
-
- XObject resultObj = inlineFnXpath.execute(xctxt, dtmNodeHandle, null);
+
+ XObject resultObj = inlineFnXpath.execute(xctxt, contextNode, null);
+
resultSeq.add(resultObj);
}
diff --git a/tests/inline_function_expr/gold/test4.out b/tests/inline_function_expr/gold/test4.out
new file mode 100644
index 00000000..205f3509
--- /dev/null
+++ b/tests/inline_function_expr/gold/test4.out
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>2 3 4 5 6 7 8 9 10 11</one>
+ <two>4 5 6 7 8 9 10 11 12 13</two>
+ <three>
+ <idx>1</idx>
+ <idx>2</idx>
+ <idx>3</idx>
+ <idx>4</idx>
+ <idx>5</idx>
+ </three>
+ <four>
+ <idx>6</idx>
+ <idx>7</idx>
+ <idx>8</idx>
+ <idx>9</idx>
+ <idx>10</idx>
+ </four>
+ <five>4 8 12 16 20</five>
+ <six>4 8 12 16 20</six>
+ <seven>
+ <sub>2</sub>
+ <sub>2 4</sub>
+ <sub>2 4 6</sub>
+ <sub>2 4 6 8</sub>
+ <sub>2 4 6 8 10</sub>
+ <sub>2 4 6 8 10 12</sub>
+ <sub>2 4 6 8 10 12 14</sub>
+ <sub>2 4 6 8 10 12 14 16</sub>
+ <sub>2 4 6 8 10 12 14 16 18</sub>
+ <sub>2 4 6 8 10 12 14 16 18 20</sub>
+ </seven>
+</result>
diff --git a/tests/inline_function_expr/test1_a.xml b/tests/inline_function_expr/test1_a.xml
new file mode 100644
index 00000000..86f10239
--- /dev/null
+++ b/tests/inline_function_expr/test1_a.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<elem>
+ <list>
+ <idx>1</idx>
+ <idx>2</idx>
+ <idx>3</idx>
+ <idx>4</idx>
+ <idx>5</idx>
+ <idx>6</idx>
+ <idx>7</idx>
+ <idx>8</idx>
+ <idx>9</idx>
+ <idx>10</idx>
+ </list>
+</elem>
\ No newline at end of file
diff --git a/tests/inline_function_expr/test4.xsl b/tests/inline_function_expr/test4.xsl
new file mode 100644
index 00000000..ae0766bc
--- /dev/null
+++ b/tests/inline_function_expr/test4.xsl
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test1_a.xml -->
+
+ <!-- An XSLT stylesheet to test, using XPath function item
+ "inline function" in various ways. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:variable name="func1" select="function($x) { $x + 1 }"/>
+
+ <xsl:variable name="func2" select="function($x) { $x + 3 }"/>
+
+ <xsl:variable name="func3" select="function($x) { count(3 to $x) lt 4 }"/>
+
+ <xsl:variable name="func4" select="function($x) { count(3 to $x) ge 4 }"/>
+
+ <xsl:variable name="func5" select="function($x) { ($x mod 2) eq 0 }"/>
+
+ <xsl:template match="/elem">
+ <result>
+ <one>
+ <xsl:copy-of select="for-each(list/idx, $func1)"/>
+ </one>
+ <two>
+ <xsl:copy-of select="for-each(list/idx, $func2)"/>
+ </two>
+ <three>
+ <xsl:copy-of select="filter(list/idx, $func3)"/>
+ </three>
+ <four>
+ <xsl:copy-of select="filter(list/idx, $func4)"/>
+ </four>
+ <five>
+ <xsl:variable name="evenNums" select="filter(list/idx, $func5)"/>
+ <xsl:copy-of select="for-each($evenNums, function($x) { $x * 2 })"/>
+ </five>
+ <six>
+ <xsl:copy-of select="for-each(filter(list/idx, $func5), function($x) { $x * 2 })"/>
+ </six>
+ <seven>
+ <xsl:apply-templates select="list/idx">
+ <xsl:with-param name="funcA" select="function($x) { $x * 2 }"/>
+ </xsl:apply-templates>
+ </seven>
+ </result>
+ </xsl:template>
+
+ <!-- A template, expecting a function item "inline function"
+ argument. -->
+ <xsl:template match="idx">
+ <xsl:param name="funcA"/>
+ <sub>
+ <xsl:value-of select="for-each(1 to ., $funcA)"/>
+ </sub>
+ </xsl:template>
+
+ <!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java b/tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java
index 1a5d3081..3fc0480c 100644
--- a/tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java
+++ b/tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java
@@ -77,5 +77,15 @@ public class InlineFunctionItemExprTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslInlineFunctionExprTest4() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.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