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/07/20 16:41:19 UTC

(xalan-java) branch xalan-j_xslt3.0 updated: improving xsl:sequence and xsl:function instruction implementations, along with a related working test case

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 74e5f5a1f improving xsl:sequence and xsl:function instruction implementations, along with a related working test case
74e5f5a1f is described below

commit 74e5f5a1f363ad61eeee29a96a4f33e3331281d9
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Jul 20 22:11:03 2024 +0530

    improving xsl:sequence and xsl:function instruction implementations, along with a related working test case
---
 src/org/apache/xalan/templates/ElemFunction.java   |  53 ++++++--
 src/org/apache/xalan/templates/ElemSequence.java   | 103 ++++++++-------
 .../apache/xalan/transformer/TransformerImpl.java  | 141 ++++++++++++++++++++-
 .../xslt/util/XslTransformSharedDatastore.java     |  10 +-
 src/org/apache/xpath/compiler/XPathParser.java     |   3 +-
 tests/org/apache/xalan/xslt3/XslFunctionTests.java |  10 ++
 tests/xsl_function/gold/test18.out                 |   4 +
 tests/xsl_function/test17.xsl                      |   6 +-
 tests/xsl_function/test18.xsl                      |  64 ++++++++++
 9 files changed, 325 insertions(+), 69 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemFunction.java b/src/org/apache/xalan/templates/ElemFunction.java
index a37e4e761..e90b67356 100644
--- a/src/org/apache/xalan/templates/ElemFunction.java
+++ b/src/org/apache/xalan/templates/ElemFunction.java
@@ -27,6 +27,7 @@ import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.transformer.TransformerImpl;
 import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
+import org.apache.xalan.xslt.util.XslTransformSharedDatastore;
 import org.apache.xml.dtm.ref.DTMNodeList;
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xml.utils.QName;
@@ -39,6 +40,7 @@ import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNodeSetForDOM;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XPathInlineFunction;
 import org.apache.xpath.objects.XRTreeFrag;
 import org.apache.xpath.types.XSByte;
 import org.apache.xpath.types.XSNegativeInteger;
@@ -274,18 +276,36 @@ public class ElemFunction extends ElemTemplate
       
       if (funcAsAttrStrVal != null) {
     	 // Process xsl:function's evaluation result with "as" attribute
-         try {
-            funcResultConvertedVal = preprocessXslFunctionOrAVariableResult(result, funcAsAttrStrVal, xctxt, null);
+         try {        	 
+             if (funcResultConvertedVal instanceof XPathInlineFunction) {
+            	// The xsl:function's evaluation returned a function item. The 
+            	// value of xsl:function's "as" attribute if present, needs to 
+            	// match accordingly.
+            	XPath seqTypeXPath = new XPath(funcAsAttrStrVal, srcLocator, xctxt.getNamespaceContext(), 
+                                                                         XPath.SELECT, null, true);
+                XObject seqTypeExpressionEvalResult = seqTypeXPath.execute(xctxt, xctxt.getContextNode(), xctxt.getNamespaceContext());
+                SequenceTypeData seqExpectedTypeData = (SequenceTypeData)seqTypeExpressionEvalResult;
+            	if (seqExpectedTypeData.getSequenceTypeFunctionTest() != null) {
+            	   return funcResultConvertedVal;
+            	}
+            	else {
+            	   throw new TransformerException("XPTY0004 : The function call result for function {" + funcNameSpaceUri + "}" + funcLocalName + 
+                                                                         "(), doesn't match the declared function result type " + 
+                                                                         funcAsAttrStrVal + ".", srcLocator); 
+            	}
+             }
+             
+             funcResultConvertedVal = preprocessXslFunctionOrAVariableResult(result, funcAsAttrStrVal, xctxt, null);
             
-            if (funcResultConvertedVal == null) {
+             if (funcResultConvertedVal == null) {
                 funcResultConvertedVal = SequenceTypeSupport.convertXdmValueToAnotherType(result, funcAsAttrStrVal, null, xctxt);
                 
                 if (funcResultConvertedVal == null) {
                    throw new TransformerException("XPTY0004 : The function call result for function {" + funcNameSpaceUri + "}" + funcLocalName + 
                                                                                     "(), doesn't match the declared function result type " + 
-                                                                                                                                  funcAsAttrStrVal + ".", srcLocator);   
+                                                                                                                 funcAsAttrStrVal + ".", srcLocator);   
                 }
-            }
+             }
          }
          catch (TransformerException ex) {
             throw new TransformerException(ex.getMessage(), srcLocator); 
@@ -429,8 +449,9 @@ public class ElemFunction extends ElemTemplate
    * 
    * This method is implemented similarly to how, xsl:variable instruction's value
    * is determined from xsl:variable's child contents. Any xsl:param prefix elements 
-   * present within xsl:function element, are processed according to xsl:variable 
-   * instruction's semantics (the class ElemParam extends the class ElemVariable). 
+   * available within xsl:function element, are processed as per xsl:variable 
+   * instruction's evaluation semantics (the class ElemParam extends the class 
+   * ElemVariable). 
    * 
    * @param transformer				org.apache.xalan.transformer.TransformerImpl object
    * @param xctxt           		xpath context object
@@ -439,11 +460,19 @@ public class ElemFunction extends ElemTemplate
    */
   private XObject getXslFunctionResult(TransformerImpl transformer, XPathContext xctxt) throws TransformerException {		
 	  XObject result = null;
-
-	  int nodeDtmHandle = transformer.transformToGlobalRTF(this);
-	  NodeList nodeList = (new XRTreeFrag(nodeDtmHandle, xctxt, this)).convertToNodeset();     
-
-	  result = new XNodeSetForDOM(nodeList, xctxt);
+	  
+	  Object xslFunctionResult = transformer.transformToGlobalRTFXslFunction(this);
+	  
+	  Integer nodeDtmHandle = null;	  
+	  try {
+		 nodeDtmHandle = Integer.valueOf(xslFunctionResult.toString());
+	     NodeList nodeList = (new XRTreeFrag(nodeDtmHandle.intValue(), xctxt, this)).convertToNodeset();
+	     result = new XNodeSetForDOM(nodeList, xctxt);
+	  }
+	  catch (NumberFormatException ex) {
+		 result = (XPathInlineFunction)xslFunctionResult;
+		 XslTransformSharedDatastore.xpathInlineFunction = null;
+	  }	  
 
 	  return result;
   }
diff --git a/src/org/apache/xalan/templates/ElemSequence.java b/src/org/apache/xalan/templates/ElemSequence.java
index b98ecaf94..3785cf8a9 100644
--- a/src/org/apache/xalan/templates/ElemSequence.java
+++ b/src/org/apache/xalan/templates/ElemSequence.java
@@ -26,6 +26,7 @@ import javax.xml.transform.TransformerException;
 import org.apache.xalan.serialize.SerializerUtils;
 import org.apache.xalan.transformer.TransformerImpl;
 import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
+import org.apache.xalan.xslt.util.XslTransformSharedDatastore;
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.serializer.SerializationHandler;
 import org.apache.xpath.Expression;
@@ -35,17 +36,16 @@ import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.axes.SelfIteratorNoPredicate;
 import org.apache.xpath.compiler.XPathParser;
 import org.apache.xpath.composite.SequenceTypeData;
-import org.apache.xpath.functions.XSLConstructorStylesheetOrExtensionFunction;
-import org.apache.xpath.functions.XSLFunctionBuilder;
 import org.apache.xpath.functions.Function;
+import org.apache.xpath.functions.XSLConstructorStylesheetOrExtensionFunction;
 import org.apache.xpath.functions.XSLFunctionService;
-import org.apache.xpath.objects.XPathInlineFunction;
 import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XBoolean;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNodeSetForDOM;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XPathInlineFunction;
 import org.apache.xpath.objects.XRTreeFrag;
 import org.apache.xpath.objects.XString;
 import org.apache.xpath.operations.Operation;
@@ -335,55 +335,60 @@ public class ElemSequence extends ElemTemplateElement
                                                                                   null, XPath.SELECT, null);
           xslSequenceVal = emptySeqXPath.execute(xctxt, DTM.NULL, null);
       }
-      
-      SerializationHandler handler = transformer.getSerializationHandler();
-      
+            
       if (xslSequenceVal != null) {
-          int xObjectType = xslSequenceVal.getType();
-          String strVal = null;
-  
-          switch (xObjectType) {           
-              case XObject.CLASS_NODESET :          
-                ElemCopyOf.copyOfActionOnNodeSet((XNodeSet)xslSequenceVal, transformer, handler, xctxt);          
-                break;
-              case XObject.CLASS_RTREEFRAG :
-                SerializerUtils.outputResultTreeFragment(handler, xslSequenceVal, xctxt);
-                break;
-              case XObject.CLASS_RESULT_SEQUENCE :         
-                ResultSequence resultSequence = (ResultSequence)xslSequenceVal;          
-                ElemCopyOf.copyOfActionOnResultSequence(resultSequence, transformer, handler, xctxt, true);          
-                break;
-              default :
-                // no op
-          }
-          
-          boolean isToAddStrValSerializationSuffix = isToAddStrValSerializationSuffix(xctxt); 
-          
-          if ((xslSequenceVal instanceof XBoolean) || (xslSequenceVal instanceof XNumber) || 
-                                                                    (xslSequenceVal instanceof XString)) {
-              if (isToAddStrValSerializationSuffix) {
-                 strVal = xslSequenceVal.str() + STRING_VAL_SERIALIZATION_SUFFIX;
-              }
-              else {
-                 strVal = xslSequenceVal.str();  
-              }
-              
-              handler.characters(strVal.toCharArray(), 0, strVal.length());
-          }
-          else if (xslSequenceVal instanceof XSAnyAtomicType) {
-              if (isToAddStrValSerializationSuffix) {
-                 strVal = ((XSAnyAtomicType)xslSequenceVal).stringValue() + STRING_VAL_SERIALIZATION_SUFFIX;
-              }
-              else {
-                 strVal = ((XSAnyAtomicType)xslSequenceVal).stringValue();
-              }
-              
-              handler.characters(strVal.toCharArray(), 0, strVal.length());
-          }
-          else if (xslSequenceVal instanceof XPathInlineFunction) {
+    	  if (xslSequenceVal instanceof XPathInlineFunction) {
+    		  XslTransformSharedDatastore.xpathInlineFunction = (XPathInlineFunction)xslSequenceVal;   
+    	  }
+    	  else {
+    		  SerializationHandler handler = transformer.getSerializationHandler();
+    		  
+	          int xObjectType = xslSequenceVal.getType();
+	          String strVal = null;
+	  
+	          switch (xObjectType) {           
+	              case XObject.CLASS_NODESET :          
+	                ElemCopyOf.copyOfActionOnNodeSet((XNodeSet)xslSequenceVal, transformer, handler, xctxt);          
+	                break;
+	              case XObject.CLASS_RTREEFRAG :
+	                SerializerUtils.outputResultTreeFragment(handler, xslSequenceVal, xctxt);
+	                break;
+	              case XObject.CLASS_RESULT_SEQUENCE :         
+	                ResultSequence resultSequence = (ResultSequence)xslSequenceVal;          
+	                ElemCopyOf.copyOfActionOnResultSequence(resultSequence, transformer, handler, xctxt, true);          
+	                break;
+	              default :
+	                // no op
+	          }
+	          
+	          boolean isToAddStrValSerializationSuffix = isToAddStrValSerializationSuffix(xctxt); 
+	          
+	          if ((xslSequenceVal instanceof XBoolean) || (xslSequenceVal instanceof XNumber) || 
+	                                                                    (xslSequenceVal instanceof XString)) {
+	              if (isToAddStrValSerializationSuffix) {
+	                 strVal = xslSequenceVal.str() + STRING_VAL_SERIALIZATION_SUFFIX;
+	              }
+	              else {
+	                 strVal = xslSequenceVal.str();  
+	              }
+	              
+	              handler.characters(strVal.toCharArray(), 0, strVal.length());
+	          }
+	          else if (xslSequenceVal instanceof XSAnyAtomicType) {
+	              if (isToAddStrValSerializationSuffix) {
+	                 strVal = ((XSAnyAtomicType)xslSequenceVal).stringValue() + STRING_VAL_SERIALIZATION_SUFFIX;
+	              }
+	              else {
+	                 strVal = ((XSAnyAtomicType)xslSequenceVal).stringValue();
+	              }
+	              
+	              handler.characters(strVal.toCharArray(), 0, strVal.length());
+	          }
+    	  }
+          /*else if (xslSequenceVal instanceof XPathInlineFunction) {
               throw new TransformerException("XTDE0450 : Cannot add a function item to an XDM result tree, "
                                                                                                    + "via xsl:sequence instruction.", srcLocator);
-          }
+          }*/
        }
     }
     catch (SAXException se) {
diff --git a/src/org/apache/xalan/transformer/TransformerImpl.java b/src/org/apache/xalan/transformer/TransformerImpl.java
index 3fec3237d..7e9545833 100644
--- a/src/org/apache/xalan/transformer/TransformerImpl.java
+++ b/src/org/apache/xalan/transformer/TransformerImpl.java
@@ -67,6 +67,7 @@ import org.apache.xalan.templates.StylesheetRoot;
 import org.apache.xalan.templates.XUnresolvedVariable;
 import org.apache.xalan.trace.GenerateEvent;
 import org.apache.xalan.trace.TraceManager;
+import org.apache.xalan.xslt.util.XslTransformSharedDatastore;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.dtm.DTMManager;
@@ -1947,6 +1948,18 @@ public class TransformerImpl extends Transformer
     return transformToRTF(templateParent,dtmFrag);
   }
   
+  /**
+   * Method to get xsl:function's evaluation result.
+   */
+  public Object transformToGlobalRTFXslFunction(ElemTemplateElement templateParent) throws TransformerException {
+	  Object result = null;
+	  
+	  DTM dtmFrag = m_xcontext.getGlobalRTFDTM();
+	  result = transformToRTFXslFunction(templateParent, dtmFrag);
+	  
+	  return result;
+  }
+  
   /**
    * Given a stylesheet element, create a result tree fragment from it's
    * contents.
@@ -2008,7 +2021,7 @@ public class TransformerImpl extends Transformer
         // received, but flushed, the startDocument, and may be invalid
         // again after the document has been closed (still debating that)
         // ... so waiting until just before the end seems simplest/safest. 
-	resultFragment = dtmFrag.getDocument();      
+	    resultFragment = dtmFrag.getDocument();      
       }
       finally
       {
@@ -2028,6 +2041,64 @@ public class TransformerImpl extends Transformer
 
     return resultFragment;
   }
+  
+  /**
+   * Method to get xsl:function's evaluation result.
+   */
+  private Object transformToRTFXslFunction(ElemTemplateElement templateParent, 
+		                                   DTM dtmFrag) throws TransformerException {
+
+	  Object result = null;
+
+	  ContentHandler rtfHandler = dtmFrag.getContentHandler();
+
+	  int resultFragment;
+
+	  // Save the current result tree handler
+	  SerializationHandler savedRTreeHandler = this.m_serializationHandler;
+
+	  // And make a new handler for the RTF
+	  ToSAXHandler h = new ToXMLSAXHandler();
+	  h.setContentHandler(rtfHandler);
+	  h.setTransformer(this);
+
+	  // Replace the old handler (which was already saved)
+	  m_serializationHandler = h;
+
+	  // Use local variable for the current handler
+	  SerializationHandler rth = m_serializationHandler;
+
+	  try {
+		  rth.startDocument();
+
+		  rth.flushPending(); 
+
+		  try {
+			  // Do the transformation of the child elements
+			  result = executeChildTemplatesXslFunction(templateParent, true);
+
+			  rth.flushPending();
+
+			  // Get the document ID
+			  if (result == null) { 
+				  resultFragment = dtmFrag.getDocument();
+				  result = Integer.valueOf(resultFragment);
+			  }
+		  }
+		  finally {
+			  rth.endDocument();
+		  }
+	  }
+	  catch (org.xml.sax.SAXException se) {
+		  throw new TransformerException(se);
+	  }
+	  finally {
+		  // Restore the previous result tree handler
+		  this.m_serializationHandler = savedRTreeHandler;
+	  }
+
+	  return result;
+  }
 
   /**
    * Get the StringWriter pool, so that StringWriter
@@ -2430,6 +2501,74 @@ public class TransformerImpl extends Transformer
 //    if (check)
 //      getStackGuard().pop();
   }
+  
+  /**
+   * Method that supports, to get xsl:function's evaluation result.
+   */
+  public Object executeChildTemplatesXslFunction(ElemTemplateElement elem, 
+		                                         boolean shouldAddAttrs) throws TransformerException {
+
+	  Object result = null;
+
+	  ElemTemplateElement t = elem.getFirstChildElem();
+
+	  if (null == t)
+		  return null;      
+
+	  if (elem.hasTextLitOnly() && m_optimizer) {      
+		  char[] chars = ((ElemTextLiteral)t).getChars();
+		  try {
+			  this.pushElemTemplateElement(t);
+			  m_serializationHandler.characters(chars, 0, chars.length);
+		  }
+		  catch(SAXException se)
+		  {
+			  throw new TransformerException(se);
+		  }
+		  finally
+		  {
+			  this.popElemTemplateElement();
+		  }
+		  
+		  return null;
+	  }
+
+	  XPathContext xctxt = m_xcontext;
+	  xctxt.pushSAXLocatorNull();
+	  int currentTemplateElementsTop = m_currentTemplateElements.size();
+	  m_currentTemplateElements.push(null);
+
+	  try
+	  {
+		  for (; t != null; t = t.getNextSiblingElem())
+		  {
+			  if (!shouldAddAttrs
+					  && t.getXSLToken() == Constants.ELEMNAME_ATTRIBUTE)
+				  continue;
+
+			  xctxt.setSAXLocator(t);
+			  m_currentTemplateElements.setElementAt(t,currentTemplateElementsTop);
+			  t.execute(this);
+			  if (XslTransformSharedDatastore.xpathInlineFunction != null) {
+				  result = XslTransformSharedDatastore.xpathInlineFunction;
+				  break;
+			  }
+		  }
+	  }
+	  catch(RuntimeException re)
+	  {
+		  TransformerException te = new TransformerException(re);
+		  te.setLocator(t);
+		  throw te;
+	  }
+	  finally
+	  {
+		  m_currentTemplateElements.pop();
+		  xctxt.popSAXLocator();
+	  }
+
+	  return result;
+   }
     /**
       * Execute each of the children of a template element.
       *
diff --git a/src/org/apache/xalan/xslt/util/XslTransformSharedDatastore.java b/src/org/apache/xalan/xslt/util/XslTransformSharedDatastore.java
index 5ac345550..09acc1ec6 100644
--- a/src/org/apache/xalan/xslt/util/XslTransformSharedDatastore.java
+++ b/src/org/apache/xalan/xslt/util/XslTransformSharedDatastore.java
@@ -16,8 +16,10 @@
  */
 package org.apache.xalan.xslt.util;
 
+import org.apache.xpath.objects.XPathInlineFunction;
+
 /**
- * This class, has few XalanJ, XSLT stylesheet transformation wide variables.
+ * This class, has few Xalan-J, XSL stylesheet transformation wide variables.
  * 
  * @author Mukul Gandhi <mu...@apache.org>
  * 
@@ -25,7 +27,11 @@ package org.apache.xalan.xslt.util;
  */
 public class XslTransformSharedDatastore {
     
-    // XSLT document's uri, used for error reporting
+    // XSL stylesheet document's uri, used for error handling
     public static String xslSystemId;
+    
+    // Used to return function items, from XSL stylesheet 
+    // xsl:function calls.
+    public static XPathInlineFunction xpathInlineFunction;
 
 }
diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index c0a2f3681..12aff4657 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -1245,8 +1245,7 @@ public class XPathParser
   protected void Expr() throws javax.xml.transform.TransformerException
   {	  
 	  if (m_isXPathExprBeginParse && tokenIs("(") && (lookahead("to", 2) || lookahead("to", 3))) {
-		  // To parse an XPath expression like '(a to b) => function()', it seems simpler
-		  // to handle its parse here.
+		  // XPath parse of expression like '(a to b) => function()'
 		  
 		  int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
 		  
diff --git a/tests/org/apache/xalan/xslt3/XslFunctionTests.java b/tests/org/apache/xalan/xslt3/XslFunctionTests.java
index d125a337d..3014dbea3 100644
--- a/tests/org/apache/xalan/xslt3/XslFunctionTests.java
+++ b/tests/org/apache/xalan/xslt3/XslFunctionTests.java
@@ -218,5 +218,15 @@ public class XslFunctionTests extends XSLTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslFunctionTest18() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test18.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test18.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test18.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/xsl_function/gold/test18.out b/tests/xsl_function/gold/test18.out
new file mode 100644
index 000000000..c7ff4601e
--- /dev/null
+++ b/tests/xsl_function/gold/test18.out
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one>5</one>
+  <two>3</two>
+</result>
diff --git a/tests/xsl_function/test17.xsl b/tests/xsl_function/test17.xsl
index 43e4242c9..a30ab817b 100644
--- a/tests/xsl_function/test17.xsl
+++ b/tests/xsl_function/test17.xsl
@@ -7,9 +7,9 @@
                 
   <!-- Author: mukulg@apache.org -->
   
- <!-- An XSLT stylesheet test case, that tests XPath arithmetic binary 
-      operators '+' and '-', when the operands to these XPath operators 
-      are stylesheet function calls. 
+  <!-- An XSLT stylesheet test case, that tests XPath arithmetic binary 
+       operators '+' and '-', when the operands to these XPath operators 
+       are stylesheet function calls. 
   -->                
                 
   <xsl:output method="xml" indent="yes"/>
diff --git a/tests/xsl_function/test18.xsl b/tests/xsl_function/test18.xsl
new file mode 100644
index 000000000..71de22d37
--- /dev/null
+++ b/tests/xsl_function/test18.xsl
@@ -0,0 +1,64 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+				xmlns:fn0="http://fn0"                
+                exclude-result-prefixes="xs fn0" version="3.0">
+                
+     <!-- Author: mukulg@apache.org -->
+     
+     <!-- An XSL stylesheet test case, that tests xsl:function calls 
+          returning function items. -->            
+				
+     <xsl:output method="xml" indent="yes"/>          				
+  
+     <xsl:template match="/">
+	    <result>
+		   <xsl:variable name="func1" select="fn0:getFuncItem(1)" as="function(*)"/>
+		   <xsl:variable name="func2" select="fn0:getFuncItem(2)" as="function(*)"/>
+		   <one>
+		      <xsl:value-of select="$func1(2,3)"/>
+		   </one>
+		   <two>
+		      <xsl:value-of select="$func2(5,2)"/>
+		   </two>
+		</result>
+	 </xsl:template>
+	 
+	 <!-- 
+	    An XSL stylesheet function, that returns different function 
+	    items depending on what argument has been passed with 
+	    xsl:function call.
+	  -->
+	 <xsl:function name="fn0:getFuncItem" as="function(*)">
+	    <xsl:param name="n0" as="xs:integer"/>
+		<xsl:choose>
+		   <xsl:when test="$n0 eq 1">
+		      <xsl:sequence select="function($a,$b) { $a + $b }"/>
+		   </xsl:when>
+		   <xsl:when test="$n0 eq 2">
+		      <xsl:sequence select="function($a,$b) { $a - $b }"/>
+		   </xsl:when>
+		   <xsl:when test="$n0 eq 3">
+		      <xsl:sequence select="function($a,$b) { $a * $b }"/>		   
+		   </xsl:when>
+		</xsl:choose>
+	 </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>


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