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 2025/04/11 16:53:40 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: adding a new test case for xsl:try instruction
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
new 0ec081642 adding a new test case for xsl:try instruction
0ec081642 is described below
commit 0ec081642dd60bc9cbd4fa49dfaf848f414582c3
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Apr 11 22:23:22 2025 +0530
adding a new test case for xsl:try instruction
---
README | 6 +-
.../apache/xalan/tests/xslt3/XslTryCatchTests.java | 10 +++
src/test/resources/xsl_try_catch/gold/test8.out | 29 +++++++++
src/test/resources/xsl_try_catch/info1.csv | 15 +++++
src/test/resources/xsl_try_catch/test8.xsl | 71 ++++++++++++++++++++++
5 files changed, 128 insertions(+), 3 deletions(-)
diff --git a/README b/README
index 8e7036896..8b499e9cd 100644
--- a/README
+++ b/README
@@ -59,16 +59,16 @@ This produces Maven build output with trailing information like following:
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.xalan.tests.main.AllXsl3Tests
-[INFO] Tests run: 998, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 28.173 s - in org.apache.xalan.tests.main.AllXsl3Tests
+[INFO] Tests run: 999, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 29.201 s - in org.apache.xalan.tests.main.AllXsl3Tests
[INFO]
[INFO] Results:
[INFO]
-[INFO] Tests run: 998, Failures: 0, Errors: 0, Skipped: 0
+[INFO] Tests run: 999, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
-[INFO] Total time: 58.560 s
+[INFO] Total time: 01:28 min
To run Xalan-J's XSL 3 processor for invoking an XSL stylesheet transformation, the jar file xalan-java-3.0.1.jar and other
jar files available within 'libs' folder need to be made available on Java run-time's classpath.
diff --git a/src/test/java/org/apache/xalan/tests/xslt3/XslTryCatchTests.java b/src/test/java/org/apache/xalan/tests/xslt3/XslTryCatchTests.java
index 90ddc1a2d..776599997 100644
--- a/src/test/java/org/apache/xalan/tests/xslt3/XslTryCatchTests.java
+++ b/src/test/java/org/apache/xalan/tests/xslt3/XslTryCatchTests.java
@@ -118,5 +118,15 @@ public class XslTryCatchTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslTryCatchTest8() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test8.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test8.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test8.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/src/test/resources/xsl_try_catch/gold/test8.out b/src/test/resources/xsl_try_catch/gold/test8.out
new file mode 100644
index 000000000..e3da37982
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/gold/test8.out
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <sum num2="6" num1="5" id="1">11</sum>
+ <sum num2="6.7" num1="5.5" id="2">12.2</sum>
+ <sum num2="12" num1="10" id="3">22</sum>
+ <sum num2="6" num1="5" id="4">11</sum>
+ <sum num2="6" num1="5" id="5">11</sum>
+ <sum num2="3" num1="2" id="6">5</sum>
+ <sum num2="66" num1="51" id="7">117</sum>
+ <error id="8">
+ <additionOperands>P, 32</additionOperands>
+ <errCode>XPTY0004</errCode>
+ <errDesc>One or both of the operands of operator + are not numeric.</errDesc>
+ </error>
+ <sum num2="2" num1="1" id="9">3</sum>
+ <sum num2="6" num1="5" id="10">11</sum>
+ <error id="11">
+ <additionOperands>5, Q</additionOperands>
+ <errCode>XPTY0004</errCode>
+ <errDesc>One or both of the operands of operator + are not numeric.</errDesc>
+ </error>
+ <sum num2="6" num1="5" id="12">11</sum>
+ <error id="13">
+ <additionOperands>M, N</additionOperands>
+ <errCode>XPTY0004</errCode>
+ <errDesc>One or both of the operands of operator + are not numeric.</errDesc>
+ </error>
+ <sum num2="4.3" num1="2" id="14">6.3</sum>
+ <sum num2="12.5" num1="5" id="15">17.5</sum>
+</result>
diff --git a/src/test/resources/xsl_try_catch/info1.csv b/src/test/resources/xsl_try_catch/info1.csv
new file mode 100644
index 000000000..e3fedfae9
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/info1.csv
@@ -0,0 +1,15 @@
+1,a1,b1,c1,d1,5,6,e1,f1,g1,h1
+2,a2,b2,c2,d2,5.5,6.7,e2,f2,g2,h2
+3,a3,b3,c3,d3,10,12,e3,f3,g3,h3
+4,a4,b4,c4,d4,5,6,e4,f4,g4,h4
+5,a5,b5,c5,d5,5,6,e5,f5,g5,h5
+6,a6,b6,c6,d6,2,3,e6,f6,g6,h6
+7,a7,b7,c7,d7,51,66,e7,f7,g7,h7
+8,a8,b8,c8,d8,P,32,e8,f8,g8,h8
+9,a9,b9,c9,d9,1,2,e9,f9,g9,h9
+10,a10,b10,c10,d10,5,6,e10,f10,g10,h10
+11,a11,b11,c11,d11,5,Q,e11,f11,g11,h11
+12,a12,b12,c12,d12,5,6,e12,f12,g12,h12
+13,a13,b13,c13,d13,M,N,e13,f13,g13,h13
+14,a14,b14,c14,d14,2,4.3,e14,f14,g14,h14
+15,a15,b15,c15,d15,5,12.5,e15,f15,g15,h15
\ No newline at end of file
diff --git a/src/test/resources/xsl_try_catch/test8.xsl b/src/test/resources/xsl_try_catch/test8.xsl
new file mode 100644
index 000000000..a8bb024b6
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/test8.xsl
@@ -0,0 +1,71 @@
+<?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"
+ xmlns:err="http://www.w3.org/2005/xqt-errors"
+ exclude-result-prefixes="xs err"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSL stylesheet test case, to test xsl:try and xsl:catch
+ instructions.
+
+ This stylesheet reads a CSV document file using XPath function
+ fn:unparsed-text-lines. A numeric addition is performed within
+ an xsl:try instruction. If an addition fails due to incorrectly typed
+ operands, then xsl:catch instruction produces a recovery result
+ (an XML element "error"), otherwise addition details get available
+ with an XML element "sum". When a particular addition operation fails, the
+ subsequent xsl:for-each iterations are continued to be processed.
+
+ In the absence of xsl:try instruction processing, an XSL stylesheet
+ processing gets aborted after the first addition operation failure.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:variable name="fileLines" select="unparsed-text-lines('info1.csv')" as="xs:string*"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:for-each select="$fileLines">
+ <xsl:variable name="line" select="." as="xs:string"/>
+ <xsl:variable name="lineTokens" select="tokenize($line, ',')" as="xs:string*"/>
+ <xsl:variable name="a" select="$lineTokens[6]"/>
+ <xsl:variable name="b" select="$lineTokens[7]"/>
+ <xsl:variable name="xslTryResult1">
+ <xsl:try rollback-output="no">
+ <sum id="{$lineTokens[1]}" num1="{$a}" num2="{$b}"><xsl:value-of select="$a + $b"/></sum>
+ <xsl:catch errors="*">
+ <error id="{$lineTokens[1]}">
+ <additionOperands><xsl:value-of select="$a || ', ' || $b"/></additionOperands>
+ <errCode><xsl:value-of select="$err:code"/></errCode>
+ <errDesc><xsl:value-of select="$err:description"/></errDesc>
+ </error>
+ </xsl:catch>
+ </xsl:try>
+ </xsl:variable>
+ <xsl:copy-of select="if (not($xslTryResult1/error)) then $xslTryResult1/sum else $xslTryResult1/error"/>
+ </xsl:for-each>
+ </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>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org