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 2026/03/27 12:15:33 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing few xslt 3.0 stylesheet examples
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 e30a6d14f committing few xslt 3.0 stylesheet examples
e30a6d14f is described below
commit e30a6d14f206c2258a059c45283f9c260f5a07e9
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Mar 27 17:45:06 2026 +0530
committing few xslt 3.0 stylesheet examples
---
.../resources/xsl3_tests_new/collection_001.xsl | 58 +++++++++++
.../resources/xsl3_tests_new/collection_002.xsl | 33 ++++++
.../xsl3_tests_new/input/differentfile4.xml | 5 +
.../xsl3_tests_new/input/differentfile5.xml | 5 +
.../xsl3_tests_new/input/differentfile6.xml | 5 +
src/test/resources/xsl3_tests_new/input/file1.json | 7 ++
src/test/resources/xsl3_tests_new/input/file1.txt | 2 +
src/test/resources/xsl3_tests_new/input/file1.xml | 5 +
src/test/resources/xsl3_tests_new/input/file2.json | 7 ++
src/test/resources/xsl3_tests_new/input/file2.xml | 5 +
src/test/resources/xsl3_tests_new/input/file3.xml | 5 +
src/test/resources/xsl3_tests_new/input/file4.json | 11 ++
src/test/resources/xsl3_tests_new/input/file4.xml | 9 ++
src/test/resources/xsl3_tests_new/json_to_xml1.xsl | 46 +++++++++
.../xsl3_tests_new/xalan_j_xsl3-test-set.xml | 115 +++++++++++++++++++++
src/test/resources/xsl3_tests_new/xpath_bool_1.xsl | 31 ++++++
src/test/resources/xsl3_tests_new/xpath_bool_2.xsl | 35 +++++++
src/test/resources/xsl3_tests_new/xpath_bool_3.xsl | 35 +++++++
18 files changed, 419 insertions(+)
diff --git a/src/test/resources/xsl3_tests_new/collection_001.xsl b/src/test/resources/xsl3_tests_new/collection_001.xsl
new file mode 100644
index 000000000..5126bfef3
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/collection_001.xsl
@@ -0,0 +1,58 @@
+<?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:map="http://www.w3.org/2005/xpath-functions/map"
+ xmlns:array="http://www.w3.org/2005/xpath-functions/array"
+ exclude-result-prefixes="xs map array"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:param name="base-dir" select="'file:/d:/eclipseWorkspaces/xalanj/xalan-j_xslt3.0_mvn/src/test/resources/xsl3_tests/input/'" as="xs:string"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="collectionResult1" select="collection($base-dir || '.*[\\.](xml)')"/>
+ <xsl:variable name="collectionResult2" select="collection($base-dir || '.*[\\.](json)')"/>
+ <xsl:variable name="collectionResult3" select="collection($base-dir || '.*[\\.](txt)')"/>
+
+ <xsl:variable name="seq1" select="insert-before($collectionResult3, 0, $collectionResult1)"/>
+ <xsl:variable name="seq2" select="insert-before($collectionResult2, 0, $seq1)"/>
+
+ <xsl:for-each select="$seq2">
+ <xsl:variable name="collectionResult1" select="."/>
+ <xsl:choose>
+ <xsl:when test="$collectionResult1 instance of map(*)">
+ <!-- Process a JSON document which begins with json map -->
+ <xsl:variable name="map1" select="$collectionResult1" as="map(*)"/>
+ <map>
+ <xsl:for-each select="map:keys($map1)">
+ <entry key="{.}"><xsl:value-of select="map:get($map1, .)"/></entry>
+ </xsl:for-each>
+ </map>
+ </xsl:when>
+ <xsl:when test="$collectionResult1 instance of array(*)">
+ <!-- Process a JSON document which begins with json array -->
+ <array>
+ <xsl:for-each select="1 to array:size($collectionResult1)">
+ <item><xsl:value-of select="array:get($collectionResult1, xs:integer(.))"/></item>
+ </xsl:for-each>
+ </array>
+ </xsl:when>
+ <xsl:when test="$collectionResult1 instance of xs:string">
+ <!-- Process a file text document. -->
+ <txtContents><xsl:value-of select="$collectionResult1"/></txtContents>
+ </xsl:when>
+ <xsl:otherwise>
+ <xmlContents>
+ <xsl:copy-of select="."/>
+ </xmlContents>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </result>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/src/test/resources/xsl3_tests_new/collection_002.xsl b/src/test/resources/xsl3_tests_new/collection_002.xsl
new file mode 100644
index 000000000..dac823194
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/collection_002.xsl
@@ -0,0 +1,33 @@
+<?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 -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:param name="base-dir" select="'file:/d:/eclipseWorkspaces/xalanj/xalan-j_xslt3.0_mvn/src/test/resources/xsl3_tests/input/'" as="xs:string"/>
+
+ <xsl:variable name="search_word_str" select="'hello'" as="xs:string"/>
+
+ <xsl:template match="/">
+ <groups>
+ <xsl:variable name="collectionResult1" select="collection($base-dir || 'differentfile.*[\\.]xml')"/>
+ <xsl:variable name="nodeSet1">
+ <xsl:for-each select="$collectionResult1">
+ <xsl:for-each select="./*/*">
+ <xsl:copy-of select="."/>
+ </xsl:for-each>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:for-each-group select="$nodeSet1/*" group-by="contains(string(.), $search_word_str)">
+ <group key="{if (current-grouping-key() eq true()) then ('contains_word_' || $search_word_str) else ('doesnt_contain_word_' || $search_word_str)}">
+ <xsl:copy-of select="current-group()"/>
+ </group>
+ </xsl:for-each-group>
+ </groups>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/input/differentfile4.xml b/src/test/resources/xsl3_tests_new/input/differentfile4.xml
new file mode 100644
index 000000000..e855e98fd
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/differentfile4.xml
@@ -0,0 +1,5 @@
+<info id="4">
+ <a/>
+ <b>hello</b>
+ <c/>
+</info>
diff --git a/src/test/resources/xsl3_tests_new/input/differentfile5.xml b/src/test/resources/xsl3_tests_new/input/differentfile5.xml
new file mode 100644
index 000000000..0072114e1
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/differentfile5.xml
@@ -0,0 +1,5 @@
+<info id="5">
+ <p/>
+ <q/>
+ <r>hello</r>
+</info>
diff --git a/src/test/resources/xsl3_tests_new/input/differentfile6.xml b/src/test/resources/xsl3_tests_new/input/differentfile6.xml
new file mode 100644
index 000000000..32f000533
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/differentfile6.xml
@@ -0,0 +1,5 @@
+<info id="6">
+ <m>hello</m>
+ <n/>
+ <o/>
+</info>
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/input/file1.json b/src/test/resources/xsl3_tests_new/input/file1.json
new file mode 100644
index 000000000..c04a4ddd9
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file1.json
@@ -0,0 +1,7 @@
+{
+ "a" : 1,
+ "b" : 2,
+ "c" : 3,
+ "d" : 4,
+ "e" : 5
+}
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/input/file1.txt b/src/test/resources/xsl3_tests_new/input/file1.txt
new file mode 100644
index 000000000..67a0ea017
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file1.txt
@@ -0,0 +1,2 @@
+hello world. this is used
+to test xpath fn:collection function.
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/input/file1.xml b/src/test/resources/xsl3_tests_new/input/file1.xml
new file mode 100644
index 000000000..293154b27
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file1.xml
@@ -0,0 +1,5 @@
+<info id="1">
+ <a/>
+ <b/>
+ <c/>
+</info>
diff --git a/src/test/resources/xsl3_tests_new/input/file2.json b/src/test/resources/xsl3_tests_new/input/file2.json
new file mode 100644
index 000000000..66e8c6c94
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file2.json
@@ -0,0 +1,7 @@
+[
+ "a1",
+ "b1",
+ "c1",
+ "d1",
+ 10
+]
diff --git a/src/test/resources/xsl3_tests_new/input/file2.xml b/src/test/resources/xsl3_tests_new/input/file2.xml
new file mode 100644
index 000000000..295e38b4d
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file2.xml
@@ -0,0 +1,5 @@
+<info id="2">
+ <p/>
+ <q/>
+ <r/>
+</info>
diff --git a/src/test/resources/xsl3_tests_new/input/file3.xml b/src/test/resources/xsl3_tests_new/input/file3.xml
new file mode 100644
index 000000000..a51d1a76e
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file3.xml
@@ -0,0 +1,5 @@
+<info id="3">
+ <m/>
+ <n/>
+ <o/>
+</info>
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/input/file4.json b/src/test/resources/xsl3_tests_new/input/file4.json
new file mode 100644
index 000000000..dc1b23e75
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file4.json
@@ -0,0 +1,11 @@
+{
+ "info" : [
+ {"a" : 1},
+ {"b" : 2},
+ {"c" : 3},
+ {"d" : 4},
+ {"e" : 5},
+ {"f" : 6},
+ {"g" : 7}
+ ]
+}
diff --git a/src/test/resources/xsl3_tests_new/input/file4.xml b/src/test/resources/xsl3_tests_new/input/file4.xml
new file mode 100644
index 000000000..606593ae2
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/input/file4.xml
@@ -0,0 +1,9 @@
+<info>
+ <a1>8</a1>
+ <b1>9</b1>
+ <c1>10</c1>
+ <d1>11</d1>
+ <e1>12</e1>
+ <f1>13</f1>
+ <g1>14</g1>
+</info>
diff --git a/src/test/resources/xsl3_tests_new/json_to_xml1.xsl b/src/test/resources/xsl3_tests_new/json_to_xml1.xsl
new file mode 100644
index 000000000..61ef1f0aa
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/json_to_xml1.xsl
@@ -0,0 +1,46 @@
+<?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:fn="http://www.w3.org/2005/xpath-functions"
+ exclude-result-prefixes="xs fn"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:variable name="jsonStr1" as="xs:string">
+ {
+ "a" : 1,
+ "b" : 2,
+ "c" : 3
+ }
+ </xsl:variable>
+
+ <xsl:variable name="xmlNodeSet1" select="json-to-xml(normalize-space($jsonStr1))" as="element(fn:map)"/>
+
+ <!-- An XSL stylesheet initial template -->
+ <xsl:template name="Template1" visibility="public">
+ <result>
+ <one>
+ <xsl:call-template name="Template2">
+ <xsl:with-param name="nodeSet1" select="$xmlNodeSet1" as="element(fn:map)"/>
+ </xsl:call-template>
+ </one>
+ <two>
+ <xsl:variable name="nodeSetVar1" as="element(fn:map)">
+ <xsl:call-template name="Template2">
+ <xsl:with-param name="nodeSet1" select="$xmlNodeSet1" as="element(fn:map)"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:copy-of select="$nodeSetVar1"/>
+ </two>
+ </result>
+ </xsl:template>
+
+ <xsl:template name="Template2">
+ <xsl:param name="nodeSet1" as="element(fn:map)"/>
+ <xsl:copy-of select="$nodeSet1"/>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/xalan_j_xsl3-test-set.xml b/src/test/resources/xsl3_tests_new/xalan_j_xsl3-test-set.xml
new file mode 100644
index 000000000..7f9dd5b4b
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/xalan_j_xsl3-test-set.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://www.w3.org/2012/10/xslt-test-catalog"
+ name="xalan_j_tests">
+
+ <description>Few Xalan-J XSL 3 tests, written in W3C XSLT 3.0 test suite format</description>
+
+ <environment name="collection-01">
+ <source role=".">
+ <content><![CDATA[<test1/>]]></content>
+ </source>
+ </environment>
+
+ <test-case name="collection_001">
+ <description>.........</description>
+ <created by="......." on="......."/>
+ <environment ref="collection-01"/>
+ <dependencies>
+ <spec value="XSLT20+"/>
+ </dependencies>
+ <test>
+ <stylesheet file="collection_001.xsl"/>
+ </test>
+ <result>
+ <assert-xml><![CDATA[
+ <?xml version="1.0" encoding="UTF-8"?><result>
+ <xmlContents>
+ <info id="1">
+ <a/>
+ <b/>
+ <c/>
+</info>
+ </xmlContents>
+ <xmlContents>
+ <info id="2">
+ <p/>
+ <q/>
+ <r/>
+</info>
+ </xmlContents>
+ <xmlContents>
+ <info id="3">
+ <m/>
+ <n/>
+ <o/>
+</info>
+ </xmlContents>
+ <xmlContents>
+ <info>
+ <a1>8</a1>
+ <b1>9</b1>
+ <c1>10</c1>
+ <d1>11</d1>
+ <e1>12</e1>
+ <f1>13</f1>
+ <g1>14</g1>
+</info>
+ </xmlContents>
+ <txtContents>hello world. this is used
+to test xpath fn:collection function.</txtContents>
+ <map>
+ <entry key="a">1</entry>
+ <entry key="b">2</entry>
+ <entry key="c">3</entry>
+ <entry key="d">4</entry>
+ <entry key="e">5</entry>
+ </map>
+ <array>
+ <item>a1</item>
+ <item>b1</item>
+ <item>c1</item>
+ <item>d1</item>
+ <item>10</item>
+ </array>
+ <map>
+ <entry key="info"> </entry>
+ </map>
+</result>
+ ]]></assert-xml>
+ </result>
+ </test-case>
+
+ <test-case name="collection_002">
+ <description>.........</description>
+ <created by="......." on="......."/>
+ <environment ref="collection-01"/>
+ <dependencies>
+ <spec value="XSLT20+"/>
+ </dependencies>
+ <test>
+ <stylesheet file="collection_002.xsl"/>
+ </test>
+ <result>
+ <assert-xml><![CDATA[
+ <?xml version="1.0" encoding="UTF-8"?><groups>
+ <group key="doesnt_contain_word_hello">
+ <a/>
+ <c/>
+ <p/>
+ <q/>
+ <n/>
+ <o/>
+ </group>
+ <group key="contains_word_hello">
+ <b>hello</b>
+ <r>hello</r>
+ <m>hello</m>
+ </group>
+</groups>
+ ]]></assert-xml>
+ </result>
+ </test-case>
+
+</test-set>
+
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/xpath_bool_1.xsl b/src/test/resources/xsl3_tests_new/xpath_bool_1.xsl
new file mode 100644
index 000000000..db40a6629
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/xpath_bool_1.xsl
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <!-- An XSL stylesheet initial template -->
+ <xsl:template name="Template1" visibility="public">
+ <result>
+ <or>
+ <a><xsl:value-of select="false() or false()"/></a>
+ <b><xsl:value-of select="false() or true()"/></b>
+ <c><xsl:value-of select="true() or false()"/></c>
+ <d><xsl:value-of select="true() or true()"/></d>
+ </or>
+ <and>
+ <a><xsl:value-of select="false() and false()"/></a>
+ <b><xsl:value-of select="false() and true()"/></b>
+ <c><xsl:value-of select="true() and false()"/></c>
+ <d><xsl:value-of select="true() and true()"/></d>
+ </and>
+ <not>
+ <a><xsl:value-of select="not(false())"/></a>
+ <b><xsl:value-of select="not(true())"/></b>
+ </not>
+ </result>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/xpath_bool_2.xsl b/src/test/resources/xsl3_tests_new/xpath_bool_2.xsl
new file mode 100644
index 000000000..a3cf89825
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/xpath_bool_2.xsl
@@ -0,0 +1,35 @@
+<?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 -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <!-- An XSL stylesheet initial template -->
+ <xsl:template name="Template1" visibility="public">
+ <result>
+ <xsl:variable name="v1" select="'a'" as="xs:string"/>
+ <xsl:variable name="v2" select="'b'" as="xs:string"/>
+ <or>
+ <a><xsl:value-of select="($v1 eq $v2) or ($v1 eq $v2)"/></a>
+ <b><xsl:value-of select="($v1 eq $v2) or ($v1 eq $v1)"/></b>
+ <c><xsl:value-of select="($v1 eq $v1) or ($v1 eq $v2)"/></c>
+ <d><xsl:value-of select="($v1 eq $v1) or ($v1 eq $v1)"/></d>
+ </or>
+ <and>
+ <a><xsl:value-of select="($v1 eq $v2) and ($v1 eq $v2)"/></a>
+ <b><xsl:value-of select="($v1 eq $v2) and ($v1 eq $v1)"/></b>
+ <c><xsl:value-of select="($v1 eq $v1) and ($v1 eq $v2)"/></c>
+ <d><xsl:value-of select="($v1 eq $v1) and ($v1 eq $v1)"/></d>
+ </and>
+ <not>
+ <a><xsl:value-of select="not(($v1 eq $v2))"/></a>
+ <b><xsl:value-of select="not(($v1 eq $v1))"/></b>
+ </not>
+ </result>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/src/test/resources/xsl3_tests_new/xpath_bool_3.xsl b/src/test/resources/xsl3_tests_new/xpath_bool_3.xsl
new file mode 100644
index 000000000..3bacdd12c
--- /dev/null
+++ b/src/test/resources/xsl3_tests_new/xpath_bool_3.xsl
@@ -0,0 +1,35 @@
+<?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 -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <!-- An XSL stylesheet initial template -->
+ <xsl:template name="Template1" visibility="public">
+ <result>
+ <xsl:variable name="v1" select="5" as="xs:integer"/>
+ <xsl:variable name="v2" select="6" as="xs:integer"/>
+ <or>
+ <a><xsl:value-of select="($v1 eq $v2) or ($v1 eq $v2)"/></a>
+ <b><xsl:value-of select="($v1 eq $v2) or ($v1 eq $v1)"/></b>
+ <c><xsl:value-of select="($v1 eq $v1) or ($v1 eq $v2)"/></c>
+ <d><xsl:value-of select="($v1 eq $v1) or ($v1 eq $v1)"/></d>
+ </or>
+ <and>
+ <a><xsl:value-of select="($v1 eq $v2) and ($v1 eq $v2)"/></a>
+ <b><xsl:value-of select="($v1 eq $v2) and ($v1 eq $v1)"/></b>
+ <c><xsl:value-of select="($v1 eq $v1) and ($v1 eq $v2)"/></c>
+ <d><xsl:value-of select="($v1 eq $v1) and ($v1 eq $v1)"/></d>
+ </and>
+ <not>
+ <a><xsl:value-of select="not(($v1 eq $v2))"/></a>
+ <b><xsl:value-of select="not(($v1 eq $v1))"/></b>
+ </not>
+ </result>
+ </xsl:template>
+
+</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