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/12 17:08:24 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing bug fix to xalan-j's xsl 3 xsl:try and xsl:catch instruction implementations, along with few new working related test cases
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 582b8dab7 committing bug fix to xalan-j's xsl 3 xsl:try and xsl:catch instruction implementations, along with few new working related test cases
582b8dab7 is described below
commit 582b8dab707c11de2757b933c4496f2d1066444f
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Apr 12 22:38:09 2025 +0530
committing bug fix to xalan-j's xsl 3 xsl:try and xsl:catch instruction implementations, along with few new working related test cases
---
README | 6 +-
.../java/org/apache/xalan/templates/ElemTry.java | 22 ++++++--
.../apache/xalan/tests/xslt3/XslTryCatchTests.java | 24 ++++++++
src/test/resources/xsl_try_catch/gold/test10.out | 15 +++++
src/test/resources/xsl_try_catch/gold/test11.out | 7 +++
src/test/resources/xsl_try_catch/info_1.xsd | 35 ++++++++++++
src/test/resources/xsl_try_catch/test10.xsl | 66 ++++++++++++++++++++++
src/test/resources/xsl_try_catch/test11.xsl | 65 +++++++++++++++++++++
src/test/resources/xsl_try_catch/test2.xml | 4 ++
9 files changed, 235 insertions(+), 9 deletions(-)
diff --git a/README b/README
index 17f844719..ade23c370 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: 1000, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.966 s - in org.apache.xalan.tests.main.AllXsl3Tests
+[INFO] Tests run: 1002, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.785 s - in org.apache.xalan.tests.main.AllXsl3Tests
[INFO]
[INFO] Results:
[INFO]
-[INFO] Tests run: 1000, Failures: 0, Errors: 0, Skipped: 0
+[INFO] Tests run: 1002, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
-[INFO] Total time: 01:15 min
+[INFO] Total time: 01:31 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/main/java/org/apache/xalan/templates/ElemTry.java b/src/main/java/org/apache/xalan/templates/ElemTry.java
index 740f0a31c..13b711054 100644
--- a/src/main/java/org/apache/xalan/templates/ElemTry.java
+++ b/src/main/java/org/apache/xalan/templates/ElemTry.java
@@ -346,15 +346,25 @@ public class ElemTry extends ElemTemplateElement implements ExpressionOwner {
ElemCatch elemCatch = getXslCatchElemToHandleException(transformer, xctxt, errCodeStr, this);
if (elemCatch != null) {
- colonIdx = errMesg.indexOf(':');
- String errMesg2 = errMesg.substring(colonIdx + 1);
- colonIdx = errMesg2.indexOf(':');
- errMesg2 = (errMesg2.substring(colonIdx + 1)).trim();
-
+ String errMesg2 = null;
+ if (errCodeStr.length() > 8) {
+ colonIdx = errMesg.indexOf(':');
+ errCodeStr = (errMesg.substring(0, colonIdx)).trim();
+ errMesg2 = (errMesg.substring(colonIdx + 1)).trim();
+ }
+ else {
+ colonIdx = errMesg.indexOf(':');
+ errMesg2 = errMesg.substring(colonIdx + 1);
+ colonIdx = errMesg2.indexOf(':');
+ errMesg2 = (errMesg2.substring(colonIdx + 1)).trim();
+ }
+
+ errMesg = errMesg2;
+
// Set variables err:code, err:description, err:line-number,
// err:column-number within XPath evaluation context.
xpathVarMap.put(errCodeKey, new XSString(errCodeStr));
- xpathVarMap.put(errDescKey, new XSString(errMesg2));
+ xpathVarMap.put(errDescKey, new XSString(errMesg));
SourceLocator srcLocator2 = ex.getLocator();
int errLineNum = srcLocator2.getLineNumber();
int errColNum = srcLocator2.getColumnNumber();
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 4dccffdf4..7a297aae0 100644
--- a/src/test/java/org/apache/xalan/tests/xslt3/XslTryCatchTests.java
+++ b/src/test/java/org/apache/xalan/tests/xslt3/XslTryCatchTests.java
@@ -138,5 +138,29 @@ public class XslTryCatchTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslTryCatchTest10() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test10.out";
+
+ setXmlValidationProperty(true);
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslTryCatchTest11() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test11.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test11.out";
+
+ setXmlValidationProperty(true);
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/src/test/resources/xsl_try_catch/gold/test10.out b/src/test/resources/xsl_try_catch/gold/test10.out
new file mode 100644
index 000000000..e3437e006
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/gold/test10.out
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <warning>
+ <errCode>XTTE1540</errCode>
+ <reason>An error occured while evaluating an XSL stylesheet xsl:copy-of instruction. cvc-complex-type.2.4.h: Invalid content was found starting with element 'd'. 'a' is expected to occur a minimum of '3' times in the current sequence. '2' more instances are required to satisfy this constraint.</reason>
+ <errLocation>Line number : 33, Column number : 64</errLocation>
+ <documentValidated>
+ <aList id="10">
+ <a val="5">hello</a>
+ <d/>
+ <a val="5">hello</a>
+ <a val="5">hello</a>
+ </aList>
+ </documentValidated>
+ </warning>
+</result>
diff --git a/src/test/resources/xsl_try_catch/gold/test11.out b/src/test/resources/xsl_try_catch/gold/test11.out
new file mode 100644
index 000000000..5bef7e8f6
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/gold/test11.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <aList id="10">
+ <a val="5">hello</a>
+ <a val="5">hello</a>
+ <a val="5">hello</a>
+ </aList>
+</result>
diff --git a/src/test/resources/xsl_try_catch/info_1.xsd b/src/test/resources/xsl_try_catch/info_1.xsd
new file mode 100644
index 000000000..e738c7c69
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/info_1.xsd
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:element name="info">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="a" type="aType"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name="aType">
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="val">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer">
+ <xs:maxInclusive value="10"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+
+ <xs:element name="aList">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="a" type="aType" minOccurs="3" maxOccurs="3"/>
+ </xs:sequence>
+ <xs:attribute name="id" type="xs:integer"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
diff --git a/src/test/resources/xsl_try_catch/test10.xsl b/src/test/resources/xsl_try_catch/test10.xsl
new file mode 100644
index 000000000..3c898d976
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/test10.xsl
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:err="http://www.w3.org/2005/xqt-errors"
+ exclude-result-prefixes="err"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test2.xml -->
+
+ <!-- An XSL stylesheet test case, to test xsl:try and xsl:catch
+ instructions.
+
+ An algorithm for this xsl:try and xsl:catch use case, is borrowed
+ from XSLT 3.0 spec with minor modifications.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:import-schema schema-location="info_1.xsd"/>
+
+ <xsl:template match="/info">
+ <result>
+ <xsl:variable name="var1">
+ <aList id="10">
+ <xsl:copy-of select="a"/>
+ <d/>
+ <xsl:copy-of select="a"/>
+ <xsl:copy-of select="a"/>
+ </aList>
+ </xsl:variable>
+ <xsl:try>
+ <xsl:copy-of select="$var1/aList" validation="strict"/>
+ <xsl:catch>
+ <warning>
+ <errCode><xsl:value-of select="$err:code"/></errCode>
+ <reason><xsl:value-of select="$err:description"/></reason>
+ <errLocation><xsl:value-of select="'Line number : ' || $err:line-number || ', Column number : ' || $err:column-number"/></errLocation>
+ <documentValidated>
+ <xsl:copy-of select="$var1/aList"/>
+ </documentValidated>
+ </warning>
+ </xsl:catch>
+ </xsl:try>
+ </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>
diff --git a/src/test/resources/xsl_try_catch/test11.xsl b/src/test/resources/xsl_try_catch/test11.xsl
new file mode 100644
index 000000000..5a0aca28d
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/test11.xsl
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:err="http://www.w3.org/2005/xqt-errors"
+ exclude-result-prefixes="err"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test2.xml -->
+
+ <!-- An XSL stylesheet test case, to test xsl:try and xsl:catch
+ instructions.
+
+ An algorithm for this xsl:try and xsl:catch use case, is borrowed
+ from XSLT 3.0 spec with minor modifications.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:import-schema schema-location="info_1.xsd"/>
+
+ <xsl:template match="/info">
+ <result>
+ <xsl:variable name="var1">
+ <aList id="10">
+ <xsl:copy-of select="a"/>
+ <xsl:copy-of select="a"/>
+ <xsl:copy-of select="a"/>
+ </aList>
+ </xsl:variable>
+ <xsl:try>
+ <xsl:copy-of select="$var1/aList" validation="strict"/>
+ <xsl:catch>
+ <warning>
+ <errCode><xsl:value-of select="$err:code"/></errCode>
+ <reason><xsl:value-of select="$err:description"/></reason>
+ <errLocation><xsl:value-of select="'Line number : ' || $err:line-number || ', Column number : ' || $err:column-number"/></errLocation>
+ <documentValidated>
+ <xsl:copy-of select="$var1/aList"/>
+ </documentValidated>
+ </warning>
+ </xsl:catch>
+ </xsl:try>
+ </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>
diff --git a/src/test/resources/xsl_try_catch/test2.xml b/src/test/resources/xsl_try_catch/test2.xml
new file mode 100644
index 000000000..cc7839c25
--- /dev/null
+++ b/src/test/resources/xsl_try_catch/test2.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<info>
+ <a val="5">hello</a>
+</info>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org