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 2023/08/27 14:33:45 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: committing implementation of xpath 3.1 function fn:parse-xml-fragment, and committing a related working new test case. fixing a bug for the processing of xsl:attribute instruction when using 'select' attribute, related to xslt variables not been resolved. committing and improving few other relevant xslt 3.0 test cases. and committing minor improvements to comments within codebase within this xalanj dev repos branch.

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 3b247329 committing implementation of xpath 3.1 function fn:parse-xml-fragment, and committing a related working new test case. fixing a bug for the processing of xsl:attribute instruction when using 'select' attribute, related to xslt variables not been resolved. committing and improving few other relevant xslt 3.0 test cases. and committing minor improvements to comments within codebase within this xalanj dev repos branch.
     new 0dd6305a Merge pull request #65 from mukulga/xalan-j_xslt3.0_mukul
3b247329 is described below

commit 3b247329a80c35314f5e7b15e7a64ec74b9df79d
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sun Aug 27 19:58:28 2023 +0530

    committing implementation of xpath 3.1 function fn:parse-xml-fragment, and committing a related working new test case. fixing a bug for the processing of xsl:attribute instruction when using 'select' attribute, related to xslt variables not been resolved. committing and improving few other relevant xslt 3.0 test cases. and committing minor improvements to comments within codebase within this xalanj dev repos branch.
---
 src/org/apache/xalan/templates/ElemAttribute.java  | 25 +++++++++
 .../xalan/templates/ElemTemplateElement.java       |  6 ++-
 src/org/apache/xpath/VariableStack.java            |  7 ++-
 src/org/apache/xpath/compiler/FunctionTable.java   |  9 +++-
 src/org/apache/xpath/compiler/Keywords.java        |  3 ++
 src/org/apache/xpath/functions/FuncParseXml.java   |  2 +-
 ...FuncParseXml.java => FuncParseXmlFragment.java} | 34 ++++++++----
 tests/fn_parse_xml/test1.xsl                       |  6 +--
 tests/fn_parse_xml/test2.xsl                       |  2 +-
 tests/fn_parse_xml_fragment/gold/test1.out         |  9 ++++
 .../test1.xsl                                      | 48 +++++++++++------
 .../xalan/xpath3/FnParseXmlFragmentTests.java      | 62 ++++++++++++++++++++++
 tests/org/apache/xalan/xpath3/RangeExprTests.java  | 13 ++++-
 tests/org/apache/xalan/xslt3/AllXsl3Tests.java     |  3 +-
 tests/org/apache/xalan/xslt3/TemplateTests.java    | 60 +++++++++++++++++++++
 tests/range_expr/gold/test14.out                   | 17 ++++++
 .../test1.xsl => range_expr/test14.xsl}            | 42 +++++++++------
 tests/range_expr/test1_d.xml                       |  7 +++
 tests/xsl_template/gold/test1.out                  |  7 +++
 tests/{fn_parse_xml => xsl_template}/test1.xsl     | 41 +++++++-------
 tests/xsl_template/test1_a.xml                     |  7 +++
 21 files changed, 338 insertions(+), 72 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemAttribute.java b/src/org/apache/xalan/templates/ElemAttribute.java
index 625b4013..08ee9083 100644
--- a/src/org/apache/xalan/templates/ElemAttribute.java
+++ b/src/org/apache/xalan/templates/ElemAttribute.java
@@ -20,6 +20,8 @@
  */
 package org.apache.xalan.templates;
 
+import java.util.Vector;
+
 import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.res.XSLTErrorResources;
@@ -62,6 +64,12 @@ public class ElemAttribute extends ElemElement
      * The "select" expression.
      */
     protected Expression m_selectExpression = null;
+    
+    // The following two variables are used, for performing fixupVariables
+    // action on certain XPath expression objects, within an object of this
+    // class.
+    private Vector fVars;    
+    private int fGlobalsSize;
 
   /**
    * Get an int constant identifying the type of element.
@@ -104,6 +112,18 @@ public class ElemAttribute extends ElemElement
       return m_selectExpression;
   }
   
+  public void compose(StylesheetRoot sroot) throws TransformerException
+  {
+    super.compose(sroot);
+    
+    StylesheetRoot.ComposeState cstate = sroot.getComposeState();
+    java.util.Vector vnames = cstate.getVariableNames();
+    int golbalsSize = cstate.getGlobalsSize();
+    
+    fVars = (java.util.Vector)(vnames.clone());
+    fGlobalsSize = golbalsSize; 
+  }
+  
   /**
    * Resolve the namespace into a prefix.  At this level, if no prefix exists, 
    * then return a manufactured prefix.
@@ -189,6 +209,11 @@ public class ElemAttribute extends ElemElement
                             
               if (m_selectExpression != null) {
                   // evaluate the value of xsl:attribute's "select" attribute
+                  
+                  if (fVars != null) {
+                     m_selectExpression.fixupVariables(fVars, fGlobalsSize);   
+                  }
+                  
                   XObject xpathEvalResult = m_selectExpression.execute(xctxt);              
                   val = xpathEvalResult.str();
               }
diff --git a/src/org/apache/xalan/templates/ElemTemplateElement.java b/src/org/apache/xalan/templates/ElemTemplateElement.java
index 65647efc..f9813792 100644
--- a/src/org/apache/xalan/templates/ElemTemplateElement.java
+++ b/src/org/apache/xalan/templates/ElemTemplateElement.java
@@ -1742,7 +1742,8 @@ public class ElemTemplateElement extends UnImplNode
   /**
    * During processing of, xsl:for-each or xsl:iterate instruction, when the input data to be
    * processed by these instructions is a 'ResultSequence' object, we use this method to set
-   * the XPath context information before each sequence item is processed by these instructions.
+   * the XPath context information before each sequence item is processed by these 
+   * XSL instructions.
    * 
    * @param inpSequenceLength                  an input data sequence length
    * @param currentlyProcessingItemIndex       an index of currently processed item within an 
@@ -1770,7 +1771,8 @@ public class ElemTemplateElement extends UnImplNode
   /**
    * During processing of, xsl:for-each or xsl:iterate instruction, when the input data to be
    * processed by these instructions is a 'ResultSequence' object, we use this method to reset
-   * the XPath context information after each sequence item is processed by these instructions. 
+   * the XPath context information after each sequence item has been processed by these 
+   * XSL instructions. 
    * 
    * @param currentContextItem      the current xdm item been processed
    * @param xctxt                   the currently active, XPath context object
diff --git a/src/org/apache/xpath/VariableStack.java b/src/org/apache/xpath/VariableStack.java
index fcdab8b2..26416586 100644
--- a/src/org/apache/xpath/VariableStack.java
+++ b/src/org/apache/xpath/VariableStack.java
@@ -20,6 +20,7 @@
  */
 package org.apache.xpath;
 
+import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.res.XSLMessages;
@@ -501,6 +502,8 @@ public class VariableStack implements Cloneable
 
     org.apache.xml.utils.PrefixResolver prefixResolver =
       xctxt.getNamespaceContext();
+    
+    SourceLocator srcLocator = xctxt.getSAXLocator();
 
     // Get the current ElemTemplateElement, which must be pushed in as the 
     // prefix resolver, and then walk backwards in document order, searching 
@@ -541,7 +544,9 @@ public class VariableStack implements Cloneable
         return getGlobalVariable(xctxt, vvar.getIndex());
     }
 
-    throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[]{qname.toString()})); //"Variable not resolvable: " + qname);
+    throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.
+                                                                          ER_VAR_NOT_RESOLVABLE, new Object[]{qname.toString()}), 
+                                                                                             srcLocator); //"Variable not resolvable: " + qname);
   }
 }  // end VariableStack
 
diff --git a/src/org/apache/xpath/compiler/FunctionTable.java b/src/org/apache/xpath/compiler/FunctionTable.java
index ded47104..6bcc12d0 100644
--- a/src/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/org/apache/xpath/compiler/FunctionTable.java
@@ -305,6 +305,9 @@ public class FunctionTable
   
   /** The 'parse-xml()' id. */
   public static final int FUNC_PARSE_XML = 93;
+  
+  /** The 'parse-xml-fragment()' id. */
+  public static final int FUNC_PARSE_XML_FRAGMENT = 94;
 
   // Proprietary
 
@@ -362,7 +365,7 @@ public class FunctionTable
    * Number of built in functions. Be sure to update this as
    * built-in functions are added.
    */
-  private static final int NUM_BUILT_IN_FUNCS = 94;
+  private static final int NUM_BUILT_IN_FUNCS = 95;
 
   /**
    * Number of built-in functions that may be added.
@@ -551,6 +554,8 @@ public class FunctionTable
     
     m_functions[FUNC_PARSE_XML] = 
       org.apache.xpath.functions.FuncParseXml.class;
+    m_functions[FUNC_PARSE_XML_FRAGMENT] = 
+      org.apache.xpath.functions.FuncParseXmlFragment.class;
     
   }
 
@@ -747,6 +752,8 @@ public class FunctionTable
          
          m_functionID.put(Keywords.FUNC_PARSE_XML,
                          new Integer(FunctionTable.FUNC_PARSE_XML));
+         m_functionID.put(Keywords.FUNC_PARSE_XML_FRAGMENT,
+                         new Integer(FunctionTable.FUNC_PARSE_XML_FRAGMENT));
   }
   
   public FunctionTable(){
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index 2befeee8..f0b394c6 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -416,6 +416,9 @@ public class Keywords
   /** parse-xml function string. */
   public static final String FUNC_PARSE_XML = "parse-xml";
   
+  /** parse-xml-fragment function string. */
+  public static final String FUNC_PARSE_XML_FRAGMENT = "parse-xml-fragment";
+  
   // Proprietary, built in functions
 
   /** current function string (Proprietary). */
diff --git a/src/org/apache/xpath/functions/FuncParseXml.java b/src/org/apache/xpath/functions/FuncParseXml.java
index ea5f4571..f862493f 100644
--- a/src/org/apache/xpath/functions/FuncParseXml.java
+++ b/src/org/apache/xpath/functions/FuncParseXml.java
@@ -81,7 +81,7 @@ public class FuncParseXml extends FunctionOneArg {
         try {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             
-            // make the XML namespace processing active, on an XML parse 
+            // Make the XML namespace processing active, on an XML parse 
             // of the string value.
             dbf.setNamespaceAware(true);         
             
diff --git a/src/org/apache/xpath/functions/FuncParseXml.java b/src/org/apache/xpath/functions/FuncParseXmlFragment.java
similarity index 67%
copy from src/org/apache/xpath/functions/FuncParseXml.java
copy to src/org/apache/xpath/functions/FuncParseXmlFragment.java
index ea5f4571..fe773d3e 100644
--- a/src/org/apache/xpath/functions/FuncParseXml.java
+++ b/src/org/apache/xpath/functions/FuncParseXmlFragment.java
@@ -31,17 +31,19 @@ import org.apache.xpath.XPathContext;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XObject;
 import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.NodeList;
 
 /**
- * Implementation of the parse-xml() function.
+ * Implementation of the parse-xml-fragment() function.
  * 
  * @author Mukul Gandhi <mu...@apache.org>
  * 
  * @xsl.usage advanced
  */
-public class FuncParseXml extends FunctionOneArg {
+public class FuncParseXmlFragment extends FunctionOneArg {
 
-    private static final long serialVersionUID = -6262670777202140694L;
+    private static final long serialVersionUID = -3212697250471567672L;
 
     /**
      * Execute the function. The function must return a valid object.
@@ -58,7 +60,7 @@ public class FuncParseXml extends FunctionOneArg {
         SourceLocator srcLocator = xctxt.getSAXLocator();
 
         try {
-            XObject xObject0 = m_arg0.execute(xctxt);
+            XObject xObject0 = m_arg0.execute(xctxt);            
             
             String argStrVal = XslTransformEvaluationHelper.getStrVal(xObject0);
             
@@ -72,7 +74,7 @@ public class FuncParseXml extends FunctionOneArg {
     }
     
     /**
-     * Get an XDM nodeset corresponding to an XML string value.
+     * Get an XDM nodeset corresponding to an XML fragment string value.
      */
     private XNodeSet getNodeSetFromStr(String strVal, XPathContext xctxt) throws 
                                                           javax.xml.transform.TransformerException {
@@ -81,17 +83,31 @@ public class FuncParseXml extends FunctionOneArg {
         try {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             
-            // make the XML namespace processing active, on an XML parse 
+            // Make the XML namespace processing active, on an XML parse 
             // of the string value.
             dbf.setNamespaceAware(true);         
             
             DocumentBuilder dBuilder = dbf.newDocumentBuilder();
             
-            InputStream inpStream = new ByteArrayInputStream(strVal.getBytes(
-                                                                      StandardCharsets.UTF_8));
+            // Wrap the originally provided string value (that is supposed to be an XML fragment 
+            // string value), with a temporary XML outer element.
+            String currentTimeMillisec = String.valueOf(System.currentTimeMillis());
+            String tempOuterWrapperElementName = "t0_" + currentTimeMillisec;            
+            String wrappedXmlStrVal = "<"+tempOuterWrapperElementName+">" + strVal + 
+                                                                              "</"+tempOuterWrapperElementName+">"; 
+            
+            InputStream inpStream = new ByteArrayInputStream(wrappedXmlStrVal.getBytes(
+                                                                                    StandardCharsets.UTF_8));
             Document xmlDocument = dBuilder.parse(inpStream);
             
-            DTM dtm = xctxt.getDTM(new DOMSource(xmlDocument), true, null, false, false);            
+            DocumentFragment xmlDocFragment = xmlDocument.createDocumentFragment();            
+            NodeList xmlDomChildNodes = (xmlDocument.getDocumentElement()).getChildNodes();
+            
+            while (xmlDomChildNodes.getLength() > 0) {
+               xmlDocFragment.appendChild(xmlDomChildNodes.item(0));
+            }
+            
+            DTM dtm = xctxt.getDTM(new DOMSource(xmlDocFragment), true, null, false, false);            
             int documentNodeHandleVal = dtm.getDocument();
             
             nodeSet = new XNodeSet(documentNodeHandleVal, xctxt.getDTMManager());
diff --git a/tests/fn_parse_xml/test1.xsl b/tests/fn_parse_xml/test1.xsl
index 9fdb6234..34408b29 100644
--- a/tests/fn_parse_xml/test1.xsl
+++ b/tests/fn_parse_xml/test1.xsl
@@ -4,9 +4,9 @@
                 
     <!-- Author: mukulg@apache.org -->
    
-    <!-- An XSLT stylesheet test, for the XPath 3.1 fn:parse-xml() function.
-         The XPath function fn:parse-xml's example, as used within this
-         stylesheet is borrowed from XPath 3.1 F&O spec. -->                
+    <!-- An XSLT stylesheet test, to test the XPath 3.1 fn:parse-xml()
+         function. The XPath function fn:parse-xml's usage example, as used
+         within this stylesheet is borrowed from XPath 3.1 F&O spec. -->                
                 
     <xsl:output method="xml" indent="yes"/>
     
diff --git a/tests/fn_parse_xml/test2.xsl b/tests/fn_parse_xml/test2.xsl
index 3dcbd6e1..9bb26a9f 100644
--- a/tests/fn_parse_xml/test2.xsl
+++ b/tests/fn_parse_xml/test2.xsl
@@ -4,7 +4,7 @@
                 
     <!-- Author: mukulg@apache.org -->
    
-    <!-- An XSLT stylesheet test, for the XPath 3.1 fn:parse-xml() 
+    <!-- An XSLT stylesheet test, to test the XPath 3.1 fn:parse-xml() 
          function.
          
          Within this stylesheet, we parse an XML document string value
diff --git a/tests/fn_parse_xml_fragment/gold/test1.out b/tests/fn_parse_xml_fragment/gold/test1.out
new file mode 100644
index 00000000..f8698976
--- /dev/null
+++ b/tests/fn_parse_xml_fragment/gold/test1.out
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>
+    <alpha>abcd</alpha>
+    <beta>abcd</beta>
+  </one>
+  <two>He was <i>so</i> kind</two>
+  <three/>
+  <four> </four>
+</result>
diff --git a/tests/fn_parse_xml/test1.xsl b/tests/fn_parse_xml_fragment/test1.xsl
similarity index 50%
copy from tests/fn_parse_xml/test1.xsl
copy to tests/fn_parse_xml_fragment/test1.xsl
index 9fdb6234..0c180947 100644
--- a/tests/fn_parse_xml/test1.xsl
+++ b/tests/fn_parse_xml_fragment/test1.xsl
@@ -1,29 +1,43 @@
 <?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 -->
    
-    <!-- An XSLT stylesheet test, for the XPath 3.1 fn:parse-xml() function.
-         The XPath function fn:parse-xml's example, as used within this
-         stylesheet is borrowed from XPath 3.1 F&O spec. -->                
-                
-    <xsl:output method="xml" indent="yes"/>
-    
-    <!-- The XML document string value, passed to fn:parse-xml 
-         function call within below mentioned xsl:variable 
-         declaration is following (with XML special characters 
-         escaped within function call fn:parse-xml's argument, 
-         according to XML conventions),
+    <!-- An XSLT stylesheet test, to test the XPath 3.1 fn:parse-xml-fragment()
+         function. The XPath function fn:parse-xml-fragment's usage examples,
+         as used within this stylesheet are borrowed from XPath 3.1 F&O spec. 
          
-         <alpha>abcd</alpha> 
+         The XML special characters present within, function call 
+         fn:parse-xml-fragment's argument, have been escaped according to XML
+         conventions.
     -->
-    <xsl:variable name="xmlDocNode" select="parse-xml('&lt;alpha&gt;abcd&lt;/alpha&gt;')"/>
-        
+         
+    <xsl:output method="xml" indent="yes"/>
+
+    <xsl:variable name="xmlDocNode1" select="parse-xml-fragment('&lt;alpha&gt;abcd&lt;/alpha&gt;&lt;beta&gt;abcd&lt;/beta&gt;')"/>
+    
+    <xsl:variable name="xmlDocNode2" select="parse-xml-fragment('He was &lt;i&gt;so&lt;/i&gt; kind')"/>
+    
+    <xsl:variable name="xmlDocNode3" select="parse-xml-fragment('')"/>
+    
+    <xsl:variable name="xmlDocNode4" select="parse-xml-fragment(' ')"/>
+    
     <xsl:template match="/">
        <result>
-          <xsl:copy-of select="$xmlDocNode"/>
-       </result>
+         <one>
+            <xsl:copy-of select="$xmlDocNode1"/>
+         </one>
+         <two>
+	        <xsl:copy-of select="$xmlDocNode2"/>
+         </two>
+         <three>
+	        <xsl:copy-of select="$xmlDocNode3"/>
+         </three>
+         <four>
+	        <xsl:copy-of select="$xmlDocNode4"/>
+         </four>
+       </result> 
     </xsl:template>
     
     <!--
diff --git a/tests/org/apache/xalan/xpath3/FnParseXmlFragmentTests.java b/tests/org/apache/xalan/xpath3/FnParseXmlFragmentTests.java
new file mode 100644
index 00000000..66f740e3
--- /dev/null
+++ b/tests/org/apache/xalan/xpath3/FnParseXmlFragmentTests.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.xpath3;
+
+import org.apache.xalan.util.XslTransformTestsUtil;
+import org.apache.xalan.xslt3.XSLConstants;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XPath 3.1 function fn:parse-xml-fragment test cases.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class FnParseXmlFragmentTests extends XslTransformTestsUtil {        
+    
+    private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX 
+                                                                                                          + "fn_parse_xml_fragment/";
+    
+    private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX 
+                                                                                                          + "fn_parse_xml_fragment/gold/";
+    
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        // no op
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {        
+        xmlDocumentBuilderFactory = null;
+        xmlDocumentBuilder = null;
+        xslTransformerFactory = null;
+    }
+
+    @Test
+    public void xslFnParseXmlFragmentTest1() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+
+}
diff --git a/tests/org/apache/xalan/xpath3/RangeExprTests.java b/tests/org/apache/xalan/xpath3/RangeExprTests.java
index 040b6062..3e7e01b4 100644
--- a/tests/org/apache/xalan/xpath3/RangeExprTests.java
+++ b/tests/org/apache/xalan/xpath3/RangeExprTests.java
@@ -24,7 +24,8 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
- * XSLT 3.0 test cases, for using XPath 3.1 range expressions.
+ * XSLT 3.0 test cases, for the XPath 3.1 range "to" 
+ * expression.
  * 
  * @author Mukul Gandhi <mu...@apache.org>
  * 
@@ -179,5 +180,15 @@ public class RangeExprTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslRangeExprTest14() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_d.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test14.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test14.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
index d874999c..6a31fe8c 100644
--- a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
+++ b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
@@ -29,6 +29,7 @@ import org.apache.xalan.xpath3.FnFoldRightTests;
 import org.apache.xalan.xpath3.FnForEachPairTests;
 import org.apache.xalan.xpath3.FnForEachTests;
 import org.apache.xalan.xpath3.FnIndexOfTests;
+import org.apache.xalan.xpath3.FnParseXmlFragmentTests;
 import org.apache.xalan.xpath3.FnParseXmlTests;
 import org.apache.xalan.xpath3.FnSortTests;
 import org.apache.xalan.xpath3.FnStringJoinTests;
@@ -85,7 +86,7 @@ import org.junit.runners.Suite.SuiteClasses;
                 NodeComparisonTests.class, SimpleMapOperatorTests.class, FnFoldLeftTests.class,
                 FnFoldRightTests.class, FnForEachPairTests.class, FnSortTests.class, FnCodepointsToStringTests.class,
                 FnStringToCodepointsTests.class, FnCompareTests.class, FnCodepointEqualTests.class,
-                SequenceFunctionTests.class, FnParseXmlTests.class })
+                SequenceFunctionTests.class, FnParseXmlTests.class, FnParseXmlFragmentTests.class, TemplateTests.class})
 public class AllXsl3Tests {
 
 }
diff --git a/tests/org/apache/xalan/xslt3/TemplateTests.java b/tests/org/apache/xalan/xslt3/TemplateTests.java
new file mode 100644
index 00000000..e143624c
--- /dev/null
+++ b/tests/org/apache/xalan/xslt3/TemplateTests.java
@@ -0,0 +1,60 @@
+/*
+ * 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.xslt3;
+
+import org.apache.xalan.util.XslTransformTestsUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XSLT test cases, to test xsl:template instruction.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class TemplateTests extends XslTransformTestsUtil {
+    
+    private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "xsl_template/";
+    
+    private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "xsl_template/gold/";      
+
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        // no op
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+        xmlDocumentBuilderFactory = null;
+        xmlDocumentBuilder = null;
+        xslTransformerFactory = null;
+    }
+
+    @Test
+    public void xslTemplateTest1() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.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/tests/range_expr/gold/test14.out b/tests/range_expr/gold/test14.out
new file mode 100644
index 00000000..f435eb26
--- /dev/null
+++ b/tests/range_expr/gold/test14.out
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?><alpha>
+  <a strLen="5">hello</a>
+  <a>hello</a>
+  <a>hello</a>
+  <b strLen="5">world</b>
+  <b>world</b>
+  <b>world</b>
+  <c strLen="4">this</c>
+  <c>this</c>
+  <c>this</c>
+  <d strLen="2">is</d>
+  <d>is</d>
+  <d>is</d>
+  <e strLen="22">an xml sample document</e>
+  <e>an xml sample document</e>
+  <e>an xml sample document</e>
+</alpha>
diff --git a/tests/fn_parse_xml/test1.xsl b/tests/range_expr/test14.xsl
similarity index 56%
copy from tests/fn_parse_xml/test1.xsl
copy to tests/range_expr/test14.xsl
index 9fdb6234..8d1916cb 100644
--- a/tests/fn_parse_xml/test1.xsl
+++ b/tests/range_expr/test14.xsl
@@ -1,29 +1,37 @@
 <?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 XSLT stylesheet test, for the XPath 3.1 fn:parse-xml() function.
-         The XPath function fn:parse-xml's example, as used within this
-         stylesheet is borrowed from XPath 3.1 F&O spec. -->                
+    <!-- Author: mukulg@apache.org -->                
                 
+    <!-- use with test1_d.xml -->
+    
+    <!-- An XSLT stylesheet test case, to test XPath 3.1
+         range "to" expression.
+     -->
+    
     <xsl:output method="xml" indent="yes"/>
     
-    <!-- The XML document string value, passed to fn:parse-xml 
-         function call within below mentioned xsl:variable 
-         declaration is following (with XML special characters 
-         escaped within function call fn:parse-xml's argument, 
-         according to XML conventions),
-         
-         <alpha>abcd</alpha> 
-    -->
-    <xsl:variable name="xmlDocNode" select="parse-xml('&lt;alpha&gt;abcd&lt;/alpha&gt;')"/>
+    <xsl:variable name="repetitionCount" select="3"/>
         
     <xsl:template match="/">
-       <result>
-          <xsl:copy-of select="$xmlDocNode"/>
-       </result>
+       <alpha>
+         <xsl:apply-templates select="alpha/*"/>
+       </alpha>
+    </xsl:template>
+    
+    <xsl:template match="*">
+      <xsl:variable name="elem" select="."/>
+      <xsl:for-each select="1 to $repetitionCount">
+         <xsl:element name="{name($elem)}">
+            <xsl:if test="position() = 1">
+               <xsl:attribute name="strLen" select="string-length(xs:string($elem))"/>
+            </xsl:if>
+            <xsl:copy-of select="$elem/node()"/>
+         </xsl:element>
+      </xsl:for-each>
     </xsl:template>
     
     <!--
diff --git a/tests/range_expr/test1_d.xml b/tests/range_expr/test1_d.xml
new file mode 100644
index 00000000..b9f378eb
--- /dev/null
+++ b/tests/range_expr/test1_d.xml
@@ -0,0 +1,7 @@
+<alpha>
+  <a>hello</a>
+  <b>world</b>
+  <c>this</c>
+  <d>is</d>
+  <e>an xml sample document</e>
+</alpha>
\ No newline at end of file
diff --git a/tests/xsl_template/gold/test1.out b/tests/xsl_template/gold/test1.out
new file mode 100644
index 00000000..e93fb0c3
--- /dev/null
+++ b/tests/xsl_template/gold/test1.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><alpha>
+  <a>hello</a>
+  <b>world</b>
+  <alpha pos="3">this</alpha>
+  <d>is</d>
+  <e>an xml sample document</e>
+</alpha>
diff --git a/tests/fn_parse_xml/test1.xsl b/tests/xsl_template/test1.xsl
similarity index 59%
copy from tests/fn_parse_xml/test1.xsl
copy to tests/xsl_template/test1.xsl
index 9fdb6234..936f8a38 100644
--- a/tests/fn_parse_xml/test1.xsl
+++ b/tests/xsl_template/test1.xsl
@@ -2,28 +2,33 @@
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="3.0">
                 
-    <!-- Author: mukulg@apache.org -->
-   
-    <!-- An XSLT stylesheet test, for the XPath 3.1 fn:parse-xml() function.
-         The XPath function fn:parse-xml's example, as used within this
-         stylesheet is borrowed from XPath 3.1 F&O spec. -->                
+    <!-- Author: mukulg@apache.org -->                
                 
-    <xsl:output method="xml" indent="yes"/>
+    <!-- use with test1_a.xml -->
     
-    <!-- The XML document string value, passed to fn:parse-xml 
-         function call within below mentioned xsl:variable 
-         declaration is following (with XML special characters 
-         escaped within function call fn:parse-xml's argument, 
-         according to XML conventions),
-         
-         <alpha>abcd</alpha> 
-    -->
-    <xsl:variable name="xmlDocNode" select="parse-xml('&lt;alpha&gt;abcd&lt;/alpha&gt;')"/>
+    <!-- This XSLT stylesheet test case, tests the
+         xsl:template instruction.
+    -->                
+                
+    <xsl:output method="xml" indent="yes"/>
         
     <xsl:template match="/">
-       <result>
-          <xsl:copy-of select="$xmlDocNode"/>
-       </result>
+       <alpha>
+         <xsl:apply-templates select="alpha/*"/>
+       </alpha>
+    </xsl:template>
+    
+    <xsl:template match="alpha">
+       <xsl:element name="{name()}">
+          <xsl:attribute name="pos" select="position()"/>
+          <xsl:copy-of select="node()"/>
+       </xsl:element>
+    </xsl:template>
+    
+    <xsl:template match="*">
+       <xsl:element name="{name()}">
+          <xsl:copy-of select="node()"/>
+       </xsl:element>
     </xsl:template>
     
     <!--
diff --git a/tests/xsl_template/test1_a.xml b/tests/xsl_template/test1_a.xml
new file mode 100644
index 00000000..2565dd4f
--- /dev/null
+++ b/tests/xsl_template/test1_a.xml
@@ -0,0 +1,7 @@
+<alpha>
+  <a>hello</a>
+  <b>world</b>
+  <alpha>this</alpha>
+  <d>is</d>
+  <e>an xml sample document</e>
+</alpha>
\ 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