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/10/22 12:48:08 UTC

(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing xalan-j xslt 3.0 implementation of xsl:mode instruction. this is wip

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 7120f1869 committing xalan-j xslt 3.0 implementation of xsl:mode instruction. this is wip
7120f1869 is described below

commit 7120f1869b6dd7e7061da118016095b44dd9899e
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Wed Oct 22 18:17:35 2025 +0530

    committing xalan-j xslt 3.0 implementation of xsl:mode instruction. this is wip
---
 README                                             |   6 +-
 .../xalan/processor/ProcessorTemplateElem.java     |   7 +
 .../org/apache/xalan/processor/XSLTSchema.java     |  33 +++-
 .../java/org/apache/xalan/templates/Constants.java |  13 +-
 .../apache/xalan/templates/ElemApplyTemplates.java |  31 +++-
 .../java/org/apache/xalan/templates/ElemMode.java  | 185 +++++++++++++++++++++
 .../java/org/apache/xalan/templates/ModeList.java  |  80 +++++++++
 .../org/apache/xalan/templates/Stylesheet.java     |  39 +++++
 .../org/apache/xalan/templates/StylesheetRoot.java |  93 ++++++++++-
 .../xalan/tests/main/XalanXsl3TestSuite2.java      |   3 +-
 .../xalan/tests/w3c/xslt3/W3CXSLT3Tests.java       |   4 +-
 .../w3c/xslt3/misc/XslBuiltInTemplateTests.java    |  61 +++++++
 .../misc/_built-in-templates-test-set_result.xml   |   8 +
 .../result/w3c_xslt3_testsuite_xalan-j_result.xml  |   3 +-
 .../org/apache/xalan/tests/xslt3/XslModeTests.java |  70 ++++++++
 src/test/resources/xsl_mode/gold/test1.out         |  35 ++++
 src/test/resources/xsl_mode/gold/test2.out         |  13 ++
 src/test/resources/xsl_mode/test1.xml              |  80 +++++++++
 src/test/resources/xsl_mode/test1.xsl              |  42 +++++
 src/test/resources/xsl_mode/test2.xsl              |  42 +++++
 20 files changed, 831 insertions(+), 17 deletions(-)

diff --git a/README b/README
index 94d70df61..b6e324d19 100644
--- a/README
+++ b/README
@@ -17,7 +17,7 @@
 
 Copyright 1999-2025 The Apache Software Foundation
 
-Document last modified : 2025-10-20
+Document last modified : 2025-10-22
 
 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: 1330, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: ..... - in org.apache.xalan.tests.main.AllXalanXSLT3Tests
+[INFO] Tests run: 1332, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: ..... - in org.apache.xalan.tests.main.AllXalanXSLT3Tests
 [INFO]
 [INFO] Results:
 [INFO]
-[INFO] Tests run: 1330, Failures: 0, Errors: 0, Skipped: 0
+[INFO] Tests run: 1332, Failures: 0, Errors: 0, Skipped: 0
 [INFO]
 [INFO]
 [INFO] --- jar:3.3.0:jar (default-jar) @ xalan-java ---
diff --git a/src/main/java/org/apache/xalan/processor/ProcessorTemplateElem.java b/src/main/java/org/apache/xalan/processor/ProcessorTemplateElem.java
index 6ce205913..418c11663 100644
--- a/src/main/java/org/apache/xalan/processor/ProcessorTemplateElem.java
+++ b/src/main/java/org/apache/xalan/processor/ProcessorTemplateElem.java
@@ -24,7 +24,9 @@ import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.res.XSLTErrorResources;
 import org.apache.xalan.templates.Constants;
+import org.apache.xalan.templates.ElemMode;
 import org.apache.xalan.templates.ElemTemplateElement;
+import org.apache.xalan.templates.Stylesheet;
 import org.xml.sax.Attributes;
 
 /**
@@ -135,6 +137,11 @@ public class ProcessorTemplateElem extends XSLTElementProcessor
     {
       parent.appendChild(elem);
       handler.pushElemTemplateElement(elem);
+      
+      if (elem instanceof ElemMode) {
+    	 Stylesheet stylesheet = (Stylesheet)parent;
+    	 stylesheet.setElemMode((ElemMode)elem);
+      }
     }
   }
 
diff --git a/src/main/java/org/apache/xalan/processor/XSLTSchema.java b/src/main/java/org/apache/xalan/processor/XSLTSchema.java
index b9dc3806f..7210a07c3 100644
--- a/src/main/java/org/apache/xalan/processor/XSLTSchema.java
+++ b/src/main/java/org/apache/xalan/processor/XSLTSchema.java
@@ -57,6 +57,7 @@ import org.apache.xalan.templates.ElemMergeAction;
 import org.apache.xalan.templates.ElemMergeKey;
 import org.apache.xalan.templates.ElemMergeSource;
 import org.apache.xalan.templates.ElemMessage;
+import org.apache.xalan.templates.ElemMode;
 import org.apache.xalan.templates.ElemNonMatchingSubstring;
 import org.apache.xalan.templates.ElemNumber;
 import org.apache.xalan.templates.ElemOtherwise;
@@ -203,7 +204,7 @@ public class XSLTSchema extends XSLTElementDef
                                         
     // Optional
     // Static error if invalid
-    // xsl:template, xsl:decimal-format                                      
+    // xsl:template, xsl:decimal-format, xsl:mode                                      
     XSLTAttributeDef nameAttrOpt_ERROR = new XSLTAttributeDef(null, "name",
                                      XSLTAttributeDef.T_QNAME, false, false, XSLTAttributeDef.ERROR);
     
@@ -217,6 +218,21 @@ public class XSLTSchema extends XSLTElementDef
     XSLTAttributeDef sortBeforeMergeAttrOpt = new XSLTAttributeDef(null, "sort-before-merge",
                                      XSLTAttributeDef.T_YESNO, false, false, XSLTAttributeDef.WARNING);
     
+    // Optional
+    // xsl:mode
+    XSLTAttributeDef onNoMatchOpt = new XSLTAttributeDef(null, "on-no-match",
+                                     XSLTAttributeDef.T_STRING, false, false, XSLTAttributeDef.ERROR);
+    
+    // Optional
+    // xsl:mode
+    XSLTAttributeDef onMultipleMatchOpt = new XSLTAttributeDef(null, "on-multiple-match",
+                                     XSLTAttributeDef.T_STRING, false, false, XSLTAttributeDef.ERROR);
+    
+    // Optional
+    // xsl:mode
+    XSLTAttributeDef warningOnMultipleMatchOpt = new XSLTAttributeDef(null, "warning-on-multiple-match",
+                                     XSLTAttributeDef.T_STRING, false, false, XSLTAttributeDef.ERROR);
+    
     // Optional
     // xsl:param                                      
     XSLTAttributeDef requiredAttrOpt = new XSLTAttributeDef(null, "required",
@@ -1230,7 +1246,20 @@ public class XSLTSchema extends XSLTElementDef
                                                    nameAttrRequired,
                                                    selectAttrOpt, asAttrOpt, requiredAttrOpt }, 
                                            new ProcessorGlobalParamDecl(),
-                                           ElemParam.class /* class object */, 20, true),
+                                           ElemParam.class /* class object */, 20, true),                                  
+                                  new XSLTElementDef(
+                                          this,
+                                          Constants.S_XSLNAMESPACEURL,
+                                          "mode",
+                                          null /*alias */,
+                                          null /* elements */,
+                                          new XSLTAttributeDef[]{
+                                                  nameAttrOpt_ERROR,
+                                                  onNoMatchOpt,
+                                                  onMultipleMatchOpt,
+                                                  warningOnMultipleMatchOpt,
+                                                  spaceAttr }, 
+                                          new ProcessorTemplateElem(), ElemMode.class /* class object */, true, 20, true),
                                   new XSLTElementDef(
                                            this,
                                            Constants.S_XSLNAMESPACEURL,
diff --git a/src/main/java/org/apache/xalan/templates/Constants.java b/src/main/java/org/apache/xalan/templates/Constants.java
index fc145d0a4..cebe7e55e 100644
--- a/src/main/java/org/apache/xalan/templates/Constants.java
+++ b/src/main/java/org/apache/xalan/templates/Constants.java
@@ -137,9 +137,11 @@ public class Constants extends org.apache.xml.utils.Constants
   
   ELEMNAME_CONTEXT_ITEM = 113,
   
-  ELEMNAME_DOCUMENT = 114;
+  ELEMNAME_DOCUMENT = 114,
   
-  // next available number : 115
+  ELEMNAME_MODE = 115;
+  
+  // next available number : 116
 
   /**
    * Literals for XSL element names. Note that there are more
@@ -222,6 +224,13 @@ public class Constants extends org.apache.xml.utils.Constants
       ELEMNAME_TARGETPI_STRING = "target-pi",
       ELEMNAME_TARGETTEXT_STRING = "target-text",
       ELEMNAME_TEMPLATE_STRING = "template",
+      
+      ELEMNAME_MODE_STRING = "mode",
+      
+      ELEMNAME_DEEP_COPY_STRING = "deep-copy",
+      ELEMNAME_SHALLOW_COPY_STRING = "shallow-copy",
+      ELEMNAME_DEEP_SKIP_STRING = "deep-skip",
+      
       ELEMNAME_TEXT_STRING = "text",
       ELEMNAME_TRANSFORM_STRING = "transform",
       ELEMNAME_URL_STRING = "uri",  // pattern-by-example support
diff --git a/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java b/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java
index e980fb3ff..17962bc44 100644
--- a/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java
+++ b/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java
@@ -582,11 +582,32 @@ public class ElemApplyTemplates extends ElemCallTemplate
 			  // If that didn't locate a node, fall back to a default template rule
 			  if (template == null)
 			  {
+				  ElemMode elemMode = sroot.getElemMode(mode);
+				  
 				  switch (nodeType)
 				  {
 				  case DTM.DOCUMENT_FRAGMENT_NODE :
 				  case DTM.ELEMENT_NODE :
-					  template = sroot.getDefaultRule();
+					  if (elemMode != null) {
+						  String onNoMatchStr = elemMode.getOnNoMatch();
+						  if ((Constants.ELEMNAME_DEEP_COPY_STRING).equals(onNoMatchStr)) {
+							 template = sroot.getDeepCopyRule(elemMode.getName());
+						  }
+						  else if ((Constants.ELEMNAME_SHALLOW_COPY_STRING).equals(onNoMatchStr)) {
+							 template = sroot.getShallowCopyRule(elemMode.getName());
+						  }
+                          else if ((Constants.ELEMNAME_DEEP_SKIP_STRING).equals(onNoMatchStr)) {
+                        	 template = sroot.getDeepSkipRule(elemMode.getName());
+						  }
+						  
+						  if (template == null) {
+							 // REVISIT
+							 template = sroot.getDefaultRule(); 
+						  }
+					  }
+					  else {
+					     template = sroot.getDefaultRule();
+					  }
 					  break;
 				  case DTM.ATTRIBUTE_NODE :
 				  case DTM.CDATA_SECTION_NODE :
@@ -696,9 +717,11 @@ public class ElemApplyTemplates extends ElemCallTemplate
 
 			  if (templateAsAttrVal != null) {         
 				  try {
-					  // Check whether an xsl:template element's result contents conform to the 
-					  // SequenceType expression specified as value of xsl:template element's 
-					  // 'as' attribute.
+					  /**
+					   * Check whether an xsl:template element's result contents conform to the
+					   * SequenceType expression specified as value of xsl:template element's
+					   * 'as' attribute.
+					   */
 
 					  int dtmNodeHandle = transformer.transformToGlobalRTF(template);
 
diff --git a/src/main/java/org/apache/xalan/templates/ElemMode.java b/src/main/java/org/apache/xalan/templates/ElemMode.java
new file mode 100644
index 000000000..939046cf9
--- /dev/null
+++ b/src/main/java/org/apache/xalan/templates/ElemMode.java
@@ -0,0 +1,185 @@
+/*
+ * 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.templates;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xml.utils.QName;
+
+/**
+ * A class definition, supporting an implementation of 
+ * XSLT 3.0 xsl:mode instruction.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class ElemMode extends ElemTemplateElement
+{
+  
+  private static final long serialVersionUID = 5605801317717210156L;
+
+  /**
+   * The owning stylesheet.
+   */
+  private Stylesheet m_stylesheet;
+
+  /**
+   * Get the stylesheet composed (resolves includes and
+   * imports and has methods on it that return "composed" properties.
+   * 
+   * @return The stylesheet composed.
+   */
+  public StylesheetComposed getStylesheetComposed()
+  {
+	  return m_stylesheet.getStylesheetComposed();
+  }
+
+  /**
+   * Get the owning stylesheet.
+   *
+   * @return The owning stylesheet.
+   */
+  public Stylesheet getStylesheet()
+  {
+	  return m_stylesheet;
+  }
+
+  /**
+   * Set the owning stylesheet.
+   *
+   * @param stylesheet The owning stylesheet for this element
+   */
+  public void setStylesheet(Stylesheet stylesheet)
+  {
+	  m_stylesheet = stylesheet;
+  }
+
+  /**
+   * Get the root stylesheet.
+   *
+   * @return The root stylesheet for this element
+   */
+  public StylesheetRoot getStylesheetRoot()
+  {
+	  return m_stylesheet.getStylesheetRoot();
+  }
+
+  /**
+   * An xsl:mode element's 'name' attribute.
+   */
+  private QName m_name = null;
+  
+  /**
+   * An xsl:mode element's 'on-no-match' attribute.
+   */
+  private String m_onNoMatch = null;
+
+  /**
+   * Set the "name" attribute.
+   *
+   * @param qname Value to set the "name" attribute
+   */
+  public void setName(QName qname)
+  {
+	  m_name = qname;
+  }
+
+  /**
+   * Get the "name" attribute.
+   *
+   * @return Value of the "name" attribute
+   */
+  public QName getName()
+  {
+	  return m_name;
+  }
+  
+  /**
+   * Set the "on-no-match" attribute.
+   *
+   * @param onNoMatch Value to set the "on-no-match" attribute
+   */
+  public void setOnNoMatch(String onNoMatch)
+  {
+	  m_onNoMatch = onNoMatch;
+  }
+  
+  /**
+   * Get the "on-no-match" attribute.
+   *
+   * @return Value of the "on-no-match" attribute
+   */
+  public String getOnNoMatch()
+  {
+	  return m_onNoMatch;
+  }
+  
+  /**
+   * Get an int constant identifying the type of element.
+   * @see org.apache.xalan.templates.Constants
+   *
+   * @return The token ID for the element
+   */
+  public int getXSLToken()
+  {
+	  return Constants.ELEMNAME_MODE;
+  }
+
+  /**
+   * Return the node name.
+   *
+   * @return The element's name
+   */
+  public String getNodeName()
+  {
+	  return Constants.ELEMNAME_MODE_STRING;
+  }
+  
+  /**
+   * This function is called after everything else has been
+   * recomposed, and allows the template to set remaining
+   * values that may be based on some other property that
+   * depends on recomposition.
+   */
+  public void compose(StylesheetRoot sroot) throws TransformerException
+  {
+	  super.compose(sroot);
+  }
+  
+  /**
+   * This method is called after the template's children have been composed.
+   */
+  public void endCompose(StylesheetRoot sroot) throws TransformerException
+  {
+	  super.endCompose(sroot);
+  }
+
+  /**
+   * A placeholder method definition, that doesn't do evaluation.
+   *
+   * @param transformer non-null reference to the the current transform-time state.
+   *
+   * @throws TransformerException
+   */
+  public void execute(TransformerImpl transformer) throws TransformerException {    
+	  // NO OP    
+  }
+
+}
diff --git a/src/main/java/org/apache/xalan/templates/ModeList.java b/src/main/java/org/apache/xalan/templates/ModeList.java
new file mode 100644
index 000000000..34ed00bb6
--- /dev/null
+++ b/src/main/java/org/apache/xalan/templates/ModeList.java
@@ -0,0 +1,80 @@
+/*
+ * 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.templates;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.xml.utils.QName;
+
+/**
+ * A class definition, to encapsulate an XSL mode list indentified 
+ * by xsl:mode instruction(s), and helps locate individual mode 
+ * declarations.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class ModeList implements java.io.Serializable
+{
+
+  private static final long serialVersionUID = -6677705125375244140L;
+
+  /**
+   * Construct a ModeList object. Needs to be public so it can
+   * be invoked from the CompilingStylesheetHandler.
+   */
+  public ModeList()
+  {
+    super();
+  }
+  
+  /**
+   * A java.util.Map object, containing xsl:mode declarations 
+   * keyed by their names.
+   * 
+   * REVISIT : To handle xsl:mode declarations, that don't 
+   *           have an attribute 'name'.
+   */
+  private Map<QName, ElemMode> m_elem_mode_map = new HashMap<QName, ElemMode>();
+
+  /**
+   * Add a mode to the table of mode declarations.
+   *
+   * @param ElemMode				An ElemMode object instance
+   */
+  public void setElemMode(ElemMode elemMode)
+  {    	      
+	  m_elem_mode_map.put(elemMode.getName(), elemMode);
+  }
+
+  /**
+   * Locate a mode declaration.
+   *
+   * @param qname             Qualified name of the mode
+   *
+   * @return 	              An xsl:mode definition object instance, or null 
+   *                          if not found.
+   */
+  public ElemMode getElemMode(QName qname)
+  {
+	  return m_elem_mode_map.get(qname);
+  }
+
+}
diff --git a/src/main/java/org/apache/xalan/templates/Stylesheet.java b/src/main/java/org/apache/xalan/templates/Stylesheet.java
index d8570bfef..1da893b29 100644
--- a/src/main/java/org/apache/xalan/templates/Stylesheet.java
+++ b/src/main/java/org/apache/xalan/templates/Stylesheet.java
@@ -1081,6 +1081,45 @@ public class Stylesheet extends ElemTemplateElement implements java.io.Serializa
 	{
 		return (m_character_maps != null) ? m_character_maps.size() : 0;
 	}
+	
+	/**
+	 * A class object instance, supporting an implementation
+	 * of xsl:mode instruction. 
+	 */
+	private ModeList m_modeList;
+	
+	/**
+	 * Set an "xsl:mode" property.
+	 *
+	 * @param elemMode ElemMode to add to list of modes
+	 */
+	public void setElemMode(ElemMode elemMode)
+	{
+		if (m_modeList == null)
+			m_modeList = new ModeList();
+
+		m_modeList.setElemMode(elemMode);
+		elemMode.setStylesheet(this);
+	}
+	
+	/**
+	 * Get an "xsl:mode" property.
+	 *
+	 * @param modeName         name of the mode
+	 *
+	 * @return                 ElemMode object instance
+	 *
+	 * @throws TransformerException
+	 */
+	public ElemMode getElemMode(QName modeName) {
+		ElemMode result = null;
+		
+		if (m_modeList != null) {
+		   result = m_modeList.getElemMode(modeName);
+		}
+		
+		return result;
+	}
 
 	/**
 	 * The "xsl:namespace-alias" properties.
diff --git a/src/main/java/org/apache/xalan/templates/StylesheetRoot.java b/src/main/java/org/apache/xalan/templates/StylesheetRoot.java
index b770117b7..9bbc9b9dc 100644
--- a/src/main/java/org/apache/xalan/templates/StylesheetRoot.java
+++ b/src/main/java/org/apache/xalan/templates/StylesheetRoot.java
@@ -127,7 +127,9 @@ public class StylesheetRoot extends StylesheetComposed
     /**
      * An XSL transformation initial template name.
      */
-    private String m_init_template_name = null; 
+    private String m_init_template_name = null;
+    
+    private ErrorListener m_errorListener;
     
   /**
    * Uses an XSL stylesheet document.
@@ -142,6 +144,7 @@ public class StylesheetRoot extends StylesheetComposed
 
     try
     {
+      m_errorListener = errorListener; 
       m_selectDefault = new XPath("node()", this, this, XPath.SELECT, errorListener);
 
       initDefaultRule(errorListener);
@@ -1096,6 +1099,90 @@ public class StylesheetRoot extends StylesheetComposed
   {
     return m_defaultRule;
   }
+  
+  /**
+   * Method definition, to get an XSL deep copy rule for xdm element nodes.
+   * 
+   * @param mode								An XSL template mode value
+   * @return                                    An xsl:template declaration
+   *                                            object for an XSL stylesheet rule.
+   * @throws TransformerException
+   */
+  public ElemTemplate getDeepCopyRule(QName mode) throws TransformerException
+  {		  
+	  ElemTemplate elemTemplate = new ElemTemplate();
+	  
+	  elemTemplate.setMode(mode);
+	  
+	  XPath xpathMatch = new XPath("*", this, this, XPath.MATCH, m_errorListener);
+	  elemTemplate.setMatch(xpathMatch);	  	  
+	  elemTemplate.setStylesheet(this);
+	  
+	  ElemCopyOf elemCopyOf = new ElemCopyOf();
+	  XPath xpathSelect = new XPath(".", this, this, XPath.SELECT, m_errorListener);
+	  elemCopyOf.setSelect(xpathSelect);
+	  
+	  elemTemplate.appendChild(elemCopyOf);
+	  
+	  return elemTemplate;
+  }
+  
+  /**
+   * Method definition, to get an XSL shallow copy rule for xdm nodes.
+   * 
+   * @param mode								An XSL template mode value
+   * @return                                    An xsl:template declaration
+   *                                            object for an XSL stylesheet rule.
+   * @throws TransformerException
+   */
+  public ElemTemplate getShallowCopyRule(QName mode) throws TransformerException
+  {	  
+	  ElemTemplate elemTemplate = new ElemTemplate();
+	  
+	  elemTemplate.setMode(mode);
+	  
+	  XPath xpathMatch = new XPath("@* | node()", this, this, XPath.MATCH, m_errorListener);
+	  elemTemplate.setMatch(xpathMatch);	  
+	  
+	  ElemCopy elemCopy = new ElemCopy();
+	  
+	  ElemApplyTemplates elemApplyTemplates = new ElemApplyTemplates();
+	  elemApplyTemplates.setMode(mode);
+	  XPath xpathSelect = new XPath("@*", this, this, XPath.SELECT, m_errorListener);
+	  elemApplyTemplates.setSelect(xpathSelect);
+	  elemCopy.appendChild(elemApplyTemplates);
+
+	  elemApplyTemplates = new ElemApplyTemplates();
+	  elemApplyTemplates.setMode(mode);
+	  xpathSelect = new XPath("node()", this, this, XPath.SELECT, m_errorListener);
+	  elemApplyTemplates.setSelect(xpathSelect);
+	  elemCopy.appendChild(elemApplyTemplates);
+	  
+	  elemTemplate.appendChild(elemCopy);
+
+	  return elemTemplate;
+  }
+  
+  /**
+   * Method definition, to get an XSL deep skip rule for xdm element nodes.
+   * 
+   * @param mode								An XSL template mode value
+   * @return                                    An xsl:template declaration
+   *                                            object for an XSL stylesheet rule.
+   * @throws TransformerException
+   */
+  public ElemTemplate getDeepSkipRule(QName mode) throws TransformerException
+  {	  
+	  ElemTemplate elemTemplate = new ElemTemplate();
+	  
+	  elemTemplate.setMode(mode);
+	  
+	  XPath xpathMatch = new XPath("*", this, this, XPath.MATCH, m_errorListener);
+	  elemTemplate.setStylesheet(this);	    
+	  elemTemplate.setMatch(xpathMatch);
+
+	  return elemTemplate;
+  }
 
   /**
    * The default template to use for the root if we don't find
@@ -1168,8 +1255,8 @@ public class StylesheetRoot extends StylesheetComposed
     childrenElement.setSelect(m_selectDefault);
     m_defaultRule.appendChild(childrenElement);
     
-    m_startRule = m_defaultRule;
-
+    m_startRule = m_defaultRule;               
+    
     // -----------------------------
     m_defaultTextRule = new ElemTemplate();
 
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 0083b25a9..138f809a4 100644
--- a/src/test/java/org/apache/xalan/tests/main/XalanXsl3TestSuite2.java
+++ b/src/test/java/org/apache/xalan/tests/main/XalanXsl3TestSuite2.java
@@ -97,6 +97,7 @@ import org.apache.xalan.tests.xslt3.XslIterateTests;
 import org.apache.xalan.tests.xslt3.XslJsonValidationTests;
 import org.apache.xalan.tests.xslt3.XslMergeTests;
 import org.apache.xalan.tests.xslt3.XslMethodOutputJsonTests;
+import org.apache.xalan.tests.xslt3.XslModeTests;
 import org.apache.xalan.tests.xslt3.XslResultDocumentTests;
 import org.apache.xalan.tests.xslt3.XslRtfMigrationTests;
 import org.apache.xalan.tests.xslt3.XslSequenceInstTests;
@@ -147,7 +148,7 @@ import org.junit.runners.Suite.SuiteClasses;
                 XslIncludeMiscTests.class, FnNormalizeUnicodeTests.class, XslExpandTextTests.class,
                 XslJsonValidationTests.class, XPathUriQualifiedNameTests.class, FnRoundHalfToEvenTests.class,
                 XPathPartialFuncApplnTests.class, XslCopyTests.class, XalanJavascriptExtensionTests.class, XalanJavaExtensionTests.class,
-                XPathTextAndNodePattern.class, XPathLiteralSequenceTests.class })
+                XPathTextAndNodePattern.class, XPathLiteralSequenceTests.class, XslModeTests.class })
 public class XalanXsl3TestSuite2 {
 
 }
diff --git a/src/test/java/org/apache/xalan/tests/w3c/xslt3/W3CXSLT3Tests.java b/src/test/java/org/apache/xalan/tests/w3c/xslt3/W3CXSLT3Tests.java
index 66884d4bf..b922f7c4a 100644
--- a/src/test/java/org/apache/xalan/tests/w3c/xslt3/W3CXSLT3Tests.java
+++ b/src/test/java/org/apache/xalan/tests/w3c/xslt3/W3CXSLT3Tests.java
@@ -54,6 +54,7 @@ import org.apache.xalan.tests.w3c.xslt3.insn.XslIterateTests;
 import org.apache.xalan.tests.w3c.xslt3.insn.XslSequenceTests;
 import org.apache.xalan.tests.w3c.xslt3.insn.XslSortTests;
 import org.apache.xalan.tests.w3c.xslt3.insn.XslTryTests;
+import org.apache.xalan.tests.w3c.xslt3.misc.XslBuiltInTemplateTests;
 import org.apache.xalan.tests.w3c.xslt3.misc.XslMiscRegexTests;
 import org.apache.xalan.tests.w3c.xslt3.type.XslBooleanTests;
 import org.apache.xalan.tests.w3c.xslt3.type.XslDateTests;
@@ -80,7 +81,8 @@ import org.junit.runners.Suite.SuiteClasses;
 	            XslNodeTestTests.class, XslPathTests.class, XslPredicateTests.class, XslAttributeTests.class, XslCallTemplateTests.class, 
 	            XslNodeTests.class, XslStringTests.class, XslDateTests.class, XslFnDeepEqualTests.class, XslFnPositionTests.class, 
 	            XslAnalyzeStringTests.class, XslFnRootTests.class, XslFnKeyTests.class, XslFnFormatNumberTests.class, XslMiscRegexTests.class,
-	            XslDocumentTests.class, XslXPathDefaultNamespaceAttrTests.class, XslExpandTextAttrTests.class, XslFnJsonToXmlTests.class })
+	            XslDocumentTests.class, XslXPathDefaultNamespaceAttrTests.class, XslExpandTextAttrTests.class, XslFnJsonToXmlTests.class,
+	            XslBuiltInTemplateTests.class })
 public class W3CXSLT3Tests {
 
 }
diff --git a/src/test/java/org/apache/xalan/tests/w3c/xslt3/misc/XslBuiltInTemplateTests.java b/src/test/java/org/apache/xalan/tests/w3c/xslt3/misc/XslBuiltInTemplateTests.java
new file mode 100644
index 000000000..ec43d500b
--- /dev/null
+++ b/src/test/java/org/apache/xalan/tests/w3c/xslt3/misc/XslBuiltInTemplateTests.java
@@ -0,0 +1,61 @@
+/*
+ * 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.w3c.xslt3.misc;
+
+import org.apache.xalan.tests.w3c.xslt3.W3CXslTransformTestsUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Xalan-J XSL 3 test driver, to run W3C XSL 3.0 transformation 
+ * tests for XSLT built-in templates.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class XslBuiltInTemplateTests extends W3CXslTransformTestsUtil {
+	
+	/**
+	 * Xalan may probably have bugs for this W3C XSLT 3.0 test set.
+	 * Adding this XSLT 3.0 test set to Xalan's XSLT 3.0 test suite 
+	 * driver, for tracking.
+	 * 
+	 * REVISIT
+	 */
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+    	m_xslTransformTestSetFilePath = W3C_XSLT3_TESTS_META_DATA_DIR_HOME + "misc/built-in-templates/_built-in-templates-test-set.xml";
+    	m_resultSubFolderName = "misc";
+    	m_testResultFileName = "_built-in-templates-test-set_result.xml";
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+        m_xmlDocumentBuilderFactory = null;
+        m_xmlDocumentBuilder = null;
+        m_xslTransformerFactory = null;
+    }
+
+    @Test
+    public void runXslBuiltInTemplateTests() {    	
+       runXslTestSet();
+    }
+
+}
diff --git a/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/misc/_built-in-templates-test-set_result.xml b/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/misc/_built-in-templates-test-set_result.xml
new file mode 100644
index 000000000..e00a4dc63
--- /dev/null
+++ b/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/misc/_built-in-templates-test-set_result.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><testrun dateTime="2025-10-22T12:42:17Z" fail="2" name="built-in-templates" pass="4" skipped="0" statusUnknown="0" totalRun="6">
+   <testResult status="pass" testName="built-in-templates-0101"/>
+   <testResult status="pass" testName="built-in-templates-0102"/>
+   <testResult status="fail" testName="built-in-templates-0201"/>
+   <testResult status="fail" testName="built-in-templates-0202"/>
+   <testResult status="pass" testName="built-in-templates-0301"/>
+   <testResult status="pass" testName="built-in-templates-0302"/>
+</testrun>
diff --git a/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/w3c_xslt3_testsuite_xalan-j_result.xml b/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/w3c_xslt3_testsuite_xalan-j_result.xml
index 90cce8299..f4204be6d 100644
--- a/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/w3c_xslt3_testsuite_xalan-j_result.xml
+++ b/src/test/java/org/apache/xalan/tests/w3c/xslt3/result/w3c_xslt3_testsuite_xalan-j_result.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<testResult dateTime="2025-10-21T11:44:30Z" desc="W3C XSLT 3.0 test suite results" fail="669" pass="1772" skipped="73" success="72.15%" totalRun="2456" xslt_processor="Xalan-J XSLT 3.0 development code">
+<testResult dateTime="2025-10-22T12:42:34Z" desc="W3C XSLT 3.0 test suite results" fail="671" pass="1776" skipped="73" success="72.14%" totalRun="2462" xslt_processor="Xalan-J XSLT 3.0 development code">
   <attr>
     <as fail="31" pass="73" skipped="4" success="69.52%" totalRun="105"/>
     <avt fail="15" pass="20" skipped="0" success="57.14%" totalRun="35"/>
@@ -49,6 +49,7 @@
     <xsl-document fail="13" pass="12" skipped="0" success="48.0%" totalRun="25"/>
   </insn>
   <misc>
+    <built-in-templates fail="2" pass="4" skipped="0" success="66.67%" totalRun="6"/>
     <regex fail="12" pass="32" skipped="1" success="72.73%" totalRun="44"/>
   </misc>
   <type>
diff --git a/src/test/java/org/apache/xalan/tests/xslt3/XslModeTests.java b/src/test/java/org/apache/xalan/tests/xslt3/XslModeTests.java
new file mode 100644
index 000000000..40a7b620d
--- /dev/null
+++ b/src/test/java/org/apache/xalan/tests/xslt3/XslModeTests.java
@@ -0,0 +1,70 @@
+/*
+ * 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 xsl:mode instruction.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class XslModeTests extends XslTransformTestsUtil {        
+    
+    private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLTestConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "xsl_mode/";
+    
+    private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLTestConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "xsl_mode/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 xslModeTest1() {
+        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);
+    }
+    
+    @Test
+    public void xslModeTest2() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+
+}
diff --git a/src/test/resources/xsl_mode/gold/test1.out b/src/test/resources/xsl_mode/gold/test1.out
new file mode 100644
index 000000000..394e30f14
--- /dev/null
+++ b/src/test/resources/xsl_mode/gold/test1.out
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <a>
+     <one>
+	    <x>1</x>
+	 </one>
+	 <two>
+	    <y>2</y>
+	 </two>
+	 <three>
+	    <z>3</z>
+	 </three>
+   </a>
+  <b>
+     <one>
+	    <x>4</x>
+	 </one>
+	 <two>
+	    <y>5</y>
+	 </two>
+	 <three>
+	    <z>6</z>
+	 </three>
+   </b>
+  <c>
+     <one>
+	    <x>7</x>
+	 </one>
+	 <two>
+	    <y>8</y>
+	 </two>
+	 <three>
+	    <z>9</z>
+	 </three>
+   </c>
+</result>
diff --git a/src/test/resources/xsl_mode/gold/test2.out b/src/test/resources/xsl_mode/gold/test2.out
new file mode 100644
index 000000000..01327345e
--- /dev/null
+++ b/src/test/resources/xsl_mode/gold/test2.out
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <a>
+     <one>
+	    <x>1</x>
+	 </one>
+	 <two>
+	    <y>2</y>
+	 </two>
+	 <three>
+	    <z>3</z>
+	 </three>
+   </a>
+</result>
diff --git a/src/test/resources/xsl_mode/test1.xml b/src/test/resources/xsl_mode/test1.xml
new file mode 100644
index 000000000..df2a22111
--- /dev/null
+++ b/src/test/resources/xsl_mode/test1.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<info>
+   <a>
+     <one>
+	    <x>1</x>
+	 </one>
+	 <two>
+	    <y>2</y>
+	 </two>
+	 <three>
+	    <z>3</z>
+	 </three>
+   </a>
+   <b>
+     <one>
+	    <x>4</x>
+	 </one>
+	 <two>
+	    <y>5</y>
+	 </two>
+	 <three>
+	    <z>6</z>
+	 </three>
+   </b>
+   <c>
+     <one>
+	    <x>7</x>
+	 </one>
+	 <two>
+	    <y>8</y>
+	 </two>
+	 <three>
+	    <z>9</z>
+	 </three>
+   </c>
+   <d>
+     <one>
+	    <x>10</x>
+	 </one>
+	 <two>
+	    <y>11</y>
+	 </two>
+	 <three>
+	    <z>12</z>
+	 </three>
+   </d>
+   <e>
+      <one>
+	    <x>13</x>
+	 </one>
+	 <two>
+	    <y>14</y>
+	 </two>
+	 <three>
+	    <z>15</z>
+	 </three>
+   </e>
+   <f>
+      <one>
+	    <x>16</x>
+	 </one>
+	 <two>
+	    <y>17</y>
+	 </two>
+	 <three>
+	    <z>18</z>
+	 </three>
+   </f>   
+   <g>
+      <one>
+	    <x>19</x>
+	 </one>
+	 <two>
+	    <y>20</y>
+	 </two>
+	 <three>
+	    <z>21</z>
+	 </three>
+   </g>
+</info>
diff --git a/src/test/resources/xsl_mode/test1.xsl b/src/test/resources/xsl_mode/test1.xsl
new file mode 100644
index 000000000..9ee8accea
--- /dev/null
+++ b/src/test/resources/xsl_mode/test1.xsl
@@ -0,0 +1,42 @@
+<?xml version="1.0"?> 
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+                version="3.0">
+                
+   <!-- Author: mukulg@apache.org -->
+   
+   <!-- use with test1.xml -->
+   
+   <!-- XSL 3 stylesheet test case, to test xsl:mode instruction. -->                
+
+   <xsl:output method="xml" indent="yes"/>
+   
+   <xsl:mode name="m1" on-no-match="deep-copy"/>
+   
+   <xsl:mode name="m2" on-no-match="deep-skip"/>
+   
+   <xsl:template match="info">
+      <result>
+	     <xsl:apply-templates select="a | b | c" mode="m1"/>
+		 <xsl:apply-templates select="d | e | f | g" mode="m2"/>
+	  </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/src/test/resources/xsl_mode/test2.xsl b/src/test/resources/xsl_mode/test2.xsl
new file mode 100644
index 000000000..f2924b16d
--- /dev/null
+++ b/src/test/resources/xsl_mode/test2.xsl
@@ -0,0 +1,42 @@
+<?xml version="1.0"?> 
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+                version="3.0">
+                
+   <!-- Author: mukulg@apache.org -->
+   
+   <!-- use with test1.xml -->
+   
+   <!-- XSL 3 stylesheet test case, to test xsl:mode instruction. -->                
+
+   <xsl:output method="xml" indent="yes"/>
+   
+   <xsl:mode name="m1" on-no-match="shallow-copy"/>
+   
+   <xsl:mode name="m2" on-no-match="deep-skip"/>
+   
+   <xsl:template match="info">
+      <result>
+	     <xsl:apply-templates select="a" mode="m1"/>
+		 <xsl:apply-templates select="b | c | d | e | f | g" mode="m2"/>
+	  </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


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