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 2024/08/24 16:49:22 UTC

(xalan-java) branch xalan-j_xslt3.0 updated: committing fix for jira issue XALANJ-2780

This is an automated email from the ASF dual-hosted git repository.

mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git


The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
     new 8e1100cfb committing fix for jira issue XALANJ-2780
8e1100cfb is described below

commit 8e1100cfb9be1e59028bcb1c9a1e0066f019bae0
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Aug 24 22:19:05 2024 +0530

    committing fix for jira issue XALANJ-2780
---
 src/org/apache/xalan/templates/ElemValueOf.java    | 40 ++++++++++++++++++
 tests/jira_issues/gold/test3.out                   | 10 +++++
 tests/jira_issues/test3.xsl                        | 47 ++++++++++++++++++++++
 .../xalan/{xpath3 => xslt3}/JiraIssuesTests.java   | 15 ++++++-
 tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java   |  9 ++---
 5 files changed, 114 insertions(+), 7 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemValueOf.java b/src/org/apache/xalan/templates/ElemValueOf.java
index eb2f95943..57c08676e 100644
--- a/src/org/apache/xalan/templates/ElemValueOf.java
+++ b/src/org/apache/xalan/templates/ElemValueOf.java
@@ -735,6 +735,13 @@ public class ElemValueOf extends ElemTemplateElement {
 			  if (m_separator != null) {        				
 				  nodeStrVal = nodeStrVal.replace(" ", m_separator);
 				  nodeStrVal = nodeStrVal.substring(0, (nodeStrVal.length() - 1));
+				  String rTrimmedSeparator = strRtrim(m_separator);
+				  if (!m_separator.equals(rTrimmedSeparator)) {
+					  int lIdx = nodeStrVal.lastIndexOf(rTrimmedSeparator);
+					  if (lIdx > 0) {
+						  nodeStrVal = nodeStrVal.substring(0, lIdx);
+					  } 
+				  }
 			  }
 			  else {
 				  nodeStrVal = nodeStrVal.trim();
@@ -750,5 +757,38 @@ public class ElemValueOf extends ElemTemplateElement {
 		  (new XString(nodeStrVal)).dispatchCharactersEvents(rth);
 	  }
    }
+  
+   /**
+    * This method strips whitespace characaters from RHS of 
+    * an input string, and returns the resulting string.
+    */
+   private String strRtrim(String str) {
+	  String resultStr = null;
+	  
+	  if (str.length() == 0) {
+		 resultStr = "";  
+	  }
+	  else if (str.length() == 1) {
+		 if (Character.isWhitespace(str.charAt(0))) {
+			resultStr = ""; 
+		 }
+		 else {
+			resultStr = str;
+		 }
+	  }
+	  else {
+		 char chr = str.charAt(str.length() - 1);
+		 if (Character.isWhitespace(chr)) {
+			resultStr = str.substring(0, str.length() - 1);
+			// Recursive call to this method
+			resultStr = strRtrim(resultStr); 
+		 }
+		 else {
+			resultStr = str; 
+		 }
+	  }
+	  
+	  return resultStr;
+   }
 
 }
diff --git a/tests/jira_issues/gold/test3.out b/tests/jira_issues/gold/test3.out
new file mode 100644
index 000000000..b8251f083
--- /dev/null
+++ b/tests/jira_issues/gold/test3.out
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <section>
+    <h2>Test 1</h2>
+    <p>1 | 2 | 3 | 4 | 5</p>
+  </section>
+  <section>
+    <h2>Test 2</h2>
+    <p>1 | 2 | 3 | 4 | 5</p>
+  </section>
+</result>
diff --git a/tests/jira_issues/test3.xsl b/tests/jira_issues/test3.xsl
new file mode 100644
index 000000000..fa16fbea8
--- /dev/null
+++ b/tests/jira_issues/test3.xsl
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+				version="3.0">
+				
+  <!-- An XSL stylesheet, contributed by Martin Honnen,
+       for the jira issue XALANJ-2780. -->				
+				
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/">
+     <result>
+		 <section>
+			<h2>Test 1</h2>
+			<p>
+			   <xsl:value-of select="1 to 5" separator=" | "/>
+			</p>
+		 </section>
+		 <section>
+			<h2>Test 2</h2>
+			<p>
+			   <xsl:value-of separator=" | ">
+				 <xsl:sequence select="1 to 5"/>
+			   </xsl:value-of>
+			</p>
+		 </section>
+	 </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>
\ No newline at end of file
diff --git a/tests/org/apache/xalan/xpath3/JiraIssuesTests.java b/tests/org/apache/xalan/xslt3/JiraIssuesTests.java
similarity index 83%
rename from tests/org/apache/xalan/xpath3/JiraIssuesTests.java
rename to tests/org/apache/xalan/xslt3/JiraIssuesTests.java
index 489b1e491..39ce41fe9 100644
--- a/tests/org/apache/xalan/xpath3/JiraIssuesTests.java
+++ b/tests/org/apache/xalan/xslt3/JiraIssuesTests.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.xalan.xpath3;
+package org.apache.xalan.xslt3;
 
 import org.apache.xalan.util.XSLConstants;
 import org.apache.xalan.util.XSLTransformTestsUtil;
@@ -23,7 +23,8 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
- * Xalan-J jira issues, test cases.
+ * Xalan-J jira issues, test cases for XSL 3 
+ * implementation work.
  * 
  * @author Mukul Gandhi <mu...@apache.org>
  * 
@@ -66,5 +67,15 @@ public class JiraIssuesTests extends XSLTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslJiraIssuesTest3() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
index 97cf59dbb..edbbfdabe 100644
--- a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
+++ b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
@@ -32,25 +32,24 @@ import org.apache.xalan.xpath3.FnJsonToXmlTests;
 import org.apache.xalan.xpath3.FnLangTests;
 import org.apache.xalan.xpath3.FnMapFindTests;
 import org.apache.xalan.xpath3.FnMapMerge;
-import org.apache.xalan.xpath3.XPathMapOtherTests;
 import org.apache.xalan.xpath3.FnParseJsonTests;
 import org.apache.xalan.xpath3.FnQNameTests;
 import org.apache.xalan.xpath3.FnResolveQNameTests;
 import org.apache.xalan.xpath3.FnRootTests;
 import org.apache.xalan.xpath3.FnXmlToJsonTests;
 import org.apache.xalan.xpath3.FuncBooleanValuesTests;
-import org.apache.xalan.xpath3.XPathInlineFunctionItemExprTests;
-import org.apache.xalan.xpath3.JiraIssuesTests;
-import org.apache.xalan.xpath3.XPathStringTests;
-import org.apache.xalan.xpath3.XPathValueComparisonTests;
 import org.apache.xalan.xpath3.XPathArrayTests;
 import org.apache.xalan.xpath3.XPathArrowOpTests;
 import org.apache.xalan.xpath3.XPathCastTests;
 import org.apache.xalan.xpath3.XPathExprFunctionCallSuffixTests;
 import org.apache.xalan.xpath3.XPathGeneralComparisonOpTests;
+import org.apache.xalan.xpath3.XPathInlineFunctionItemExprTests;
+import org.apache.xalan.xpath3.XPathMapOtherTests;
 import org.apache.xalan.xpath3.XPathMapTests;
 import org.apache.xalan.xpath3.XPathNamedFunctionReferenceTests;
 import org.apache.xalan.xpath3.XPathNumericArithmeticTests;
+import org.apache.xalan.xpath3.XPathStringTests;
+import org.apache.xalan.xpath3.XPathValueComparisonTests;
 import org.apache.xalan.xpath3.XsConstructorFunctionTests;
 import org.apache.xalan.xpath3.XsDateTimeArithmeticTests;
 import org.apache.xalan.xpath3.XsDateTimeTests;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org