Try to catch element order and required element errors during stylesheet object creation. This new code adds an order and a required field to XSLElementDef objects where it is applicable.


git-svn-id: https://svn.apache.org/repos/asf/xalan/java/trunk@334559 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xalan/processor/ProcessorStylesheetElement.java b/src/org/apache/xalan/processor/ProcessorStylesheetElement.java
index b7343d0..75822a0 100644
--- a/src/org/apache/xalan/processor/ProcessorStylesheetElement.java
+++ b/src/org/apache/xalan/processor/ProcessorStylesheetElement.java
@@ -94,6 +94,7 @@
             throws org.xml.sax.SAXException
   {
 
+		super.startElement(handler, uri, localName, rawName, attributes);
     try
     {
       int stylesheetType = handler.getStylesheetType();
@@ -159,6 +160,7 @@
           StylesheetHandler handler, String uri, String localName, String rawName)
             throws org.xml.sax.SAXException
   {
+		super.endElement(handler, uri, localName, rawName);
     handler.popElemTemplateElement();
     handler.popStylesheet();
   }
diff --git a/src/org/apache/xalan/processor/ProcessorTemplateElem.java b/src/org/apache/xalan/processor/ProcessorTemplateElem.java
index e49f6ae..90bd338 100644
--- a/src/org/apache/xalan/processor/ProcessorTemplateElem.java
+++ b/src/org/apache/xalan/processor/ProcessorTemplateElem.java
@@ -93,6 +93,7 @@
             throws org.xml.sax.SAXException
   {
 
+		super.startElement(handler, uri, localName, rawName, attributes);
     try
     {
       // ElemTemplateElement parent = handler.getElemTemplateElement();
@@ -163,6 +164,7 @@
           StylesheetHandler handler, String uri, String localName, String rawName)
             throws org.xml.sax.SAXException
   {
+		super.endElement(handler, uri, localName, rawName);
     handler.popElemTemplateElement();
   }
 }
diff --git a/src/org/apache/xalan/processor/StylesheetHandler.java b/src/org/apache/xalan/processor/StylesheetHandler.java
index a5b5cb8..20a6159 100644
--- a/src/org/apache/xalan/processor/StylesheetHandler.java
+++ b/src/org/apache/xalan/processor/StylesheetHandler.java
@@ -404,7 +404,8 @@
             && ((null == getStylesheet()
                 || Double.valueOf(getStylesheet().getVersion()).doubleValue()
                    > Constants.XSLTVERSUPPORTED) ||
-                currentProcessor instanceof ProcessorStylesheetElement))
+								(!uri.equals(Constants.S_XSLNAMESPACEURL) &&
+                currentProcessor instanceof ProcessorStylesheetElement)))
     {
       elemProcessor = def.getProcessorForUnknown(uri, localName);
     }
@@ -412,7 +413,7 @@
     if (null == elemProcessor)
       error(rawName + " is not allowed in this position in the stylesheet!",
             null);
-
+		
     return elemProcessor;
   }
 
@@ -493,7 +494,7 @@
       if (null != getStylesheetRoot())
       {
         if (0 == m_stylesheetLevel)
-          getStylesheetRoot().recompose();
+          getStylesheetRoot().recompose();        
       }
       else
         throw new TransformerException("Did not find the stylesheet root!");
@@ -503,7 +504,7 @@
       if (null != elemProcessor)
         elemProcessor.startNonText(this);
 
-      m_stylesheetLevel--;
+      m_stylesheetLevel--;			
       
       popSpaceHandling();
 
@@ -599,7 +600,7 @@
           String uri, String localName, String rawName, Attributes attributes)
             throws org.xml.sax.SAXException
   {
-    NamespaceSupport nssupport = this.getNamespaceSupport();
+		NamespaceSupport nssupport = this.getNamespaceSupport();
     nssupport.pushContext();
     
     int n = m_prefixMappings.size();
@@ -612,7 +613,7 @@
     //m_prefixMappings.clear(); // JDK 1.2+ only -sc
     m_prefixMappings.removeAllElements(); // JDK 1.1.x compat -sc
 
-    m_elementID++;
+    m_elementID++;		
 
     checkForFragmentID(attributes);
 
@@ -628,6 +629,7 @@
 
     this.pushProcessor(elemProcessor);
     elemProcessor.startElement(this, uri, localName, rawName, attributes);
+		
   }
 
   /**
@@ -1138,8 +1140,8 @@
 
   /** The root stylesheet of the stylesheets tree. */
   StylesheetRoot m_stylesheetRoot;
-
-  /** The last stylesheet that was popped off the stylesheets stack. */
+	
+	/** The last stylesheet that was popped off the stylesheets stack. */
   Stylesheet m_lastPoppedStylesheet;
 
   /**
@@ -1295,13 +1297,7 @@
     return (ElemTemplateElement) m_elems.pop();
   }
 
-  /**
-   * Flag to let us know when we've found an element inside the
-   * stylesheet that is not an xsl:import, so we can restrict imports
-   * to being the first elements.
-   */
-  private boolean m_foundNotImport = false;
-
+  
   /**
    * A XSLMessages instance capable of producing user messages.
    */
diff --git a/src/org/apache/xalan/processor/XSLTElementDef.java b/src/org/apache/xalan/processor/XSLTElementDef.java
index 1d5ce96..eabf400 100644
--- a/src/org/apache/xalan/processor/XSLTElementDef.java
+++ b/src/org/apache/xalan/processor/XSLTElementDef.java
@@ -60,6 +60,11 @@
 
 import org.apache.xalan.templates.Constants;
 import org.apache.xml.utils.QName;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
+
+import java.util.Hashtable;
+import java.util.Enumeration;
 
 /**
  * This class defines the allowed structure for an element in a XSLT stylesheet,
@@ -102,6 +107,168 @@
         schema.addAvailableElement(new QName(namespace, nameAlias));
     } 
   }
+	
+	/**
+   * Construct an instance of XSLTElementDef.
+   *
+   * @param namespace  The Namespace URI, "*", or null.
+   * @param name The local name (without prefix), "*", or null.
+   * @param nameAlias A potential alias for the name, or null.
+   * @param elements An array of allowed child element defs, or null.
+   * @param attributes An array of allowed attribute defs, or null.
+   * @param contentHandler The element processor for this element.
+   * @param classObject The class of the object that this element def should produce.
+   * @param has_required true if this element has required elements by the XSLT specification.
+   */
+  XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
+                 XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
+                 XSLTElementProcessor contentHandler, Class classObject, boolean has_required)
+  {
+		this.m_has_required = has_required;
+    build(namespace, name, nameAlias, elements, attributes, contentHandler,
+          classObject);
+    if ( (null != namespace)
+    &&  (namespace.equals(Constants.S_XSLNAMESPACEURL)
+        || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) )
+    {
+      schema.addAvailableElement(new QName(namespace, name));
+      if(null != nameAlias)
+        schema.addAvailableElement(new QName(namespace, nameAlias));
+    } 
+		
+  }
+	
+	/**
+   * Construct an instance of XSLTElementDef.
+   *
+   * @param namespace  The Namespace URI, "*", or null.
+   * @param name The local name (without prefix), "*", or null.
+   * @param nameAlias A potential alias for the name, or null.
+   * @param elements An array of allowed child element defs, or null.
+   * @param attributes An array of allowed attribute defs, or null.
+   * @param contentHandler The element processor for this element.
+   * @param classObject The class of the object that this element def should produce.
+   * @param has_required true if this element has required elements by the XSLT specification.
+   * @param required true if this element is required by the XSLT specification.
+   */
+  XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
+                 XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
+                 XSLTElementProcessor contentHandler, Class classObject, 
+								 boolean has_required, boolean required)
+  {
+    this(schema, namespace, name,  nameAlias,
+                 elements, attributes,
+                 contentHandler, classObject, has_required);
+		this.m_required = required;
+  }
+	
+	/**
+   * Construct an instance of XSLTElementDef.
+   *
+   * @param namespace  The Namespace URI, "*", or null.
+   * @param name The local name (without prefix), "*", or null.
+   * @param nameAlias A potential alias for the name, or null.
+   * @param elements An array of allowed child element defs, or null.
+   * @param attributes An array of allowed attribute defs, or null.
+   * @param contentHandler The element processor for this element.
+   * @param classObject The class of the object that this element def should produce.
+   * @param has_required true if this element has required elements by the XSLT specification.
+   * @param required true if this element is required by the XSLT specification.
+   * @param order the order this element should appear according to the XSLT specification.   
+   * @param multiAllowed whether this element is allowed more than once
+   */
+  XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
+                 XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
+                 XSLTElementProcessor contentHandler, Class classObject, 
+								 boolean has_required, boolean required, int order, 
+								 boolean multiAllowed)
+  {
+		this(schema, namespace, name,  nameAlias,
+                 elements, attributes,
+                 contentHandler, classObject, has_required, required);    
+		this.m_order = order;
+		this.m_multiAllowed = multiAllowed;
+  }
+	
+	/**
+   * Construct an instance of XSLTElementDef.
+   *
+   * @param namespace  The Namespace URI, "*", or null.
+   * @param name The local name (without prefix), "*", or null.
+   * @param nameAlias A potential alias for the name, or null.
+   * @param elements An array of allowed child element defs, or null.
+   * @param attributes An array of allowed attribute defs, or null.
+   * @param contentHandler The element processor for this element.
+   * @param classObject The class of the object that this element def should produce.
+   * @param has_required true if this element has required elements by the XSLT specification.
+   * @param required true if this element is required by the XSLT specification.
+   * @param has_order whether this element has ordered child elements
+   * @param order the order this element should appear according to the XSLT specification.   
+   * @param multiAllowed whether this element is allowed more than once
+   */
+  XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
+                 XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
+                 XSLTElementProcessor contentHandler, Class classObject, 
+								 boolean has_required, boolean required, boolean has_order, int order, 
+								 boolean multiAllowed)
+  {
+		this(schema, namespace, name,  nameAlias,
+                 elements, attributes,
+                 contentHandler, classObject, has_required, required);    
+		this.m_order = order;
+		this.m_multiAllowed = multiAllowed;
+    this.m_isOrdered = has_order;		
+  }
+	
+	/**
+   * Construct an instance of XSLTElementDef.
+   *
+   * @param namespace  The Namespace URI, "*", or null.
+   * @param name The local name (without prefix), "*", or null.
+   * @param nameAlias A potential alias for the name, or null.
+   * @param elements An array of allowed child element defs, or null.
+   * @param attributes An array of allowed attribute defs, or null.
+   * @param contentHandler The element processor for this element.
+   * @param classObject The class of the object that this element def should produce.
+   * @param has_order whether this element has ordered child elements
+   * @param order the order this element should appear according to the XSLT specification.   
+   * @param multiAllowed whether this element is allowed more than once
+   */
+  XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
+                 XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
+                 XSLTElementProcessor contentHandler, Class classObject, 
+								 boolean has_order, int order, boolean multiAllowed)
+  {
+    this(schema, namespace, name,  nameAlias,
+                 elements, attributes,
+                 contentHandler, classObject, 
+								 order, multiAllowed);
+		this.m_isOrdered = has_order;		
+  }
+	
+	/**
+   * Construct an instance of XSLTElementDef.
+   *
+   * @param namespace  The Namespace URI, "*", or null.
+   * @param name The local name (without prefix), "*", or null.
+   * @param nameAlias A potential alias for the name, or null.
+   * @param elements An array of allowed child element defs, or null.
+   * @param attributes An array of allowed attribute defs, or null.
+   * @param contentHandler The element processor for this element.
+   * @param classObject The class of the object that this element def should produce.
+   * @param order the order this element should appear according to the XSLT specification.   
+   * @param multiAllowed whether this element is allowed more than once
+   */
+  XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
+                 XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
+                 XSLTElementProcessor contentHandler, Class classObject, 
+								 int order, boolean multiAllowed)
+  {
+    this(schema, namespace, name, nameAlias, elements, attributes, contentHandler,
+          classObject);
+    this.m_order = order;
+		this.m_multiAllowed = multiAllowed;
+  }
 
   /**
    * Construct an instance of XSLTElementDef that represents text.
@@ -145,6 +312,22 @@
     setElementProcessor(contentHandler);
 
     this.m_classObject = classObject;
+		
+		if (hasRequired() && m_elements != null)
+		{
+			int n = m_elements.length;
+			for (int i = 0; i < n; i++)
+			{
+				XSLTElementDef def = m_elements[i];
+				
+				if (def != null && def.getRequired())
+				{
+					if (m_requiredFound == null)			
+						m_requiredFound = new Hashtable();
+					m_requiredFound.put(def.getName(), "xsl:" +def.getName()); 
+				}
+			}
+		}
   }
 
   /**
@@ -311,16 +494,17 @@
    *
    * @return The element processor that matches the arguments, or null.
    */
-  XSLTElementProcessor getProcessorFor(String uri, String localName)
-  {
+  XSLTElementProcessor getProcessorFor(String uri, String localName) 
+	{
 
-    XSLTElementProcessor lreDef = null;  // return value
+    XSLTElementProcessor elemDef = null;  // return value
 
     if (null == m_elements)
       return null;
 
     int n = m_elements.length;
-
+    int order = -1;
+		boolean multiAllowed = true;
     for (int i = 0; i < n; i++)
     {
       XSLTElementDef def = m_elements[i];
@@ -330,16 +514,42 @@
       // see if anything else matches.
       if (def.m_name.equals("*"))
       {
-
+				
         // Don't allow xsl elements
         if (!equalsMayBeNullOrZeroLen(uri, Constants.S_XSLNAMESPACEURL))
-          lreDef = def.m_elementProcessor;
+				{
+          elemDef = def.m_elementProcessor;
+				  order = def.getOrder();
+					multiAllowed = def.getMultiAllowed();
+				}
       }
-      else if (def.QNameEquals(uri, localName))
-        return def.m_elementProcessor;
-    }
+			else if (def.QNameEquals(uri, localName))
+			{	
+				if (def.getRequired())
+					this.setRequiredFound(def.getName(), true);
+				order = def.getOrder();
+				multiAllowed = def.getMultiAllowed();
+				elemDef = def.m_elementProcessor;
+				break;
+			}
+		}		
+		
+		if (elemDef != null && this.isOrdered())
+		{			
+			int lastOrder = getLastOrder();
+			if (order > lastOrder)
+				setLastOrder(order);
+			else if (order == lastOrder && !multiAllowed)
+			{
+				return null;
+			}
+			else if (order < lastOrder && order > 0)
+			{
+				return null;
+			}
+		}
 
-    return lreDef;
+    return elemDef;
   }
 
   /**
@@ -488,4 +698,169 @@
   {
     return m_classObject;
   }
+	
+	/**
+   * If true, this has a required element.
+   */
+  private boolean m_has_required = false;
+
+  /**
+   * Get whether or not this has a required element.
+   *
+   * @return true if this this has a required element.
+   */
+  boolean hasRequired()
+  {
+    return m_has_required;
+  }
+	
+	/**
+   * If true, this is a required element.
+   */
+  private boolean m_required = false;
+
+  /**
+   * Get whether or not this is a required element.
+   *
+   * @return true if this is a required element.
+   */
+  boolean getRequired()
+  {
+    return m_required;
+  }
+	
+	Hashtable m_requiredFound;
+	
+	/**
+   * Set this required element found.
+   *
+   */
+  void setRequiredFound(String elem, boolean found)
+  {
+   if (m_requiredFound.get(elem) != null) 
+		 m_requiredFound.remove(elem);
+  }
+	
+	/**
+   * Get whether all required elements were found.
+   *
+   * @return true if all required elements were found.
+   */
+  boolean getRequiredFound()
+  {
+		if (m_requiredFound == null)
+			return true;
+    return m_requiredFound.isEmpty();
+  }
+	
+	/**
+   * Get required elements that were not found.
+   *
+   * @return required elements that were not found.
+   */
+  String getRequiredElem()
+  {
+		if (m_requiredFound == null)
+			return null;
+		Enumeration elems = m_requiredFound.elements();
+		String s = "";
+		boolean first = true;
+		while (elems.hasMoreElements())
+		{
+			if (first)
+				first = false;
+			else
+			 s = s + ", ";
+			s = s + (String)elems.nextElement();
+		}
+    return s;
+  }
+	
+	boolean m_isOrdered = false;	
+	
+	/**
+   * Get whether this element requires ordered children.
+   *
+   * @return true if this element requires ordered children.
+   */
+  boolean isOrdered()
+  {
+		/*if (!m_CheckedOrdered)
+		{
+			m_CheckedOrdered = true;
+			m_isOrdered = false;
+			if (null == m_elements)
+				return false;
+
+			int n = m_elements.length;
+
+			for (int i = 0; i < n; i++)
+			{
+				if (m_elements[i].getOrder() > 0)
+				{
+					m_isOrdered = true;
+					return true;
+				}
+			}
+			return false;
+		}
+		else*/
+			return m_isOrdered;
+  }
+	
+	/**
+   * the order that this element should appear, or -1 if not ordered
+   */
+  private int m_order = -1;
+	
+	/**
+   * Get the order that this element should appear .
+   *
+   * @return the order that this element should appear.
+   */
+  int getOrder()
+  {
+    return m_order;
+  }
+	
+	/**
+   * the highest order of child elements have appeared so far, 
+   * or -1 if not ordered
+   */
+  private int m_lastOrder = -1;
+	
+	/**
+   * Get the highest order of child elements have appeared so far .
+   *
+   * @return the highest order of child elements have appeared so far.
+   */
+  int getLastOrder()
+  {
+    return m_lastOrder;
+  }
+	
+	/**
+   * Set the highest order of child elements have appeared so far .
+   *
+   * @param order the highest order of child elements have appeared so far.
+   */
+  void setLastOrder(int order)
+  {
+    m_lastOrder = order ;
+  }
+	
+	/**
+   * True if this element can appear multiple times
+   */
+  private boolean m_multiAllowed = true;
+	
+	/**
+   * Get whether this element can appear multiple times
+   *
+   * @return true if this element can appear multiple times
+   */
+  boolean getMultiAllowed()
+  {
+    return m_multiAllowed;
+  }
 }
diff --git a/src/org/apache/xalan/processor/XSLTElementProcessor.java b/src/org/apache/xalan/processor/XSLTElementProcessor.java
index e4d1048..c535894 100644
--- a/src/org/apache/xalan/processor/XSLTElementProcessor.java
+++ b/src/org/apache/xalan/processor/XSLTElementProcessor.java
@@ -64,6 +64,9 @@
 
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xalan.res.XSLTErrorResources;
+import org.apache.xalan.templates.ElemTemplateElement;
+import org.apache.xalan.templates.Constants;
+import org.apache.xml.utils.IntStack;
 
 import org.xml.sax.helpers.AttributesImpl;
 import javax.xml.transform.ErrorListener;
@@ -84,6 +87,8 @@
    * @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
    */
   XSLTElementProcessor(){}
+	
+	private IntStack m_savedLastOrder;
 
   /**
    * The element definition that this processor conforms to.
@@ -195,7 +200,10 @@
             throws org.xml.sax.SAXException
   {
 
-    // no op
+    if (m_savedLastOrder == null)
+				m_savedLastOrder = new IntStack();
+			m_savedLastOrder.push(getElemDef().getLastOrder());
+			getElemDef().setLastOrder(-1);
   }
 
   /**
@@ -213,8 +221,8 @@
           StylesheetHandler handler, String uri, String localName, String rawName)
             throws org.xml.sax.SAXException
   {
-
-    // no op
+		if (m_savedLastOrder != null && !m_savedLastOrder.empty())
+			getElemDef().setLastOrder(m_savedLastOrder.pop());
   }
 
   /**
diff --git a/src/org/apache/xalan/processor/XSLTSchema.java b/src/org/apache/xalan/processor/XSLTSchema.java
index e6c60cf..01b1209 100644
--- a/src/org/apache/xalan/processor/XSLTSchema.java
+++ b/src/org/apache/xalan/processor/XSLTSchema.java
@@ -273,7 +273,7 @@
     XSLTElementDef[] charTemplateElements = new XSLTElementDef[15];
     XSLTElementDef resultElement = new XSLTElementDef(this, null, "*",
                                      null /*alias */,
-                                     templateElementsAndParams /* elements */,
+                                     templateElements /* elements */,
                                      new XSLTAttributeDef[]{
                                        spaceAttrLiteral, // special
                                        xslExcludeResultPrefixesAttr,
@@ -281,8 +281,9 @@
                                        xslUseAttributeSetsAttr,
                                        xslVersionAttr,
                                        xslResultAttr,
-                                       resultAttr }, new ProcessorLRE(),
-                                                     ElemLiteralResult.class /* class object */);
+                                       resultAttr }, 
+																		 new ProcessorLRE(),
+                                     ElemLiteralResult.class /* class object */, 20, true);
     XSLTElementDef unknownElement =
       new XSLTElementDef(this, "*", "unknown", null /*alias */,
                          templateElementsAndParams /* elements */,
@@ -291,20 +292,22 @@
                                                  xslUseAttributeSetsAttr,
                                                  xslVersionAttr,
                                                  xslResultAttr,
-                                                 resultAttr }, new ProcessorUnknown(),
-                                                               ElemUnknown.class /* class object */);
+                                                 resultAttr }, 
+												 new ProcessorUnknown(),
+                         ElemUnknown.class /* class object */, 20, true);
     XSLTElementDef xslValueOf = new XSLTElementDef(this,
                                   Constants.S_XSLNAMESPACEURL, "value-of",
                                   null /*alias */, null /* elements */,
                                   new XSLTAttributeDef[]{ selectAttrRequired,
-                                                          disableOutputEscapingAttr }, new ProcessorTemplateElem(),
-                                                                                       ElemValueOf.class /* class object */);
+                                                          disableOutputEscapingAttr }, 
+																	new ProcessorTemplateElem(),
+                                  ElemValueOf.class /* class object */, 20, true);
     XSLTElementDef xslCopyOf = new XSLTElementDef(this,
                                  Constants.S_XSLNAMESPACEURL, "copy-of",
                                  null /*alias */, null /* elements */,
                                  new XSLTAttributeDef[]{ selectAttrRequired },
                                  new ProcessorTemplateElem(),
-                                 ElemCopyOf.class /* class object */);
+                                 ElemCopyOf.class /* class object */, 20, true);
     XSLTElementDef xslNumber = new XSLTElementDef(this,
                                  Constants.S_XSLNAMESPACEURL, "number",
                                  null /*alias */, null /* elements */,
@@ -316,8 +319,9 @@
                                                          langAttr,
                                                          letterValueAttr,
                                                          groupingSeparatorAVT,
-                                                         groupingSizeAttr }, new ProcessorTemplateElem(),
-                                                                             ElemNumber.class /* class object */);
+                                                         groupingSizeAttr }, 
+																 new ProcessorTemplateElem(),
+                                 ElemNumber.class /* class object */, 20, true);
 
     // <!-- xsl:sort cannot occur after any other elements or
     // any non-whitespace character -->
@@ -330,8 +334,9 @@
                                                   langAttr,
                                                   dataTypeAttr,
                                                   orderAttr,
-                                                  caseOrderAttr }, new ProcessorTemplateElem(),
-                                                                   ElemSort.class /* class object */);
+                                                  caseOrderAttr }, 
+																								new ProcessorTemplateElem(),
+                                                ElemSort.class/* class object */, 19, true );
     XSLTElementDef xslWithParam = new XSLTElementDef(this,
                                     Constants.S_XSLNAMESPACEURL,
                                     "with-param", null /*alias */,
@@ -345,8 +350,9 @@
                                          new XSLTElementDef[]{ xslSort,
                                                                xslWithParam } /* elements */, new XSLTAttributeDef[]{
                                                                  selectAttrDefNode,
-                                                                 modeAttr }, new ProcessorTemplateElem(),
-                                                                             ElemApplyTemplates.class /* class object */);
+                                                                 modeAttr }, 
+																				 new ProcessorTemplateElem(),
+                                         ElemApplyTemplates.class /* class object */, 20, true);
     XSLTElementDef xslApplyImports =
       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "apply-imports",
                          null /*alias */, null /* elements */,
@@ -357,8 +363,9 @@
                                   Constants.S_XSLNAMESPACEURL, "for-each",
                                   null /*alias */, templateElementsAndSort,  // (#PCDATA %instructions; %result-elements; | xsl:sort)*
                                   new XSLTAttributeDef[]{ selectAttrRequired,
-                                                          spaceAttr }, new ProcessorTemplateElem(),
-                                                                       ElemForEach.class /* class object */);
+                                                          spaceAttr }, 
+																	new ProcessorTemplateElem(),
+                                  ElemForEach.class /* class object */, true, false, true, 20, true);
     XSLTElementDef xslIf = new XSLTElementDef(this,
                                               Constants.S_XSLNAMESPACEURL,
                                               "if", null /*alias */,
@@ -366,73 +373,79 @@
                                               new XSLTAttributeDef[]{
                                                 testAttrRequired,
                                                 spaceAttr }, new ProcessorTemplateElem(),
-                                                             ElemIf.class /* class object */);
+                                                             ElemIf.class /* class object */, 20, true);
     XSLTElementDef xslWhen =
       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "when",
                          null /*alias */, templateElements /* elements */,  // %template;>
                                                 new XSLTAttributeDef[]{
                                                   testAttrRequired,
                                                   spaceAttr }, new ProcessorTemplateElem(),
-                                                               ElemWhen.class /* class object */);
+                                                               ElemWhen.class /* class object */,
+																															 false, true, 1, true);
     XSLTElementDef xslOtherwise = new XSLTElementDef(this,
                                     Constants.S_XSLNAMESPACEURL, "otherwise",
                                     null /*alias */,
                                     templateElements /* elements */,  // %template;>
                                     new XSLTAttributeDef[]{ spaceAttr },
                                     new ProcessorTemplateElem(),
-                                    ElemOtherwise.class /* class object */);
+                                    ElemOtherwise.class /* class object */,
+																		false, false, 2, false);
     XSLTElementDef xslChoose = new XSLTElementDef(this,
                                  Constants.S_XSLNAMESPACEURL, "choose",
                                  null /*alias */,
                                  new XSLTElementDef[]{ xslWhen,
-                                       xslOtherwise } /* elements */, 
-                                new XSLTAttributeDef[]{ spaceAttr },
-                                              new ProcessorTemplateElem(),
-                                              ElemChoose.class /* class object */);
+                                                       xslOtherwise } /* elements */, 
+																 new XSLTAttributeDef[]{ spaceAttr },
+                                 new ProcessorTemplateElem(),
+                                 ElemChoose.class /* class object */, true, false, true, 20, true);                                
     XSLTElementDef xslAttribute = new XSLTElementDef(this,
                                     Constants.S_XSLNAMESPACEURL, "attribute",
                                     null /*alias */,
                                     charTemplateElements /* elements */,  // %char-template;>
                                     new XSLTAttributeDef[]{ nameAVTRequired,
                                                             namespaceAVTOpt,
-                                                            spaceAttr }, new ProcessorTemplateElem(),
-                                                                         ElemAttribute.class /* class object */);
+                                                            spaceAttr }, 
+																		new ProcessorTemplateElem(),
+                                    ElemAttribute.class /* class object */, 20, true);
     XSLTElementDef xslCallTemplate =
       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "call-template",
                          null /*alias */,
                          new XSLTElementDef[]{ xslWithParam } /* elements */,
                          new XSLTAttributeDef[]{ nameAttrRequired },
                          new ProcessorTemplateElem(),
-                         ElemCallTemplate.class /* class object */);
+                         ElemCallTemplate.class /* class object */, 20, true);
     XSLTElementDef xslVariable = new XSLTElementDef(this,
                                    Constants.S_XSLNAMESPACEURL, "variable",
                                    null /*alias */,
                                    templateElements /* elements */,  // %template;>
                                    new XSLTAttributeDef[]{ nameAttrRequired,
-                                                           selectAttrOpt }, new ProcessorTemplateElem(),
-                                                                            ElemVariable.class /* class object */);
+                                                           selectAttrOpt }, 
+																	 new ProcessorTemplateElem(),
+                                   ElemVariable.class /* class object */, 20, true);
     XSLTElementDef xslParam = new XSLTElementDef(this,
                                 Constants.S_XSLNAMESPACEURL, "param",
                                 null /*alias */,
                                 templateElements /* elements */,  // %template;>
                                 new XSLTAttributeDef[]{ nameAttrRequired,
-                                                        selectAttrOpt }, new ProcessorTemplateElem(),
-                                                                         ElemParam.class /* class object */);
+                                                        selectAttrOpt }, 
+																new ProcessorTemplateElem(),
+                                ElemParam.class /* class object */, 19, true);
     XSLTElementDef xslText =
       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "text",
                          null /*alias */,
                          new XSLTElementDef[]{ charData } /* elements */,
                          new XSLTAttributeDef[]{ disableOutputEscapingAttr },
                          new ProcessorText(),
-                         ElemText.class /* class object */);
+                         ElemText.class /* class object */, 20, true);
     XSLTElementDef xslProcessingInstruction =
       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL,
                          "processing-instruction", null /*alias */,
                          charTemplateElements /* elements */,  // %char-template;>
-                                                new XSLTAttributeDef[]{
+                         new XSLTAttributeDef[]{
                                                   nameAVTRequired,
-                                                  spaceAttr }, new ProcessorTemplateElem(),
-                                                               ElemPI.class /* class object */);
+                                                  spaceAttr }, 
+													new ProcessorTemplateElem(),
+                          ElemPI.class /* class object */, 20, true);
     XSLTElementDef xslElement = new XSLTElementDef(this,
                                   Constants.S_XSLNAMESPACEURL, "element",
                                   null /*alias */,
@@ -440,36 +453,38 @@
                                   new XSLTAttributeDef[]{ nameAVTRequired,
                                                           namespaceAVTOpt,
                                                           useAttributeSetsAttr,
-                                                          spaceAttr }, new ProcessorTemplateElem(),
-                                                                       ElemElement.class /* class object */);
+                                                          spaceAttr }, 
+																	new ProcessorTemplateElem(),
+                                  ElemElement.class /* class object */, 20, true);
     XSLTElementDef xslComment = new XSLTElementDef(this,
                                   Constants.S_XSLNAMESPACEURL, "comment",
                                   null /*alias */,
                                   charTemplateElements /* elements */,  // %char-template;>
                                   new XSLTAttributeDef[]{ spaceAttr },
                                   new ProcessorTemplateElem(),
-                                  ElemComment.class /* class object */);
+                                  ElemComment.class /* class object */, 20, true);
     XSLTElementDef xslCopy =
       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "copy",
                          null /*alias */, templateElements /* elements */,  // %template;>
-                                                new XSLTAttributeDef[]{
+                          new XSLTAttributeDef[]{
                                                   spaceAttr,
-                                                  useAttributeSetsAttr }, new ProcessorTemplateElem(),
-                                                                          ElemCopy.class /* class object */);
+                                                  useAttributeSetsAttr }, 
+													new ProcessorTemplateElem(),
+                          ElemCopy.class /* class object */, 20, true);
     XSLTElementDef xslMessage = new XSLTElementDef(this,
                                   Constants.S_XSLNAMESPACEURL, "message",
                                   null /*alias */,
                                   templateElements /* elements */,  // %template;>
                                   new XSLTAttributeDef[]{ terminateAttr },
                                   new ProcessorTemplateElem(),
-                                  ElemMessage.class /* class object */);
+                                  ElemMessage.class /* class object */, 20, true);
     XSLTElementDef xslFallback = new XSLTElementDef(this,
                                    Constants.S_XSLNAMESPACEURL, "fallback",
                                    null /*alias */,
                                    templateElements /* elements */,  // %template;>
                                    new XSLTAttributeDef[]{ spaceAttr },
                                    new ProcessorTemplateElem(),
-                                   ElemFallback.class /* class object */);
+                                   ElemFallback.class /* class object */, 20, true);
     int i = 0;
 
     templateElements[i++] = charData;  // #PCDATA
@@ -537,13 +552,15 @@
                                  null /*alias */, null /* elements */,
                                  new XSLTAttributeDef[]{ hrefAttr },  // EMPTY
                                  new ProcessorImport(),
-                                 null /* class object */);
+                                 null /* class object */,
+																 1, true);
     XSLTElementDef includeDef = new XSLTElementDef(this,
                                   Constants.S_XSLNAMESPACEURL, "include",
                                   null /*alias */, null /* elements */,  // EMPTY
                                   new XSLTAttributeDef[]{ hrefAttr },
                                   new ProcessorInclude(),
-                                  null /* class object */);
+                                  null /* class object */,
+																	2, true);
     XSLTElementDef[] topLevelElements = new XSLTElementDef[]{ includeDef,
                                                               importDef,
                                                               // resultElement,
@@ -558,7 +575,7 @@
                                                                 new XSLTAttributeDef[]{
                                                                 elementsAttr },
                                                                 new ProcessorStripSpace(),
-                                                                null /* class object */),
+                                                                null /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -568,7 +585,7 @@
                                                                 new XSLTAttributeDef[]{
                                                                 elementsAttr },
                                                                 new ProcessorPreserveSpace(),
-                                                                null /* class object */),
+                                                                null /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -587,15 +604,17 @@
                                                                   indentAttr,
                                                                   mediaTypeAttr,
                                                                   XSLTAttributeDef.m_foreignAttr }, 
-                                                                  new ProcessorOutputElem(), null /* class object */), new XSLTElementDef(
+                                                                new ProcessorOutputElem(), null /* class object */, 20, true), 
+																				                      new XSLTElementDef(
                                                                     this,
                                                                     Constants.S_XSLNAMESPACEURL,
                                                                     "key",
                                                                     null /*alias */,
                                                                     null /* elements */,  // EMPTY
-                                                                                                                                                                                                                                                                                     new XSLTAttributeDef[]{ nameAttrRequired,
-                                                                                                                                                                                                                                                                                                             matchAttrRequired,
-                                                                                                                                                                                                                                                                                                             useAttr }, new ProcessorKey(), null /* class object */),
+                                                                    new XSLTAttributeDef[]{ nameAttrRequired,
+                                                                                            matchAttrRequired,
+                                                                                            useAttr }, 
+																				                        new ProcessorKey(), null /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -613,8 +632,9 @@
                                                                                    perMilleAttr,
                                                                                    zeroDigitAttr,
                                                                                    digitAttr,
-                                                                                   patternSeparatorAttr }, new ProcessorDecimalFormat(),
-                                                                                                           null /* class object */),
+                                                                                   patternSeparatorAttr }, 
+																				                        new ProcessorDecimalFormat(),
+                                                                null /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -625,7 +645,7 @@
                                                                 new XSLTAttributeDef[]{
                                                                   nameAttrRequired,
                                                                   useAttributeSetsAttr }, new ProcessorAttributeSet(),
-                                                                                          null /* class object */),
+                                                                                          null /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -635,7 +655,7 @@
                                                                 new XSLTAttributeDef[]{
                                                                   nameAttrRequired,
                                                                   selectAttrOpt }, new ProcessorGlobalVariableDecl(),
-                                                                                   ElemVariable.class /* class object */),
+                                                                                   ElemVariable.class /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -645,7 +665,7 @@
                                                                 new XSLTAttributeDef[]{
                                                                   nameAttrRequired,
                                                                   selectAttrOpt }, new ProcessorGlobalParamDecl(),
-                                                                                   ElemParam.class /* class object */),
+                                                                                   ElemParam.class /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_XSLNAMESPACEURL,
@@ -657,14 +677,16 @@
                                                                   nameAttrOpt,
                                                                   priorityAttr,
                                                                   modeAttr,
-                                                                  spaceAttr }, new ProcessorTemplate(), ElemTemplate.class /* class object */), new XSLTElementDef(
+                                                                  spaceAttr }, new ProcessorTemplate(), ElemTemplate.class /* class object */, 20, true), 
+																				                      new XSLTElementDef(
                                                                     this,
                                                                     Constants.S_XSLNAMESPACEURL,
                                                                     "namespace-alias",
                                                                     null /*alias */,
                                                                     null /* elements */,  // EMPTY
-                                                                                                                                                                                                                                                                                                                    new XSLTAttributeDef[]{ stylesheetPrefixAttr,
-                                                                                                                                                                                                                                                                                                                                            resultPrefixAttr }, new ProcessorNamespaceAlias(), null /* class object */),
+                                                                    new XSLTAttributeDef[]{ stylesheetPrefixAttr,
+                                                                                            resultPrefixAttr }, 
+																				                            new ProcessorNamespaceAlias(), null /* class object */, 20, true),
                                                               new XSLTElementDef(
                                                                 this,
                                                                 Constants.S_BUILTIN_EXTENSIONS_URL,
@@ -683,8 +705,9 @@
                                                                         "lang",
                                                                         XSLTAttributeDef.T_NMTOKEN,
                                                                         true),
-                                                                      new XSLTAttributeDef(null, "src", XSLTAttributeDef.T_URL, false) }, new ProcessorLRE(),
-                                                                                                                                          ElemExtensionScript.class /* class object */) },  // EMPTY
+                                                                      new XSLTAttributeDef(null, "src", XSLTAttributeDef.T_URL, false) }, 
+																				                           new ProcessorLRE(),
+                                                                   ElemExtensionScript.class /* class object */, 20, true) },  // EMPTY
                                                                                                                                                                                                                                                                                                                                                 new XSLTAttributeDef[]{ new XSLTAttributeDef(null, "prefix", XSLTAttributeDef.T_NMTOKEN, true),
                                                                                                                                                                                                                                                                                                                                                                         new XSLTAttributeDef(null, "elements", XSLTAttributeDef.T_STRINGLIST, false),
                                                                                                                                                                                                                                                                                                                                                                         new XSLTAttributeDef(null, "functions", XSLTAttributeDef.T_STRINGLIST, false) }, new ProcessorLRE(), ElemExtensionDecl.class /* class object */) };
@@ -710,8 +733,8 @@
                                            idAttr,
                                            versionAttrRequired,
                                            spaceAttr }, new ProcessorStylesheetElement(),  /* ContentHandler */
-                                                                                                                                                                               null  /* class object */
-                                                                                                                                                                                 );
+                                         null  /* class object */,
+                                         true, -1, false);
 
     importDef.setElements(new XSLTElementDef[]{ stylesheetElemDef,
                                                 resultElement,