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/09/23 10:49:49 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing improvements to implementations of xsl:function and xsl:variable instructions, when the sequence constructor present within them has xsl:sequence instruction(s). committing few new 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 c41329c7 committing improvements to implementations of xsl:function and xsl:variable instructions, when the sequence constructor present within them has xsl:sequence instruction(s). committing few new related working test cases as well.
new 0795ce4b Merge pull request #89 from mukulga/xalan-j_xslt3.0_mukul
c41329c7 is described below
commit c41329c78babd905d84739bf0512abe56f649931
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Sep 23 16:15:05 2023 +0530
committing improvements to implementations of xsl:function and xsl:variable instructions, when the sequence constructor present within them has xsl:sequence instruction(s). committing few new related working test cases as well.
---
src/org/apache/xalan/templates/ElemFunction.java | 85 +++++++++++-----------
src/org/apache/xalan/templates/ElemVariable.java | 11 ++-
.../apache/xalan/xslt3/XslSequenceInstTests.java | 53 ++++++++++++++
tests/xsl_sequence_inst/gold/test10.out | 3 +
tests/xsl_sequence_inst/gold/test7.out | 3 +
tests/xsl_sequence_inst/gold/test9.out | 1 +
tests/xsl_sequence_inst/test10.xsl | 50 +++++++++++++
tests/xsl_sequence_inst/test1_b.xml | 5 ++
tests/xsl_sequence_inst/test6.xsl | 47 ++++++++++++
tests/xsl_sequence_inst/test7.xsl | 45 ++++++++++++
tests/xsl_sequence_inst/test8.xsl | 47 ++++++++++++
tests/xsl_sequence_inst/test9.xsl | 45 ++++++++++++
12 files changed, 350 insertions(+), 45 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemFunction.java b/src/org/apache/xalan/templates/ElemFunction.java
index 21834aa3..6c7397b2 100644
--- a/src/org/apache/xalan/templates/ElemFunction.java
+++ b/src/org/apache/xalan/templates/ElemFunction.java
@@ -73,7 +73,7 @@ public class ElemFunction extends ElemTemplate
/**
* The value of the "name" attribute.
*/
- protected QName m_qname;
+ protected static QName m_qname;
public void setName(QName qName)
{
@@ -200,7 +200,7 @@ public class ElemFunction extends ElemTemplate
if (funcAsAttrStrVal != null) {
try {
- funcResultConvertedVal = preprocessXslFunctionOrAVariableResult((XNodeSetForDOM)result, funcAsAttrStrVal, xctxt);
+ funcResultConvertedVal = preprocessXslFunctionOrAVariableResult((XNodeSetForDOM)result, funcAsAttrStrVal, xctxt, null);
if (funcResultConvertedVal == null) {
funcResultConvertedVal = SequenceTypeSupport.convertXDMValueToAnotherType(result, funcAsAttrStrVal, null, xctxt);
@@ -213,9 +213,7 @@ public class ElemFunction extends ElemTemplate
}
}
catch (TransformerException ex) {
- throw new TransformerException("XPTY0004 : The function call result for function {" + funcNameSpaceUri + "}" + funcLocalName +
- "(), doesn't match the declared function result type " +
- funcAsAttrStrVal + ".", srcLocator);
+ throw new TransformerException(ex.getMessage(), srcLocator);
}
}
@@ -286,7 +284,7 @@ public class ElemFunction extends ElemTemplate
*/
public static ResultSequence preprocessXslFunctionOrAVariableResult(XNodeSetForDOM xNodeSetForDOM,
String sequenceTypeXPathExprStr,
- XPathContext xctxt) throws TransformerException {
+ XPathContext xctxt, QName varQName) throws TransformerException {
ResultSequence resultSequence = null;
DTMNodeList dtmNodeList = (DTMNodeList)(xNodeSetForDOM.object());
@@ -311,45 +309,46 @@ public class ElemFunction extends ElemTemplate
if (nodeType == Node.TEXT_NODE) {
String strVal = ((Text)node).getNodeValue();
if (seqExpectedTypeData.getSequenceTypeKindTest() == null) {
- resultSequence = new ResultSequence();
- if ((seqExpectedTypeData.getItemTypeOccurrenceIndicator() == 0) ||
- (seqExpectedTypeData.getItemTypeOccurrenceIndicator() ==
- SequenceTypeSupport.OccurenceIndicator.ZERO_OR_ONE)) {
- if (strVal.contains(ElemSequence.STRING_VAL_SERIALIZATION_SUFFIX)) {
- strVal = strVal.replaceAll(ElemSequence.STRING_VAL_SERIALIZATION_SUFFIX, "");
- XObject xObject = getXSTypedAtomicValue(strVal, seqExpectedTypeData.getSequenceType());
- if (xObject != null) {
- resultSequence.add(xObject);
- }
- }
- else {
- XObject xObject = getXSTypedAtomicValue(strVal, seqExpectedTypeData.getSequenceType());
- if (xObject != null) {
- resultSequence.add(xObject);
- }
- }
- }
- else {
- if (strVal.contains(ElemSequence.STRING_VAL_SERIALIZATION_SUFFIX)) {
- String[] strParts = strVal.split(ElemSequence.STRING_VAL_SERIALIZATION_SUFFIX);
- for (int idx = 0; idx < strParts.length; idx++) {
- String seqItemStrVal = strParts[idx];
- XObject xObject = getXSTypedAtomicValue(seqItemStrVal, seqExpectedTypeData.getSequenceType());
- if (xObject != null) {
- resultSequence.add(xObject);
- }
- }
- }
- else {
- XObject xObject = getXSTypedAtomicValue(strVal, seqExpectedTypeData.getSequenceType());
- if (xObject != null) {
- resultSequence.add(xObject);
- }
- }
- }
+ resultSequence = new ResultSequence();
+ if (strVal.contains(ElemSequence.STRING_VAL_SERIALIZATION_SUFFIX)) {
+ String[] strParts = strVal.split(ElemSequence.STRING_VAL_SERIALIZATION_SUFFIX);
+ for (int idx = 0; idx < strParts.length; idx++) {
+ String seqItemStrVal = strParts[idx];
+ XObject xObject = getXSTypedAtomicValue(seqItemStrVal, seqExpectedTypeData.getSequenceType());
+ if (xObject != null) {
+ resultSequence.add(xObject);
+ }
+ }
+ }
+ else {
+ XObject xObject = getXSTypedAtomicValue(strVal, seqExpectedTypeData.getSequenceType());
+ if (xObject != null) {
+ resultSequence.add(xObject);
+ }
+ }
+ }
+ }
+ }
+
+ if (seqExpectedTypeData.getSequenceTypeKindTest() == null) {
+ if ((seqExpectedTypeData.getItemTypeOccurrenceIndicator() == 0) ||
+ (seqExpectedTypeData.getItemTypeOccurrenceIndicator() ==
+ SequenceTypeSupport.OccurenceIndicator.ZERO_OR_ONE)) {
+ if ((resultSequence != null) && (resultSequence.size() > 1)) {
+ String errMesg = null;
+ if (m_qname != null) {
+ errMesg = "XTTE0780 : A sequence of more than one item, is not allowed as a result of call to function '" + m_qname.toString() + "'. "
+ + "The expected result type of this function is " + sequenceTypeXPathExprStr + ".";
+ }
+ else {
+ errMesg = "XTTE0570 : A sequence of more than one item, is not allowed as the value of variable '$" + varQName.toString() + "'. "
+ + "This variable has expected type " + sequenceTypeXPathExprStr + ".";
+ }
+
+ throw new TransformerException(errMesg);
}
}
- }
+ }
return resultSequence;
}
diff --git a/src/org/apache/xalan/templates/ElemVariable.java b/src/org/apache/xalan/templates/ElemVariable.java
index 715ea666..4d38b254 100644
--- a/src/org/apache/xalan/templates/ElemVariable.java
+++ b/src/org/apache/xalan/templates/ElemVariable.java
@@ -558,8 +558,15 @@ public class ElemVariable extends ElemTemplateElement
if (m_asAttr != null) {
if (var instanceof XNodeSetForDOM) {
- XObject variableConvertedVal = ElemFunction.preprocessXslFunctionOrAVariableResult(
- (XNodeSetForDOM)var, m_asAttr, xctxt);
+ XObject variableConvertedVal = null;
+
+ try {
+ variableConvertedVal = ElemFunction.preprocessXslFunctionOrAVariableResult((XNodeSetForDOM)var, m_asAttr, xctxt, m_qname);
+ }
+ catch (TransformerException ex) {
+ throw new TransformerException(ex.getMessage(), srcLocator);
+ }
+
if (variableConvertedVal != null) {
var = variableConvertedVal;
}
diff --git a/tests/org/apache/xalan/xslt3/XslSequenceInstTests.java b/tests/org/apache/xalan/xslt3/XslSequenceInstTests.java
index 9b255a0f..0c5fd760 100644
--- a/tests/org/apache/xalan/xslt3/XslSequenceInstTests.java
+++ b/tests/org/apache/xalan/xslt3/XslSequenceInstTests.java
@@ -16,6 +16,7 @@
*/
package org.apache.xalan.xslt3;
+import org.apache.xalan.util.XslTestsErrorHandler;
import org.apache.xalan.util.XslTransformTestsUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -99,5 +100,57 @@ public class XslSequenceInstTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslSequenceTest6() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test7.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslSequenceTest7() {
+ 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);
+ }
+
+ @Test
+ public void xslSequenceTest8() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test8.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test8.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
+ new XslTestsErrorHandler());
+ }
+
+ @Test
+ public void xslSequenceTest9() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
+ new XslTestsErrorHandler());
+ }
+
+ @Test
+ public void xslSequenceTest10() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_b.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test10.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/tests/xsl_sequence_inst/gold/test10.out b/tests/xsl_sequence_inst/gold/test10.out
new file mode 100644
index 00000000..84b8fade
--- /dev/null
+++ b/tests/xsl_sequence_inst/gold/test10.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <mesg count="3">hello hi there</mesg>
+</result>
diff --git a/tests/xsl_sequence_inst/gold/test7.out b/tests/xsl_sequence_inst/gold/test7.out
new file mode 100644
index 00000000..db1767cd
--- /dev/null
+++ b/tests/xsl_sequence_inst/gold/test7.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <mesg count="5">hello hello hello hello hello</mesg>
+</result>
diff --git a/tests/xsl_sequence_inst/gold/test9.out b/tests/xsl_sequence_inst/gold/test9.out
new file mode 100644
index 00000000..f41b0d0c
--- /dev/null
+++ b/tests/xsl_sequence_inst/gold/test9.out
@@ -0,0 +1 @@
+<no_op/>
\ No newline at end of file
diff --git a/tests/xsl_sequence_inst/test10.xsl b/tests/xsl_sequence_inst/test10.xsl
new file mode 100644
index 00000000..e80ca3ed
--- /dev/null
+++ b/tests/xsl_sequence_inst/test10.xsl
@@ -0,0 +1,50 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="xs fn0"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test1_b.xml -->
+
+ <!-- An XSLT stylesheet test, to test an xsl:sequence
+ instruction.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/info">
+ <result>
+ <mesg count="{count(fn0:str1(mesg))}">
+ <xsl:copy-of select="fn0:str1(mesg)"/>
+ </mesg>
+ </result>
+ </xsl:template>
+
+ <xsl:function name="fn0:str1" as="xs:string*">
+ <xsl:param name="mesgList" as="element(mesg)*"/>
+ <xsl:for-each select="$mesgList">
+ <xsl:sequence select="string(.)"/>
+ </xsl:for-each>
+ </xsl:function>
+
+ <!--
+ * 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_sequence_inst/test1_b.xml b/tests/xsl_sequence_inst/test1_b.xml
new file mode 100644
index 00000000..b172509a
--- /dev/null
+++ b/tests/xsl_sequence_inst/test1_b.xml
@@ -0,0 +1,5 @@
+<info>
+ <mesg>hello</mesg>
+ <mesg>hi</mesg>
+ <mesg>there</mesg>
+</info>
\ No newline at end of file
diff --git a/tests/xsl_sequence_inst/test6.xsl b/tests/xsl_sequence_inst/test6.xsl
new file mode 100644
index 00000000..bfd8df89
--- /dev/null
+++ b/tests/xsl_sequence_inst/test6.xsl
@@ -0,0 +1,47 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="xs fn0"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test an xsl:sequence
+ instruction.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <mesg count="{count(fn0:str1())}">
+ <xsl:copy-of select="fn0:str1()"/>
+ </mesg>
+ </result>
+ </xsl:template>
+
+ <xsl:function name="fn0:str1" as="xs:string*">
+ <xsl:for-each select="1 to 5">
+ <xsl:sequence select="'hello'"/>
+ </xsl:for-each>
+ </xsl:function>
+
+ <!--
+ * 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_sequence_inst/test7.xsl b/tests/xsl_sequence_inst/test7.xsl
new file mode 100644
index 00000000..2f645fd9
--- /dev/null
+++ b/tests/xsl_sequence_inst/test7.xsl
@@ -0,0 +1,45 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ exclude-result-prefixes="xs"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test an xsl:sequence
+ instruction.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="strList" as="xs:string*">
+ <xsl:for-each select="1 to 5">
+ <xsl:sequence select="'hello'"/>
+ </xsl:for-each>
+ </xsl:variable>
+ <mesg count="{count($strList)}">
+ <xsl:copy-of select="$strList"/>
+ </mesg>
+ </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>
\ No newline at end of file
diff --git a/tests/xsl_sequence_inst/test8.xsl b/tests/xsl_sequence_inst/test8.xsl
new file mode 100644
index 00000000..92a58b81
--- /dev/null
+++ b/tests/xsl_sequence_inst/test8.xsl
@@ -0,0 +1,47 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="xs fn0"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test an xsl:sequence
+ instruction.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <mesg count="{count(fn0:str1())}">
+ <xsl:copy-of select="fn0:str1()"/>
+ </mesg>
+ </result>
+ </xsl:template>
+
+ <xsl:function name="fn0:str1" as="xs:string">
+ <xsl:for-each select="1 to 5">
+ <xsl:sequence select="'hello'"/>
+ </xsl:for-each>
+ </xsl:function>
+
+ <!--
+ * 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_sequence_inst/test9.xsl b/tests/xsl_sequence_inst/test9.xsl
new file mode 100644
index 00000000..bdc19102
--- /dev/null
+++ b/tests/xsl_sequence_inst/test9.xsl
@@ -0,0 +1,45 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ exclude-result-prefixes="xs"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test an xsl:sequence
+ instruction.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="strList" as="xs:string">
+ <xsl:for-each select="1 to 5">
+ <xsl:sequence select="'hello'"/>
+ </xsl:for-each>
+ </xsl:variable>
+ <mesg count="{count($strList)}">
+ <xsl:copy-of select="$strList"/>
+ </mesg>
+ </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>
\ 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