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/02/21 06:13:50 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing an xsl 3 stylesheet test case, to test linear regression
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 77fbcfc3d committing an xsl 3 stylesheet test case, to test linear regression
77fbcfc3d is described below
commit 77fbcfc3dff28cbfd0db23f1252d8b1b25869005
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Feb 21 11:43:27 2026 +0530
committing an xsl 3 stylesheet test case, to test linear regression
---
README | 6 +-
.../xalan/tests/main/XalanXsl3TestSuite2.java | 3 +-
.../tests/xslt3/XslLinearRegressionTests.java | 62 +++++++++++++++
.../resources/linear_regression/gold/test1.out | 5 ++
src/test/resources/linear_regression/test1.xml | 13 ++++
src/test/resources/linear_regression/test1.xsl | 89 ++++++++++++++++++++++
6 files changed, 174 insertions(+), 4 deletions(-)
diff --git a/README b/README
index b39ed2e3c..19a78b4c4 100644
--- a/README
+++ b/README
@@ -17,7 +17,7 @@
Copyright 1999-2025 The Apache Software Foundation
-Document last modified : 2026-02-20
+Document last modified : 2026-02-21
Authors:
Gary Gregory <gg...@apache.org>
@@ -49,11 +49,11 @@ The Maven build results like following shall be produced:
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.xalan.tests.main.AllXalanXSLT3Tests
-[INFO] Tests run: 1400, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: ..... - in org.apache.xalan.tests.main.AllXalanXSLT3Tests
+[INFO] Tests run: 1401, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: ..... - in org.apache.xalan.tests.main.AllXalanXSLT3Tests
[INFO]
[INFO] Results:
[INFO]
-[INFO] Tests run: 1400, Failures: 0, Errors: 0, Skipped: 0
+[INFO] Tests run: 1401, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ xalan-java ---
diff --git a/src/test/java/org/apache/xalan/tests/main/XalanXsl3TestSuite2.java b/src/test/java/org/apache/xalan/tests/main/XalanXsl3TestSuite2.java
index fe5360111..324b29e9d 100644
--- a/src/test/java/org/apache/xalan/tests/main/XalanXsl3TestSuite2.java
+++ b/src/test/java/org/apache/xalan/tests/main/XalanXsl3TestSuite2.java
@@ -100,6 +100,7 @@ import org.apache.xalan.tests.xslt3.XslIncludeTests;
import org.apache.xalan.tests.xslt3.XslInitialTemplateTests;
import org.apache.xalan.tests.xslt3.XslIterateTests;
import org.apache.xalan.tests.xslt3.XslJsonValidationTests;
+import org.apache.xalan.tests.xslt3.XslLinearRegressionTests;
import org.apache.xalan.tests.xslt3.XslMergeTests;
import org.apache.xalan.tests.xslt3.XslMessageTests;
import org.apache.xalan.tests.xslt3.XslMethodOutputJsonTests;
@@ -161,7 +162,7 @@ import org.junit.runners.Suite.SuiteClasses;
XPathTextAndNodePattern.class, XPathLiteralSequenceTests.class, XslModeTests.class, XslTemplatePriorityTests.class,
XslDisableOutputEscapingAttrTests.class, XslMessageTests.class, FnAdjustDatetimeToTimezoneTests.class,
FnAdjustDateToTimezoneTests.class, FnAdjustTimeToTimezoneTests.class, FnFormatIntegerTests.class, XslPerformSortTests.class,
- XslPackageTests.class, XslUseWhenTests.class } )
+ XslPackageTests.class, XslUseWhenTests.class, XslLinearRegressionTests.class } )
public class XalanXsl3TestSuite2 {
}
diff --git a/src/test/java/org/apache/xalan/tests/xslt3/XslLinearRegressionTests.java b/src/test/java/org/apache/xalan/tests/xslt3/XslLinearRegressionTests.java
new file mode 100644
index 000000000..506f17870
--- /dev/null
+++ b/src/test/java/org/apache/xalan/tests/xslt3/XslLinearRegressionTests.java
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.xalan.tests.xslt3;
+
+import org.apache.xalan.tests.util.XSLTestConstants;
+import org.apache.xalan.tests.util.XslTransformTestsUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XSL 3 stylesheet test cases, to test statistical
+ prediction with linear regression.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class XslLinearRegressionTests extends XslTransformTestsUtil {
+
+ private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLTestConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "linear_regression/";
+
+ private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLTestConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "linear_regression/gold/";
+
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ // no op
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ m_xmlDocumentBuilderFactory = null;
+ m_xmlDocumentBuilder = null;
+ m_xslTransformerFactory = null;
+ }
+
+ @Test
+ public void xslLinearRegressionTest1() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+}
diff --git a/src/test/resources/linear_regression/gold/test1.out b/src/test/resources/linear_regression/gold/test1.out
new file mode 100644
index 000000000..43dfb92dc
--- /dev/null
+++ b/src/test/resources/linear_regression/gold/test1.out
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <answer x="23" y="4.6"/>
+ <answer x="37" y="7.4"/>
+ <answer x="42" y="8.4"/>
+</result>
diff --git a/src/test/resources/linear_regression/test1.xml b/src/test/resources/linear_regression/test1.xml
new file mode 100644
index 000000000..afe4a4538
--- /dev/null
+++ b/src/test/resources/linear_regression/test1.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<data>
+ <point x="5" y="1"/>
+ <point x="10" y="2"/>
+ <point x="15" y="3"/>
+ <point x="20" y="4"/>
+ <point x="25" y="5"/>
+ <point x="30" y="6"/>
+ <point x="35" y="7"/>
+ <point x="40" y="8"/>
+ <point x="45" y="9"/>
+ <point x="50" y="10"/>
+</data>
diff --git a/src/test/resources/linear_regression/test1.xsl b/src/test/resources/linear_regression/test1.xsl
new file mode 100644
index 000000000..57b1c87a1
--- /dev/null
+++ b/src/test/resources/linear_regression/test1.xsl
@@ -0,0 +1,89 @@
+<?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:math="http://www.w3.org/2005/xpath-functions/math"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="#all"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test1.xml -->
+
+ <!-- An XSL 3 stylesheet example, to implement statistical
+ prediction with linear regression. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <!-- Value of linear regression weight, using sample data -->
+ <xsl:variable name="w" select="fn0:getWeight(data)" as="xs:double"/>
+
+ <!-- Value of linear regression bias, using sample data -->
+ <xsl:variable name="b" select="fn0:getBias(data, $w)" as="xs:double"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:for-each select="(23, 37, 42)">
+ <answer x="{.}" y="{fn0:predictY(., $w, $b)}"/>
+ </xsl:for-each>
+ </result>
+ </xsl:template>
+
+ <!-- An XSL stylesheet function, to predict value of 'y'
+ (dependent variable) for a supplied input value ('x'),
+ using a linear prediction model. -->
+ <xsl:function name="fn0:predictY" as="xs:double">
+ <xsl:param name="x" as="xs:double"/>
+ <xsl:param name="w" as="xs:double"/>
+ <xsl:param name="b" as="xs:double"/>
+ <xsl:sequence select="($w * $x) + $b"/>
+ </xsl:function>
+
+ <!-- An XSL stylesheet function, to get linear regression
+ weight, using sample data. -->
+ <xsl:function name="fn0:getWeight" as="xs:double">
+ <xsl:param name="data" as="element(data)"/>
+ <xsl:variable name="meanX" select="sum($data/point/@x) div count($data/point)" as="xs:double"/>
+ <xsl:variable name="meanY" select="sum($data/point/@y) div count($data/point)" as="xs:double"/>
+ <xsl:iterate select="$data/point">
+ <xsl:param name="a" select="0" as="xs:double"/>
+ <xsl:param name="b" select="0" as="xs:double"/>
+ <xsl:on-completion>
+ <xsl:sequence select="$a div $b"/>
+ </xsl:on-completion>
+ <xsl:next-iteration>
+ <xsl:with-param name="a" select="$a + (./@x - $meanX) * (./@y - $meanY)" as="xs:double"/>
+ <xsl:with-param name="b" select="$b + math:pow((./@x - $meanX),2)" as="xs:double"/>
+ </xsl:next-iteration>
+ </xsl:iterate>
+ </xsl:function>
+
+ <!-- An XSL stylesheet function, to get linear regression
+ bias, using sample data. -->
+ <xsl:function name="fn0:getBias" as="xs:double">
+ <xsl:param name="data" as="element(data)"/>
+ <xsl:param name="w" as="xs:double"/>
+ <xsl:variable name="meanX" select="sum($data/point/@x) div count($data/point)" as="xs:double"/>
+ <xsl:variable name="meanY" select="sum($data/point/@y) div count($data/point)" as="xs:double"/>
+ <xsl:sequence select="($meanY - ($w * $meanX)) div count($data)"/>
+ </xsl:function>
+
+ <!--
+ * 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>
\ 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