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/05 13:16:25 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing implementation of an xslt 3.0 xsl:variable 'as' attribute when the variable declaration has a contained sequence constructor, along with few related new working test cases. also doing minor xalanj codebase improvements and refactoring on this dev repos branch, and committing a new working test case for xpath 3.1 dynamic function call.
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 6ee54d72 committing implementation of an xslt 3.0 xsl:variable 'as' attribute when the variable declaration has a contained sequence constructor, along with few related new working test cases. also doing minor xalanj codebase improvements and refactoring on this dev repos branch, and committing a new working test case for xpath 3.1 dynamic function call.
new fb0fb41a Merge pull request #75 from mukulga/xalan-j_xslt3.0_mukul
6ee54d72 is described below
commit 6ee54d7237a05899e3d2f81b01fb89ce4a77c23f
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue Sep 5 18:41:40 2023 +0530
committing implementation of an xslt 3.0 xsl:variable 'as' attribute when the variable declaration has a contained sequence constructor, along with few related new working test cases. also doing minor xalanj codebase improvements and refactoring on this dev repos branch, and committing a new working test case for xpath 3.1 dynamic function call.
---
src/org/apache/xalan/templates/ElemCopyOf.java | 7 +-
src/org/apache/xpath/compiler/XPathParser.java | 10 +-
.../xpath/composite/SequenceTypeSupport.java | 180 +++++++++++++++++++--
tests/dynamic_function_call/gold/test16.out | 35 ++++
.../test3.xsl => dynamic_function_call/test16.xsl} | 39 ++---
.../xalan/xpath3/DynamicFunctionCallTests.java | 10 ++
.../apache/xalan/xslt3/XslAttributeAsTests.java | 45 +++++-
tests/xsl_attribute_as/gold/test10.out | 7 +
tests/xsl_attribute_as/gold/test11.out | 4 +
tests/xsl_attribute_as/gold/test12.out | 11 ++
tests/xsl_attribute_as/gold/test3_1.out | 1 +
tests/xsl_attribute_as/gold/test9.out | 17 ++
tests/xsl_attribute_as/{test3.xsl => test10.xsl} | 43 +++--
tests/xsl_attribute_as/{test3.xsl => test11.xsl} | 37 +++--
tests/xsl_attribute_as/{test3.xsl => test12.xsl} | 24 +--
tests/xsl_attribute_as/{test3.xsl => test13.xsl} | 33 ++--
tests/xsl_attribute_as/test3.xsl | 5 -
17 files changed, 424 insertions(+), 84 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemCopyOf.java b/src/org/apache/xalan/templates/ElemCopyOf.java
index a747e35d..160a002e 100644
--- a/src/org/apache/xalan/templates/ElemCopyOf.java
+++ b/src/org/apache/xalan/templates/ElemCopyOf.java
@@ -200,7 +200,7 @@ public class ElemCopyOf extends ElemTemplateElement
str = value.str();
handler.characters(str.toCharArray(), 0, str.length());
- break;
+ break;
case XObject.CLASS_NODESET :
copyOfActionOnNodeSet((XNodeSet)value, transformer, handler, xctxt);
break;
@@ -220,6 +220,11 @@ public class ElemCopyOf extends ElemTemplateElement
break;
}
+
+ if (value instanceof XSNumericType) {
+ str = ((XSNumericType)value).stringValue();
+ handler.characters(str.toCharArray(), 0, str.length());
+ }
}
}
diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 18325b6c..6a6255fb 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -849,8 +849,8 @@ public class XPathParser
/**
* This method helps to implement, XPath 3.1 sequence type expressions.
*/
- private SequenceTypeKindTest constructSeqTypeKindTestForXmlNodes(XPathSequenceTypeExpr
- xpathSequenceTypeExpr, int nodeType) throws TransformerException {
+ private SequenceTypeKindTest constructSequenceTypeKindTestForXDMNodes(XPathSequenceTypeExpr
+ xpathSequenceTypeExpr, int nodeType) throws TransformerException {
SequenceTypeKindTest sequenceTypeKindTest = new SequenceTypeKindTest();
@@ -877,7 +877,7 @@ public class XPathParser
}
else {
throw new javax.xml.transform.TransformerException("XPST0051 : The sequence type expression is "
- + "not well-formed. The expected token ')' within "
+ + "not well-formed. An expected token ')' within "
+ "a sequence type expression is not present.");
}
@@ -3748,12 +3748,12 @@ public class XPathParser
}
}
else if (tokenIs("element")) {
- sequenceTypeKindTest = constructSeqTypeKindTestForXmlNodes(xpathSequenceTypeExpr,
+ sequenceTypeKindTest = constructSequenceTypeKindTestForXDMNodes(xpathSequenceTypeExpr,
SequenceTypeSupport.ELEMENT_KIND);
xpathSequenceTypeExpr.setSequenceTypeKindTest(sequenceTypeKindTest);
}
else if (tokenIs("attribute")) {
- sequenceTypeKindTest = constructSeqTypeKindTestForXmlNodes(xpathSequenceTypeExpr,
+ sequenceTypeKindTest = constructSequenceTypeKindTestForXDMNodes(xpathSequenceTypeExpr,
SequenceTypeSupport.ATTRIBUTE_KIND);
xpathSequenceTypeExpr.setSequenceTypeKindTest(sequenceTypeKindTest);
}
diff --git a/src/org/apache/xpath/composite/SequenceTypeSupport.java b/src/org/apache/xpath/composite/SequenceTypeSupport.java
index dae54636..2d38cfb8 100644
--- a/src/org/apache/xpath/composite/SequenceTypeSupport.java
+++ b/src/org/apache/xpath/composite/SequenceTypeSupport.java
@@ -16,6 +16,9 @@
*/
package org.apache.xpath.composite;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;
@@ -23,11 +26,13 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.DTMManager;
+import org.apache.xml.dtm.ref.DTMNodeList;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNodeSetForDOM;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.objects.XString;
@@ -48,6 +53,8 @@ import org.apache.xpath.xs.types.XSTime;
import org.apache.xpath.xs.types.XSUntyped;
import org.apache.xpath.xs.types.XSUntypedAtomic;
import org.apache.xpath.xs.types.XSYearMonthDuration;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* This class provides few utility methods, to help implement
@@ -98,7 +105,7 @@ public class SequenceTypeSupport {
public static int XS_FLOAT = 15;
-
+
public static int ELEMENT_KIND = 101;
public static int ATTRIBUTE_KIND = 102;
@@ -180,9 +187,14 @@ public class SequenceTypeSupport {
if (expectedType == STRING) {
result = srcValue;
}
- else if (sequenceTypeKindTest != null) {
- result = performXdmItemTypeNormalizationOnAtomicType(sequenceTypeKindTest, srcValue, srcStrVal,
- "xs:string", sequenceTypeXPathExprStr);
+ else if (sequenceTypeKindTest != null) {
+ if (sequenceTypeKindTest.getKindVal() == TEXT_KIND) {
+ result = srcValue;
+ }
+ else {
+ result = performXdmItemTypeNormalizationOnAtomicType(sequenceTypeKindTest, srcValue, srcStrVal,
+ "xs:string", sequenceTypeXPathExprStr);
+ }
}
else {
result = convertStringValueToAnExpectedType(srcStrVal, expectedType);
@@ -195,8 +207,13 @@ public class SequenceTypeSupport {
result = srcValue;
}
else if (sequenceTypeKindTest != null) {
- result = performXdmItemTypeNormalizationOnAtomicType(sequenceTypeKindTest, srcValue, srcStrVal,
- "xs:string", sequenceTypeXPathExprStr);
+ if (sequenceTypeKindTest.getKindVal() == TEXT_KIND) {
+ result = srcValue;
+ }
+ else {
+ result = performXdmItemTypeNormalizationOnAtomicType(sequenceTypeKindTest, srcValue, srcStrVal,
+ "xs:string", sequenceTypeXPathExprStr);
+ }
}
else {
result = convertStringValueToAnExpectedType(srcStrVal, expectedType);
@@ -327,6 +344,125 @@ public class SequenceTypeSupport {
String srcStrVal = ((XSUntypedAtomic)srcValue).stringValue();
result = convertXDMValueToAnotherType(new XSString(srcStrVal), sequenceTypeXPathExprStr, xctxt);
}
+ else if (srcValue instanceof XNodeSetForDOM) {
+ XNodeSetForDOM xNodeSetForDOM = (XNodeSetForDOM)srcValue;
+ DTMNodeList dtmNodeList = (DTMNodeList)(xNodeSetForDOM.object());
+
+ DTMManager dtmMgr = xNodeSetForDOM.getDTMManager();
+
+ List<Integer> nodesDtmList = new ArrayList<Integer>();
+
+ ResultSequence convertedResultSeq = new ResultSequence();
+
+ Node localRootNode = dtmNodeList.item(0);
+ NodeList nodeList = localRootNode.getChildNodes();
+ int nodeSetLen = nodeList.getLength();
+
+ if ((nodeSetLen > 1) && ((itemTypeOccurenceIndicator == 0) || (itemTypeOccurenceIndicator ==
+ OccurenceIndicator.ZERO_OR_ONE))) {
+ throw new TransformerException("XTTE0570 : A sequence of size " + nodeSetLen + ", cannot be cast to a type "
+ + sequenceTypeXPathExprStr + ".", srcLocator);
+ }
+ else {
+ for (int idx = 0; idx < nodeSetLen; idx++) {
+ Node node = nodeList.item(idx);
+
+ int nodeDtmHandle = dtmMgr.getDTMHandleFromNode(node);
+ nodesDtmList.add(Integer.valueOf(nodeDtmHandle));
+
+ String sequenceTypeNewXPathExprStr = null;
+ if (sequenceTypeXPathExprStr.endsWith(Q_MARK) || sequenceTypeXPathExprStr.endsWith(STAR) ||
+ sequenceTypeXPathExprStr.endsWith(PLUS)) {
+ sequenceTypeNewXPathExprStr = sequenceTypeXPathExprStr.substring(0, sequenceTypeXPathExprStr.length() - 1);
+ }
+
+ if (sequenceTypeKindTest != null) {
+ String nodeName = node.getLocalName();
+ String nodeNsUri = node.getNamespaceURI();
+
+ if (sequenceTypeKindTest.getDataTypeName() != null) {
+ String dataTypeStr = (sequenceTypeNewXPathExprStr != null) ? sequenceTypeNewXPathExprStr : sequenceTypeXPathExprStr;
+ throw new TransformerException("XTTE0570 : The required item type of an XML instance node is " + dataTypeStr +
+ ". The supplied value " + nodeName + " does not match. The "
+ + "supplied node has not been validated with a schema.", srcLocator);
+ }
+ else {
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ String elemNodeKindTestNodeName = sequenceTypeKindTest.getNodeLocalName();
+ if (elemNodeKindTestNodeName == null || "".equals(elemNodeKindTestNodeName) ||
+ STAR.equals(elemNodeKindTestNodeName)) {
+ elemNodeKindTestNodeName = nodeName;
+ }
+
+ boolean isSeqTypeMatchOk = false;
+
+ if ((sequenceTypeKindTest.getKindVal() == ELEMENT_KIND) && (nodeName.equals(elemNodeKindTestNodeName))
+ && (isTwoXmlNamespacesEqual(nodeNsUri, sequenceTypeKindTest.getNodeNsUri()))) {
+ isSeqTypeMatchOk = true;
+ }
+ else if ((sequenceTypeKindTest.getKindVal() == NODE_KIND) || (sequenceTypeKindTest.getKindVal() == ITEM_KIND)) {
+ isSeqTypeMatchOk = true;
+ }
+
+ if (!isSeqTypeMatchOk) {
+ String dataTypeStr = (sequenceTypeNewXPathExprStr != null) ? sequenceTypeNewXPathExprStr : sequenceTypeXPathExprStr;
+ throw new TransformerException("XTTE0570 : The required item type of an XML instance node is " + dataTypeStr +
+ ". The supplied value " + nodeName + " does not match.", srcLocator);
+ }
+ }
+ else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
+ String attrNodeKindTestNodeName = sequenceTypeKindTest.getNodeLocalName();
+ if (attrNodeKindTestNodeName == null || "".equals(attrNodeKindTestNodeName) ||
+ STAR.equals(attrNodeKindTestNodeName)) {
+ attrNodeKindTestNodeName = nodeName;
+ }
+
+ boolean isSeqTypeMatchOk = false;
+
+ if ((sequenceTypeKindTest.getKindVal() == ATTRIBUTE_KIND) && (nodeName.equals(attrNodeKindTestNodeName))
+ && (isTwoXmlNamespacesEqual(nodeNsUri, sequenceTypeKindTest.getNodeNsUri()))) {
+ isSeqTypeMatchOk = true;
+ }
+ else if ((sequenceTypeKindTest.getKindVal() == NODE_KIND) || (sequenceTypeKindTest.getKindVal() == ITEM_KIND)) {
+ isSeqTypeMatchOk = true;
+ }
+
+ if (!isSeqTypeMatchOk) {
+ String dataTypeStr = (sequenceTypeNewXPathExprStr != null) ? sequenceTypeNewXPathExprStr : sequenceTypeXPathExprStr;
+ throw new TransformerException("XTTE0570 : The required item type of an XML instance node is " + dataTypeStr +
+ ". The supplied value " + nodeName + " does not match.", srcLocator);
+ }
+ }
+ else if (node.getNodeType() == Node.TEXT_NODE) {
+ if (!((sequenceTypeKindTest.getKindVal() == TEXT_KIND) ||
+ (sequenceTypeKindTest.getKindVal() == NODE_KIND) ||
+ (sequenceTypeKindTest.getKindVal() == ITEM_KIND))) {
+ String dataTypeStr = (sequenceTypeNewXPathExprStr != null) ? sequenceTypeNewXPathExprStr : sequenceTypeXPathExprStr;
+ throw new TransformerException("XTTE0570 : The required item type of an XML instance node is " + dataTypeStr + ". "
+ + "The supplied value does not match.", srcLocator);
+ }
+ }
+ }
+ }
+ else {
+ if (sequenceTypeNewXPathExprStr == null) {
+ sequenceTypeNewXPathExprStr = sequenceTypeXPathExprStr;
+ }
+
+ String nodeStrVal = node.getNodeValue();
+ XObject xObject = convertXDMValueToAnotherType(new XSString(nodeStrVal), sequenceTypeNewXPathExprStr, xctxt);
+ convertedResultSeq.add(xObject);
+ }
+ }
+ }
+
+ if (convertedResultSeq.size() > 0) {
+ result = convertedResultSeq;
+ }
+ else {
+ result = new XNodeSet(nodesDtmList, dtmMgr);
+ }
+ }
else if (srcValue instanceof XNodeSet) {
XNodeSet xdmNodeSet = (XNodeSet)srcValue;
@@ -347,8 +483,7 @@ public class SequenceTypeSupport {
int nextNodeDtmHandle;
while ((nextNodeDtmHandle = dtmIter.nextNode()) != DTM.NULL) {
- XNodeSet nodeSetItem = new XNodeSet(nextNodeDtmHandle, xctxt);
- String nodeStrVal = nodeSetItem.str();
+ XNodeSet nodeSetItem = new XNodeSet(nextNodeDtmHandle, xctxt);
String sequenceTypeNewXPathExprStr = null;
if (sequenceTypeXPathExprStr.endsWith(Q_MARK) || sequenceTypeXPathExprStr.endsWith(STAR) ||
@@ -437,7 +572,9 @@ public class SequenceTypeSupport {
else {
if (sequenceTypeNewXPathExprStr == null) {
sequenceTypeNewXPathExprStr = sequenceTypeXPathExprStr;
- }
+ }
+
+ String nodeStrVal = nodeSetItem.str();
XObject xObject = convertXDMValueToAnotherType(new XSString(nodeStrVal), sequenceTypeNewXPathExprStr, xctxt);
convertedResultSeq.add(xObject);
}
@@ -480,7 +617,12 @@ public class SequenceTypeSupport {
}
}
catch (TransformerException ex) {
- throw ex;
+ if (ex.getLocator() != null) {
+ throw ex;
+ }
+ else {
+ throw new TransformerException(ex.getMessage(), srcLocator);
+ }
}
catch (Exception ex) {
String srcStrVal = XslTransformEvaluationHelper.getStrVal(srcValue);
@@ -509,6 +651,24 @@ public class SequenceTypeSupport {
result = new XSBoolean(true);
}
}
+ else if (expectedType == XS_DECIMAL) {
+ result = new XSDecimal(srcStrVal);
+ }
+ else if (expectedType == XS_INTEGER) {
+ result = new XSInteger(srcStrVal);
+ }
+ else if (expectedType == XS_LONG) {
+ result = new XSLong(srcStrVal);
+ }
+ else if (expectedType == XS_INT) {
+ result = new XSInt(srcStrVal);
+ }
+ else if (expectedType == XS_DOUBLE) {
+ result = new XSDouble(srcStrVal);
+ }
+ else if (expectedType == XS_FLOAT) {
+ result = new XSFloat(srcStrVal);
+ }
else if (expectedType == XS_DATE) {
result = XSDate.parseDate(srcStrVal);
}
diff --git a/tests/dynamic_function_call/gold/test16.out b/tests/dynamic_function_call/gold/test16.out
new file mode 100644
index 00000000..ccce041b
--- /dev/null
+++ b/tests/dynamic_function_call/gold/test16.out
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?><factorial>
+ <inp val="0">
+ <result>1</result>
+ </inp>
+ <inp val="1">
+ <result>1</result>
+ </inp>
+ <inp val="2">
+ <result>2</result>
+ </inp>
+ <inp val="3">
+ <result>6</result>
+ </inp>
+ <inp val="4">
+ <result>24</result>
+ </inp>
+ <inp val="5">
+ <result>120</result>
+ </inp>
+ <inp val="6">
+ <result>720</result>
+ </inp>
+ <inp val="7">
+ <result>5040</result>
+ </inp>
+ <inp val="8">
+ <result>40320</result>
+ </inp>
+ <inp val="9">
+ <result>362880</result>
+ </inp>
+ <inp val="10">
+ <result>3628800</result>
+ </inp>
+</factorial>
diff --git a/tests/xsl_attribute_as/test3.xsl b/tests/dynamic_function_call/test16.xsl
similarity index 60%
copy from tests/xsl_attribute_as/test3.xsl
copy to tests/dynamic_function_call/test16.xsl
index 99797a60..c23309ba 100644
--- a/tests/xsl_attribute_as/test3.xsl
+++ b/tests/dynamic_function_call/test16.xsl
@@ -1,28 +1,31 @@
<?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 -->
-
- <!-- An XSLT stylesheet test case, to test the sequence type
- declaration attribute "as" on an xsl:variable instruction.
-
- This stylesheet produces an XSLT transformation error,
- because the XPath 3.1 function conversion rules don't allow
- xs:string values to be converted to numeric types (like
- xs:integer as mentioned within this example).
- -->
+
+ <!-- This XSLT stylesheet test case, tests function recursion,
+ for an XPath 3.1 dynamic function call.
+
+ This stylesheet, specifies an XPath inline function expression
+ to calculate factorial of a numerical integer value.
+ -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="var1" select="'4'" as="xs:integer"/>
-
+ <xsl:variable name="factorial" select="function($num) {if ($num = 0) then 1 else ($num * $factorial($num - 1))}"/>
+
<xsl:template match="/">
- <result>
- <xsl:value-of select="$var1"/>
- </result>
+ <factorial>
+ <xsl:for-each select="0 to 10">
+ <xsl:variable name="num" select="."/>
+ <inp val="{$num}">
+ <result>
+ <xsl:value-of select="$factorial($num)"/>
+ </result>
+ </inp>
+ </xsl:for-each>
+ </factorial>
</xsl:template>
<!--
@@ -41,6 +44,6 @@
* 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/DynamicFunctionCallTests.java b/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java
index aef54c6d..85f24f7b 100644
--- a/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java
+++ b/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java
@@ -196,5 +196,15 @@ public class DynamicFunctionCallTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslDynamicFunctionCallTest16() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test16.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test16.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test16.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/tests/org/apache/xalan/xslt3/XslAttributeAsTests.java b/tests/org/apache/xalan/xslt3/XslAttributeAsTests.java
index 4ccdbb7e..14efd16e 100644
--- a/tests/org/apache/xalan/xslt3/XslAttributeAsTests.java
+++ b/tests/org/apache/xalan/xslt3/XslAttributeAsTests.java
@@ -76,10 +76,9 @@ public class XslAttributeAsTests extends XslTransformTestsUtil {
String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
- String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3_1.out";
- runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
- new XslTestsErrorHandler());
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
@Test
@@ -142,5 +141,45 @@ public class XslAttributeAsTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslAttributeAsTest10() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslAttributeAsTest11() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test11.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test11.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test10.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslAttributeAsTest12() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test12.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test12.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test11.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslAttributeAsTest13() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test13.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test13.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test12.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/tests/xsl_attribute_as/gold/test10.out b/tests/xsl_attribute_as/gold/test10.out
new file mode 100644
index 00000000..c1ffd9fc
--- /dev/null
+++ b/tests/xsl_attribute_as/gold/test10.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <a1/>
+ <a1/>
+ <a1/>
+ <a1/>
+ <a1/>
+</result>
diff --git a/tests/xsl_attribute_as/gold/test11.out b/tests/xsl_attribute_as/gold/test11.out
new file mode 100644
index 00000000..0271626d
--- /dev/null
+++ b/tests/xsl_attribute_as/gold/test11.out
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>123</one>
+ <two>123</two>
+</result>
diff --git a/tests/xsl_attribute_as/gold/test12.out b/tests/xsl_attribute_as/gold/test12.out
new file mode 100644
index 00000000..a87c899b
--- /dev/null
+++ b/tests/xsl_attribute_as/gold/test12.out
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one nodeCount="3">
+ <elem>
+ <a>123</a>
+ </elem>
+ hi there
+ <elem>
+ <b>456</b>
+ </elem>
+ </one>
+</result>
diff --git a/tests/xsl_attribute_as/gold/test3_1.out b/tests/xsl_attribute_as/gold/test3_1.out
new file mode 100644
index 00000000..ee3405a6
--- /dev/null
+++ b/tests/xsl_attribute_as/gold/test3_1.out
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><result>4</result>
diff --git a/tests/xsl_attribute_as/gold/test9.out b/tests/xsl_attribute_as/gold/test9.out
new file mode 100644
index 00000000..f46d87c9
--- /dev/null
+++ b/tests/xsl_attribute_as/gold/test9.out
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>
+ <elem1>a1</elem1>
+ <elem2>b1</elem2>
+ <elem3>c1</elem3>
+ </one>
+ <two>
+ <elem1>p2</elem1>
+ <elem2>q2</elem2>
+ <elem3>r2</elem3>
+ </two>
+ <three>
+ <a1>m3</a1>
+ <a1>n3</a1>
+ <a1>o3</a1>
+ </three>
+</result>
diff --git a/tests/xsl_attribute_as/test3.xsl b/tests/xsl_attribute_as/test10.xsl
similarity index 59%
copy from tests/xsl_attribute_as/test3.xsl
copy to tests/xsl_attribute_as/test10.xsl
index 99797a60..137271ef 100644
--- a/tests/xsl_attribute_as/test3.xsl
+++ b/tests/xsl_attribute_as/test10.xsl
@@ -1,27 +1,48 @@
<?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 -->
<!-- An XSLT stylesheet test case, to test the sequence type
declaration attribute "as" on an xsl:variable instruction.
- This stylesheet produces an XSLT transformation error,
- because the XPath 3.1 function conversion rules don't allow
- xs:string values to be converted to numeric types (like
- xs:integer as mentioned within this example).
- -->
+ Within this stylesheet example, the values of the variables
+ are determined using the sequence constructor provided as
+ xsl:variable's XML child contents. The values of the
+ stylesheet variables need to conform to the sequence type
+ mentioned as value of xsl:variable's "as" attribute.
+ -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="var1" select="'4'" as="xs:integer"/>
-
+ <xsl:variable name="var1" as="element()*">
+ <elem1>a1</elem1>
+ <elem2>b1</elem2>
+ <elem3>c1</elem3>
+ </xsl:variable>
+ <xsl:variable name="var2" as="element(*)*">
+ <elem1>p2</elem1>
+ <elem2>q2</elem2>
+ <elem3>r2</elem3>
+ </xsl:variable>
+ <xsl:variable name="var3" as="element(a1)*">
+ <a1>m3</a1>
+ <a1>n3</a1>
+ <a1>o3</a1>
+ </xsl:variable>
+
<xsl:template match="/">
<result>
- <xsl:value-of select="$var1"/>
+ <one>
+ <xsl:copy-of select="$var1"/>
+ </one>
+ <two>
+ <xsl:copy-of select="$var2"/>
+ </two>
+ <three>
+ <xsl:copy-of select="$var3"/>
+ </three>
</result>
</xsl:template>
diff --git a/tests/xsl_attribute_as/test3.xsl b/tests/xsl_attribute_as/test11.xsl
similarity index 56%
copy from tests/xsl_attribute_as/test3.xsl
copy to tests/xsl_attribute_as/test11.xsl
index 99797a60..5de6bb05 100644
--- a/tests/xsl_attribute_as/test3.xsl
+++ b/tests/xsl_attribute_as/test11.xsl
@@ -3,28 +3,47 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
-
+
<!-- Author: mukulg@apache.org -->
<!-- An XSLT stylesheet test case, to test the sequence type
declaration attribute "as" on an xsl:variable instruction.
- This stylesheet produces an XSLT transformation error,
- because the XPath 3.1 function conversion rules don't allow
- xs:string values to be converted to numeric types (like
- xs:integer as mentioned within this example).
- -->
+ Within this stylesheet example, the named template 'Template1''s
+ output is wrapped within an xsl:variable. The named template's
+ output needs to conform to the sequence type specified as
+ value of xsl:variable's "as" attribute.
+ -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="var1" select="'4'" as="xs:integer"/>
-
+ <xsl:variable name="varElemName" select="'a1'"/>
+ <xsl:variable name="iterFrom" select="xs:integer(1)"/>
+ <xsl:variable name="iterTo" select="xs:integer(5)"/>
+
<xsl:template match="/">
<result>
- <xsl:value-of select="$var1"/>
+ <xsl:variable name="var1" as="element(a1)*">
+ <xsl:call-template name="Template1">
+ <xsl:with-param name="elemName" select="$varElemName"/>
+ <xsl:with-param name="from" select="$iterFrom"/>
+ <xsl:with-param name="to" select="$iterTo"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:copy-of select="$var1"/>
</result>
</xsl:template>
+ <xsl:template name="Template1">
+ <xsl:param name="elemName"/>
+ <xsl:param name="from"/>
+ <xsl:param name="to"/>
+
+ <xsl:for-each select="$from to $to">
+ <xsl:element name="{$elemName}"/>
+ </xsl:for-each>
+ </xsl:template>
+
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
diff --git a/tests/xsl_attribute_as/test3.xsl b/tests/xsl_attribute_as/test12.xsl
similarity index 71%
copy from tests/xsl_attribute_as/test3.xsl
copy to tests/xsl_attribute_as/test12.xsl
index 99797a60..6044fab1 100644
--- a/tests/xsl_attribute_as/test3.xsl
+++ b/tests/xsl_attribute_as/test12.xsl
@@ -3,25 +3,31 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
-
+
<!-- Author: mukulg@apache.org -->
<!-- An XSLT stylesheet test case, to test the sequence type
declaration attribute "as" on an xsl:variable instruction.
- This stylesheet produces an XSLT transformation error,
- because the XPath 3.1 function conversion rules don't allow
- xs:string values to be converted to numeric types (like
- xs:integer as mentioned within this example).
- -->
+ Within this stylesheet example, a numeric string is specified
+ as child content of an xsl:variable instruction, which is cast
+ to the type xs:integer when the variable is evaluated.
+
+ We emit the value of variable once by xsl:copy-of instruction,
+ and then by xsl:value-of instruction.
+ -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="var1" select="'4'" as="xs:integer"/>
-
<xsl:template match="/">
<result>
- <xsl:value-of select="$var1"/>
+ <xsl:variable name="var1" as="xs:integer">123</xsl:variable>
+ <one>
+ <xsl:copy-of select="$var1"/>
+ </one>
+ <two>
+ <xsl:value-of select="$var1"/>
+ </two>
</result>
</xsl:template>
diff --git a/tests/xsl_attribute_as/test3.xsl b/tests/xsl_attribute_as/test13.xsl
similarity index 65%
copy from tests/xsl_attribute_as/test3.xsl
copy to tests/xsl_attribute_as/test13.xsl
index 99797a60..b6ab4fe3 100644
--- a/tests/xsl_attribute_as/test3.xsl
+++ b/tests/xsl_attribute_as/test13.xsl
@@ -1,27 +1,34 @@
<?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 -->
+
+ <!-- Author: mukulg@apache.org -->
<!-- An XSLT stylesheet test case, to test the sequence type
declaration attribute "as" on an xsl:variable instruction.
-
- This stylesheet produces an XSLT transformation error,
- because the XPath 3.1 function conversion rules don't allow
- xs:string values to be converted to numeric types (like
- xs:integer as mentioned within this example).
- -->
+ -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="var1" select="'4'" as="xs:integer"/>
-
<xsl:template match="/">
<result>
- <xsl:value-of select="$var1"/>
+ <!-- The following variable when evaluated, produces
+ three XDM sibling top-level nodes (two element nodes,
+ and one text node. Each of these nodes match the
+ sequence type expression node()).
+ -->
+ <xsl:variable name="var1" as="node()*">
+ <elem>
+ <a>123</a>
+ </elem>
+ hi there
+ <elem>
+ <b>456</b>
+ </elem>
+ </xsl:variable>
+ <one nodeCount="{count($var1)}">
+ <xsl:copy-of select="$var1"/>
+ </one>
</result>
</xsl:template>
diff --git a/tests/xsl_attribute_as/test3.xsl b/tests/xsl_attribute_as/test3.xsl
index 99797a60..7ae6e35a 100644
--- a/tests/xsl_attribute_as/test3.xsl
+++ b/tests/xsl_attribute_as/test3.xsl
@@ -8,11 +8,6 @@
<!-- An XSLT stylesheet test case, to test the sequence type
declaration attribute "as" on an xsl:variable instruction.
-
- This stylesheet produces an XSLT transformation error,
- because the XPath 3.1 function conversion rules don't allow
- xs:string values to be converted to numeric types (like
- xs:integer as mentioned within this example).
-->
<xsl:output method="xml" indent="yes"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org