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/03/03 07:25:04 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing few new working xsl 3 test cases related to xpath fn:collection function reading a set of csv document local files
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 96a5ce954 committing few new working xsl 3 test cases related to xpath fn:collection function reading a set of csv document local files
96a5ce954 is described below
commit 96a5ce954cf31471fb8a7e3c4d98e0bb8b34d548
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Mon Mar 3 12:54:51 2025 +0530
committing few new working xsl 3 test cases related to xpath fn:collection function reading a set of csv document local files
---
.../xalan/tests/xpath3/FnCollectionTests.java | 24 ++++++++
src/test/resources/fn_collection/file1.csv | 3 +
src/test/resources/fn_collection/file2.csv | 4 ++
src/test/resources/fn_collection/gold/test5.out | 32 ++++++++++
src/test/resources/fn_collection/gold/test6.out | 36 ++++++++++++
src/test/resources/fn_collection/test5.xsl | 63 ++++++++++++++++++++
src/test/resources/fn_collection/test6.xsl | 68 ++++++++++++++++++++++
7 files changed, 230 insertions(+)
diff --git a/src/test/java/org/apache/xalan/tests/xpath3/FnCollectionTests.java b/src/test/java/org/apache/xalan/tests/xpath3/FnCollectionTests.java
index 92dc40994..0d971ef78 100644
--- a/src/test/java/org/apache/xalan/tests/xpath3/FnCollectionTests.java
+++ b/src/test/java/org/apache/xalan/tests/xpath3/FnCollectionTests.java
@@ -94,5 +94,29 @@ public class FnCollectionTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutputWithXslParamBaseUri(xmlFilePath, xslFilePath, goldFilePath, null, localBaseUriPrefix);
}
+
+ @Test
+ public void xslFnCollectionTest5() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test5.out";
+
+ String localBaseUriPrefix = XSLConstants.LOCAL_BASE_URI_PREFIX_OF_TESTS1;
+
+ runXslTransformAndAssertOutputWithXslParamBaseUri(xmlFilePath, xslFilePath, goldFilePath, null, localBaseUriPrefix);
+ }
+
+ @Test
+ public void xslFnCollectionTest6() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test6.out";
+
+ String localBaseUriPrefix = XSLConstants.LOCAL_BASE_URI_PREFIX_OF_TESTS1;
+
+ runXslTransformAndAssertOutputWithXslParamBaseUri(xmlFilePath, xslFilePath, goldFilePath, null, localBaseUriPrefix);
+ }
}
diff --git a/src/test/resources/fn_collection/file1.csv b/src/test/resources/fn_collection/file1.csv
new file mode 100644
index 000000000..492215fe9
--- /dev/null
+++ b/src/test/resources/fn_collection/file1.csv
@@ -0,0 +1,3 @@
+id,employee id,emplolyee name,department id
+1,100,Mukul,5
+2,101,Joseph,7
\ No newline at end of file
diff --git a/src/test/resources/fn_collection/file2.csv b/src/test/resources/fn_collection/file2.csv
new file mode 100644
index 000000000..9468b6e32
--- /dev/null
+++ b/src/test/resources/fn_collection/file2.csv
@@ -0,0 +1,4 @@
+id,employee id,emplolyee name,department id
+3,102,Gary,7
+4,103,Michael,7
+5,104,Neil,5
\ No newline at end of file
diff --git a/src/test/resources/fn_collection/gold/test5.out b/src/test/resources/fn_collection/gold/test5.out
new file mode 100644
index 000000000..2233bcc9c
--- /dev/null
+++ b/src/test/resources/fn_collection/gold/test5.out
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?><rows>
+ <row>
+ <id>1</id>
+ <employeeId>100</employeeId>
+ <employeeName>Mukul</employeeName>
+ <departmentId>5</departmentId>
+ </row>
+ <row>
+ <id>2</id>
+ <employeeId>101</employeeId>
+ <employeeName>Joseph</employeeName>
+ <departmentId>7</departmentId>
+ </row>
+ <row>
+ <id>3</id>
+ <employeeId>102</employeeId>
+ <employeeName>Gary</employeeName>
+ <departmentId>7</departmentId>
+ </row>
+ <row>
+ <id>4</id>
+ <employeeId>103</employeeId>
+ <employeeName>Michael</employeeName>
+ <departmentId>7</departmentId>
+ </row>
+ <row>
+ <id>5</id>
+ <employeeId>104</employeeId>
+ <employeeName>Neil</employeeName>
+ <departmentId>5</departmentId>
+ </row>
+</rows>
diff --git a/src/test/resources/fn_collection/gold/test6.out b/src/test/resources/fn_collection/gold/test6.out
new file mode 100644
index 000000000..1bc526047
--- /dev/null
+++ b/src/test/resources/fn_collection/gold/test6.out
@@ -0,0 +1,36 @@
+{
+ "csv2": [
+ {
+ "employeeName": "Gary",
+ "departmentId": "7",
+ "employeeId": "102",
+ "id": "3"
+ },
+ {
+ "employeeName": "Michael",
+ "departmentId": "7",
+ "employeeId": "103",
+ "id": "4"
+ },
+ {
+ "employeeName": "Neil",
+ "departmentId": "5",
+ "employeeId": "104",
+ "id": "5"
+ }
+ ],
+ "csv1": [
+ {
+ "employeeName": "Mukul",
+ "departmentId": "5",
+ "employeeId": "100",
+ "id": "1"
+ },
+ {
+ "employeeName": "Joseph",
+ "departmentId": "7",
+ "employeeId": "101",
+ "id": "2"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/fn_collection/test5.xsl b/src/test/resources/fn_collection/test5.xsl
new file mode 100644
index 000000000..86de9f83b
--- /dev/null
+++ b/src/test/resources/fn_collection/test5.xsl
@@ -0,0 +1,63 @@
+<?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 XSL 3 stylesheet test case, to test XPath 3.1 collection function
+ reading a set of CSV document local files. This stylesheet combines
+ information from various CSV document files into an aggregate XML
+ result document. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:param name="localBaseUriPrefix" as="xs:string"/>
+
+ <xsl:template match="/">
+ <xsl:variable name="fnCollectionResult1" select="collection($localBaseUriPrefix || 'fn_collection/.*[.]csv')" as="xs:string*"/>
+ <xsl:variable name="noOfCsvDocuments" select="count($fnCollectionResult1)"/>
+ <rows>
+ <xsl:for-each select="1 to $noOfCsvDocuments">
+ <xsl:variable name="csvFileStrValue" select="$fnCollectionResult1[xs:integer(.)]"/>
+ <xsl:variable name="fileStrLines" select="tokenize($csvFileStrValue, '\r\n|\r|\n')" as="xs:string*"/>
+ <xsl:variable name="noOfLinesInFile" select="count($fileStrLines)"/>
+ <xsl:for-each select="1 to $noOfLinesInFile">
+ <xsl:variable name="lineNo" select="xs:integer(.)" as="xs:integer"/>
+ <xsl:variable name="fileLineStr" select="$fileStrLines[$lineNo]" as="xs:string"/>
+ <xsl:variable name="tokenSeq" select="tokenize($fileLineStr, ',')" as="xs:string*"/>
+ <!-- The first line of every csv file is csv's header value, and
+ we do not emit that to XSL transform's result output. -->
+ <xsl:if test="$lineNo gt 1">
+ <row>
+ <id><xsl:value-of select="$tokenSeq[1]"/></id>
+ <employeeId><xsl:value-of select="$tokenSeq[2]"/></employeeId>
+ <employeeName><xsl:value-of select="$tokenSeq[3]"/></employeeName>
+ <departmentId><xsl:value-of select="$tokenSeq[4]"/></departmentId>
+ </row>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:for-each>
+ </rows>
+ </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/fn_collection/test6.xsl b/src/test/resources/fn_collection/test6.xsl
new file mode 100644
index 000000000..2929eb769
--- /dev/null
+++ b/src/test/resources/fn_collection/test6.xsl
@@ -0,0 +1,68 @@
+<?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 XSL 3 stylesheet test case, to test XPath 3.1 collection function
+ reading a set of CSV document local files. This stylesheet combines
+ information from various CSV document files into an aggregate JSON
+ result document using XPath function fn:xml-to-json. -->
+
+ <xsl:output method="text"/>
+
+ <xsl:param name="localBaseUriPrefix" as="xs:string"/>
+
+ <xsl:template match="/">
+ <xsl:variable name="fnCollectionResult1" select="collection($localBaseUriPrefix || 'fn_collection/.*[.]csv')" as="xs:string*"/>
+ <xsl:variable name="noOfCsvDocuments" select="count($fnCollectionResult1)"/>
+ <xsl:variable name="nodeSet1">
+ <map xmlns="http://www.w3.org/2005/xpath-functions">
+ <xsl:for-each select="1 to $noOfCsvDocuments">
+ <xsl:variable name="csvFileStrValue" select="$fnCollectionResult1[xs:integer(.)]"/>
+ <xsl:variable name="fileStrLines" select="tokenize($csvFileStrValue, '\r\n|\r|\n')" as="xs:string*"/>
+ <xsl:variable name="noOfLinesInFile" select="count($fileStrLines)"/>
+ <array key="csv{xs:integer(.)}">
+ <xsl:for-each select="1 to $noOfLinesInFile">
+ <xsl:variable name="lineNo" select="xs:integer(.)" as="xs:integer"/>
+ <xsl:variable name="fileLineStr" select="$fileStrLines[$lineNo]" as="xs:string"/>
+ <xsl:variable name="tokenSeq" select="tokenize($fileLineStr, ',')" as="xs:string*"/>
+ <!-- The first line of every csv file is csv's header value, and
+ we do not emit that to XSL transform's result output. -->
+ <xsl:if test="$lineNo gt 1">
+ <map>
+ <string key="id"><xsl:value-of select="$tokenSeq[1]"/></string>
+ <string key="employeeId"><xsl:value-of select="$tokenSeq[2]"/></string>
+ <string key="employeeName"><xsl:value-of select="$tokenSeq[3]"/></string>
+ <string key="departmentId"><xsl:value-of select="$tokenSeq[4]"/></string>
+ </map>
+ </xsl:if>
+ </xsl:for-each>
+ </array>
+ </xsl:for-each>
+ </map>
+ </xsl:variable>
+ <xsl:value-of select="xml-to-json($nodeSet1, map {'indent' : true()})"/>
+ </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