001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: XSLTSchema.java 476466 2006-11-18 08:22:31Z minchau $
020     */
021    package org.apache.xalan.processor;
022    
023    import java.util.HashMap;
024    
025    import org.apache.xalan.templates.Constants;
026    import org.apache.xalan.templates.ElemApplyImport;
027    import org.apache.xalan.templates.ElemApplyTemplates;
028    import org.apache.xalan.templates.ElemAttribute;
029    import org.apache.xalan.templates.ElemCallTemplate;
030    import org.apache.xalan.templates.ElemChoose;
031    import org.apache.xalan.templates.ElemComment;
032    import org.apache.xalan.templates.ElemCopy;
033    import org.apache.xalan.templates.ElemCopyOf;
034    import org.apache.xalan.templates.ElemElement;
035    import org.apache.xalan.templates.ElemExsltFuncResult;
036    import org.apache.xalan.templates.ElemExsltFunction;
037    import org.apache.xalan.templates.ElemExtensionDecl;
038    import org.apache.xalan.templates.ElemExtensionScript;
039    import org.apache.xalan.templates.ElemFallback;
040    import org.apache.xalan.templates.ElemForEach;
041    import org.apache.xalan.templates.ElemIf;
042    import org.apache.xalan.templates.ElemLiteralResult;
043    import org.apache.xalan.templates.ElemMessage;
044    import org.apache.xalan.templates.ElemNumber;
045    import org.apache.xalan.templates.ElemOtherwise;
046    import org.apache.xalan.templates.ElemPI;
047    import org.apache.xalan.templates.ElemParam;
048    import org.apache.xalan.templates.ElemSort;
049    import org.apache.xalan.templates.ElemTemplate;
050    import org.apache.xalan.templates.ElemText;
051    import org.apache.xalan.templates.ElemTextLiteral;
052    import org.apache.xalan.templates.ElemUnknown;
053    import org.apache.xalan.templates.ElemValueOf;
054    import org.apache.xalan.templates.ElemVariable;
055    import org.apache.xalan.templates.ElemWhen;
056    import org.apache.xalan.templates.ElemWithParam;
057    import org.apache.xml.utils.QName;
058    
059    /**
060     * This class defines the allowed structure for a stylesheet, and the
061     * mapping between Xalan classes and the markup elements in the stylesheet.
062     * @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
063     */
064    public class XSLTSchema extends XSLTElementDef
065    {
066    
067      /**
068       * Construct a XSLTSchema which represents the XSLT "schema".
069       */
070      XSLTSchema()
071      {
072        build();
073      }
074    
075      /**
076       * This method builds an XSLT "schema" according to http://www.w3.org/TR/xslt#dtd.  This
077       * schema provides instructions for building the Xalan Stylesheet (Templates) structure.
078       */
079      void build()
080      {
081            // xsl:import, xsl:include
082        XSLTAttributeDef hrefAttr = new XSLTAttributeDef(null, "href",
083                                      XSLTAttributeDef.T_URL, true, false,XSLTAttributeDef.ERROR);
084                                      
085            // xsl:preserve-space, xsl:strip-space
086        XSLTAttributeDef elementsAttr = new XSLTAttributeDef(null, "elements",
087                                          XSLTAttributeDef.T_SIMPLEPATTERNLIST,
088                                          true, false, XSLTAttributeDef.ERROR);
089                                          
090        // XSLTAttributeDef anyNamespacedAttr = new XSLTAttributeDef("*", "*",
091        //                                XSLTAttributeDef.T_CDATA, false);
092        
093        // xsl:output
094        XSLTAttributeDef methodAttr = new XSLTAttributeDef(null, "method",
095                                        XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR);
096        XSLTAttributeDef versionAttr = new XSLTAttributeDef(null, "version",
097                                         XSLTAttributeDef.T_NMTOKEN, false, false,XSLTAttributeDef.ERROR);
098        XSLTAttributeDef encodingAttr = new XSLTAttributeDef(null, "encoding",
099                                          XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
100        XSLTAttributeDef omitXmlDeclarationAttr = new XSLTAttributeDef(null,
101                                                    "omit-xml-declaration",
102                                                    XSLTAttributeDef.T_YESNO,
103                                                    false, false,XSLTAttributeDef.ERROR);
104        XSLTAttributeDef standaloneAttr = new XSLTAttributeDef(null,
105                                            "standalone",
106                                            XSLTAttributeDef.T_YESNO, false, false,XSLTAttributeDef.ERROR);
107        XSLTAttributeDef doctypePublicAttr = new XSLTAttributeDef(null,
108                                               "doctype-public",
109                                               XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
110        XSLTAttributeDef doctypeSystemAttr = new XSLTAttributeDef(null,
111                                               "doctype-system",
112                                               XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
113        XSLTAttributeDef cdataSectionElementsAttr = new XSLTAttributeDef(null,
114                                                      "cdata-section-elements",
115                                                      XSLTAttributeDef.T_QNAMES_RESOLVE_NULL,
116                                                      false, false,XSLTAttributeDef.ERROR);
117        XSLTAttributeDef indentAttr = new XSLTAttributeDef(null, "indent",
118                                        XSLTAttributeDef.T_YESNO, false, false,XSLTAttributeDef.ERROR);
119        XSLTAttributeDef mediaTypeAttr = new XSLTAttributeDef(null, "media-type",
120                                           XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
121                                           
122                      
123        // Required.
124        // It is an error if the name attribute is invalid on any of these elements
125        // xsl:key, xsl:attribute-set, xsl:call-template, xsl:with-param, xsl:variable, xsl:param
126        XSLTAttributeDef nameAttrRequired = new XSLTAttributeDef(null, "name",
127                                              XSLTAttributeDef.T_QNAME, true, false,XSLTAttributeDef.ERROR);
128            // Required.
129        // Support AVT
130        // xsl:element, xsl:attribute                                    
131        XSLTAttributeDef nameAVTRequired = new XSLTAttributeDef(null, "name",
132                                             XSLTAttributeDef.T_AVT_QNAME, true, true,XSLTAttributeDef.WARNING);
133                
134    
135        // Required.
136        // Support AVT
137        // xsl:processing-instruction                                     
138        XSLTAttributeDef nameAVT_NCNAMERequired = new XSLTAttributeDef(null, "name",
139                                             XSLTAttributeDef.T_NCNAME, true, true,XSLTAttributeDef.WARNING);
140                                            
141        // Optional.
142        // Static error if invalid
143        // xsl:template, xsl:decimal-format                                      
144        XSLTAttributeDef nameAttrOpt_ERROR = new XSLTAttributeDef(null, "name",
145                                         XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR);
146    
147        // xsl:key                                 
148        XSLTAttributeDef useAttr = new XSLTAttributeDef(null, "use",
149                                     XSLTAttributeDef.T_EXPR, true, false,XSLTAttributeDef.ERROR);
150               
151        // xsl:element, xsl:attribute                              
152        XSLTAttributeDef namespaceAVTOpt = new XSLTAttributeDef(null,
153                                             "namespace",XSLTAttributeDef.T_URL,
154                                             false, true,XSLTAttributeDef.WARNING);
155        // xsl:decimal-format                                     
156        XSLTAttributeDef decimalSeparatorAttr = new XSLTAttributeDef(null,
157                                                  "decimal-separator",
158                                                  XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, ".");
159        XSLTAttributeDef infinityAttr = new XSLTAttributeDef(null, "infinity",
160                                          XSLTAttributeDef.T_CDATA, false,XSLTAttributeDef.ERROR,"Infinity");
161        XSLTAttributeDef minusSignAttr = new XSLTAttributeDef(null, "minus-sign",
162                                           XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR,"-");
163        XSLTAttributeDef NaNAttr = new XSLTAttributeDef(null, "NaN",
164                                     XSLTAttributeDef.T_CDATA, false,XSLTAttributeDef.ERROR, "NaN");
165        XSLTAttributeDef percentAttr = new XSLTAttributeDef(null, "percent",
166                                         XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, "%");
167        XSLTAttributeDef perMilleAttr = new XSLTAttributeDef(null, "per-mille",
168                                          XSLTAttributeDef.T_CHAR,
169                                          false, false,XSLTAttributeDef.ERROR /* ,"&#x2030;" */);
170        XSLTAttributeDef zeroDigitAttr = new XSLTAttributeDef(null, "zero-digit",
171                                           XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, "0");
172        XSLTAttributeDef digitAttr = new XSLTAttributeDef(null, "digit",
173                                       XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, "#");
174        XSLTAttributeDef patternSeparatorAttr = new XSLTAttributeDef(null,
175                                                  "pattern-separator",
176                                                  XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, ";");
177        // xsl:decimal-format                                         
178        XSLTAttributeDef groupingSeparatorAttr = new XSLTAttributeDef(null,
179                                                   "grouping-separator",
180                                                   XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR,",");
181    
182                                                  
183        // xsl:element, xsl:attribute-set, xsl:copy                                           
184        XSLTAttributeDef useAttributeSetsAttr = new XSLTAttributeDef(null,
185                                                  "use-attribute-sets",
186                                                  XSLTAttributeDef.T_QNAMES,
187                                                  false, false, XSLTAttributeDef.ERROR);
188    
189        // xsl:if, xsl:when         
190        XSLTAttributeDef testAttrRequired = new XSLTAttributeDef(null, "test",   
191                                              XSLTAttributeDef.T_EXPR, true, false,XSLTAttributeDef.ERROR);
192          
193          
194        // Required.                                       
195        // xsl:value-of, xsl:for-each, xsl:copy-of                             
196        XSLTAttributeDef selectAttrRequired = new XSLTAttributeDef(null,
197                                                "select",
198                                                XSLTAttributeDef.T_EXPR, true, false,XSLTAttributeDef.ERROR);
199    
200        // Optional.                                          
201        // xsl:variable, xsl:param, xsl:with-param                                       
202        XSLTAttributeDef selectAttrOpt = new XSLTAttributeDef(null, "select",
203                                           XSLTAttributeDef.T_EXPR, false, false,XSLTAttributeDef.ERROR);
204    
205        // Optional.
206        // Default: "node()"
207        // xsl:apply-templates                                           
208        XSLTAttributeDef selectAttrDefNode = new XSLTAttributeDef(null, "select",
209                                               XSLTAttributeDef.T_EXPR, false,XSLTAttributeDef.ERROR, "node()");
210        // Optional.
211        // Default: "."
212        // xsl:sort                                        
213        XSLTAttributeDef selectAttrDefDot = new XSLTAttributeDef(null, "select",
214                                              XSLTAttributeDef.T_EXPR, false,XSLTAttributeDef.ERROR, ".");
215        // xsl:key                                      
216        XSLTAttributeDef matchAttrRequired = new XSLTAttributeDef(null, "match",
217                                               XSLTAttributeDef.T_PATTERN, true, false,XSLTAttributeDef.ERROR);
218        // xsl:template                                       
219        XSLTAttributeDef matchAttrOpt = new XSLTAttributeDef(null, "match",
220                                          XSLTAttributeDef.T_PATTERN, false, false,XSLTAttributeDef.ERROR);
221        // xsl:template                                  
222        XSLTAttributeDef priorityAttr = new XSLTAttributeDef(null, "priority",
223                                         XSLTAttributeDef.T_NUMBER, false, false,XSLTAttributeDef.ERROR);
224                                         
225        // xsl:template, xsl:apply-templates                                 
226        XSLTAttributeDef modeAttr = new XSLTAttributeDef(null, "mode",
227                                         XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR);
228       
229        XSLTAttributeDef spaceAttr =
230          new XSLTAttributeDef(Constants.S_XMLNAMESPACEURI, "space", false, false, false, XSLTAttributeDef.WARNING,
231                               "default", Constants.ATTRVAL_STRIP, "preserve",
232                               Constants.ATTRVAL_PRESERVE);
233                               
234                             
235        XSLTAttributeDef spaceAttrLiteral =
236          new XSLTAttributeDef(Constants.S_XMLNAMESPACEURI, "space", 
237                                              XSLTAttributeDef.T_URL, false, true,XSLTAttributeDef.ERROR);
238        // xsl:namespace-alias                                      
239        XSLTAttributeDef stylesheetPrefixAttr = new XSLTAttributeDef(null,
240                                                  "stylesheet-prefix",
241                                                  XSLTAttributeDef.T_CDATA, true, false,XSLTAttributeDef.ERROR);
242        XSLTAttributeDef resultPrefixAttr = new XSLTAttributeDef(null,
243                                              "result-prefix",
244                                              XSLTAttributeDef.T_CDATA, true, false,XSLTAttributeDef.ERROR);
245                                              
246        // xsl:text, xsl:value-of                                      
247        XSLTAttributeDef disableOutputEscapingAttr = new XSLTAttributeDef(null,
248                                                       "disable-output-escaping",
249                                                       XSLTAttributeDef.T_YESNO,
250                                                       false, false,XSLTAttributeDef.ERROR);
251                                                       
252            // xsl:number                                                   
253        XSLTAttributeDef levelAttr = new XSLTAttributeDef(null, "level", false, false, false, XSLTAttributeDef.ERROR,
254                                       "single", Constants.NUMBERLEVEL_SINGLE,
255                                       "multiple", Constants.NUMBERLEVEL_MULTI,
256                                       "any", Constants.NUMBERLEVEL_ANY);
257        levelAttr.setDefault("single");
258        XSLTAttributeDef countAttr = new XSLTAttributeDef(null, "count",
259                                       XSLTAttributeDef.T_PATTERN, false, false,XSLTAttributeDef.ERROR);
260        XSLTAttributeDef fromAttr = new XSLTAttributeDef(null, "from",
261                                      XSLTAttributeDef.T_PATTERN, false, false,XSLTAttributeDef.ERROR);
262        XSLTAttributeDef valueAttr = new XSLTAttributeDef(null, "value",
263                                       XSLTAttributeDef.T_EXPR, false, false,XSLTAttributeDef.ERROR);
264        XSLTAttributeDef formatAttr = new XSLTAttributeDef(null, "format",
265                                        XSLTAttributeDef.T_CDATA, false, true,XSLTAttributeDef.ERROR);
266        formatAttr.setDefault("1");
267        
268        // xsl:number, xsl:sort
269        XSLTAttributeDef langAttr = new XSLTAttributeDef(null, "lang",
270                                      XSLTAttributeDef.T_NMTOKEN, false, true,XSLTAttributeDef.ERROR);
271       
272        // xsl:number
273        XSLTAttributeDef letterValueAttr = new XSLTAttributeDef(null,
274                                             "letter-value",
275                                             false, true, false, XSLTAttributeDef.ERROR,
276                                             "alphabetic", Constants.NUMBERLETTER_ALPHABETIC,
277                                             "traditional", Constants.NUMBERLETTER_TRADITIONAL);
278        // xsl:number
279        XSLTAttributeDef groupingSeparatorAVT = new XSLTAttributeDef(null,
280                                                  "grouping-separator",
281                                                  XSLTAttributeDef.T_CHAR, false, true,XSLTAttributeDef.ERROR);
282        // xsl:number
283        XSLTAttributeDef groupingSizeAttr = new XSLTAttributeDef(null,
284                                              "grouping-size",
285                                              XSLTAttributeDef.T_NUMBER, false, true,XSLTAttributeDef.ERROR);
286       
287       // xsl:sort
288        XSLTAttributeDef dataTypeAttr = new XSLTAttributeDef(null, "data-type", false, true, true, XSLTAttributeDef.ERROR,
289                                        "text", Constants.SORTDATATYPE_TEXT ,"number", Constants.SORTDATATYPE_TEXT);
290            dataTypeAttr.setDefault("text");
291            
292            // xsl:sort
293        XSLTAttributeDef orderAttr = new XSLTAttributeDef(null, "order", false, true, false,XSLTAttributeDef.ERROR,
294                                        "ascending", Constants.SORTORDER_ASCENDING, 
295                                        "descending", Constants.SORTORDER_DESCENDING);
296        orderAttr.setDefault("ascending");
297    
298        // xsl:sort                             
299        XSLTAttributeDef caseOrderAttr = new XSLTAttributeDef(null, "case-order", false, true, false,XSLTAttributeDef.ERROR,
300                                           "upper-first", Constants.SORTCASEORDER_UPPERFIRST ,
301                                           "lower-first", Constants.SORTCASEORDER_LOWERFIRST);
302                
303        // xsl:message                                   
304        XSLTAttributeDef terminateAttr = new XSLTAttributeDef(null, "terminate",
305                                           XSLTAttributeDef.T_YESNO, false, false,XSLTAttributeDef.ERROR);
306        terminateAttr.setDefault("no");
307    
308            // top level attributes
309        XSLTAttributeDef xslExcludeResultPrefixesAttr =
310          new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL,
311                               "exclude-result-prefixes",
312                               XSLTAttributeDef.T_PREFIXLIST, false, false,XSLTAttributeDef.ERROR);
313        XSLTAttributeDef xslExtensionElementPrefixesAttr =
314          new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL,
315                               "extension-element-prefixes",
316                               XSLTAttributeDef.T_PREFIX_URLLIST, false, false,XSLTAttributeDef.ERROR);
317        // result-element-atts                       
318        XSLTAttributeDef xslUseAttributeSetsAttr =
319          new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "use-attribute-sets",
320                               XSLTAttributeDef.T_QNAMES, false, false,XSLTAttributeDef.ERROR);
321        XSLTAttributeDef xslVersionAttr =
322          new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "version",
323                               XSLTAttributeDef.T_NMTOKEN, false, false,XSLTAttributeDef.ERROR);
324                               
325        XSLTElementDef charData = new XSLTElementDef(this, null, "text()",
326                                    null /*alias */, null /* elements */, null,  /* attributes */
327                                    new ProcessorCharacters(),
328                                    ElemTextLiteral.class /* class object */);
329    
330        charData.setType(XSLTElementDef.T_PCDATA);
331    
332        XSLTElementDef whiteSpaceOnly = new XSLTElementDef(this, null, "text()",
333                                          null /*alias */, null /* elements */,
334                                          null,  /* attributes */
335                                          null,
336                                          ElemTextLiteral.class /* should be null? -sb */);
337    
338        charData.setType(XSLTElementDef.T_PCDATA);
339    
340        XSLTAttributeDef resultAttr = new XSLTAttributeDef(null, "*",
341                                        XSLTAttributeDef.T_AVT, false, true,XSLTAttributeDef.WARNING);
342        XSLTAttributeDef xslResultAttr =
343          new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "*",
344                               XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.WARNING);
345                               
346        XSLTElementDef[] templateElements = new XSLTElementDef[23];
347        XSLTElementDef[] templateElementsAndParams = new XSLTElementDef[24];
348        XSLTElementDef[] templateElementsAndSort = new XSLTElementDef[24];
349        //exslt
350        XSLTElementDef[] exsltFunctionElements = new XSLTElementDef[24];
351        
352        XSLTElementDef[] charTemplateElements = new XSLTElementDef[15];
353        XSLTElementDef resultElement = new XSLTElementDef(this, null, "*",
354                                         null /*alias */,
355                                         templateElements /* elements */,
356                                         new XSLTAttributeDef[]{
357                                           spaceAttrLiteral, // special
358                                           xslExcludeResultPrefixesAttr,
359                                           xslExtensionElementPrefixesAttr,
360                                           xslUseAttributeSetsAttr,
361                                           xslVersionAttr,
362                                           xslResultAttr,
363                                           resultAttr }, 
364                                            new ProcessorLRE(),
365                                         ElemLiteralResult.class /* class object */, 20, true);
366        XSLTElementDef unknownElement =
367          new XSLTElementDef(this, "*", "unknown", null /*alias */,
368                             templateElementsAndParams /* elements */,
369                             new XSLTAttributeDef[]{ xslExcludeResultPrefixesAttr,
370                                                     xslExtensionElementPrefixesAttr,
371                                                     xslUseAttributeSetsAttr,
372                                                     xslVersionAttr,
373                                                     xslResultAttr,
374                                                     resultAttr }, 
375                                                                                                     new ProcessorUnknown(),
376                             ElemUnknown.class /* class object */, 20, true);
377        XSLTElementDef xslValueOf = new XSLTElementDef(this,
378                                      Constants.S_XSLNAMESPACEURL, "value-of",
379                                      null /*alias */, null /* elements */,
380                                      new XSLTAttributeDef[]{ selectAttrRequired,
381                                                              disableOutputEscapingAttr }, 
382                                                   new ProcessorTemplateElem(),
383                                      ElemValueOf.class /* class object */, 20, true);
384        XSLTElementDef xslCopyOf = new XSLTElementDef(this,
385                                     Constants.S_XSLNAMESPACEURL, "copy-of",
386                                     null /*alias */, null /* elements */,
387                                     new XSLTAttributeDef[]{ selectAttrRequired },
388                                     new ProcessorTemplateElem(),
389                                     ElemCopyOf.class /* class object */, 20, true);
390        XSLTElementDef xslNumber = new XSLTElementDef(this,
391                                     Constants.S_XSLNAMESPACEURL, "number",
392                                     null /*alias */, null /* elements */,
393                                     new XSLTAttributeDef[]{ levelAttr,
394                                                             countAttr,
395                                                             fromAttr,
396                                                             valueAttr,
397                                                             formatAttr,
398                                                             langAttr,
399                                                             letterValueAttr,
400                                                             groupingSeparatorAVT,
401                                                             groupingSizeAttr }, 
402                                            new ProcessorTemplateElem(),
403                                     ElemNumber.class /* class object */, 20, true);
404    
405        // <!-- xsl:sort cannot occur after any other elements or
406        // any non-whitespace character -->
407        XSLTElementDef xslSort = new XSLTElementDef(this,
408                                                    Constants.S_XSLNAMESPACEURL,
409                                                    "sort", null /*alias */,
410                                                    null /* elements */,
411                                                    new XSLTAttributeDef[]{
412                                                      selectAttrDefDot,
413                                                      langAttr,
414                                                      dataTypeAttr,
415                                                      orderAttr,
416                                                      caseOrderAttr }, 
417                                           new ProcessorTemplateElem(),
418                                                    ElemSort.class/* class object */, 19, true );
419        XSLTElementDef xslWithParam = new XSLTElementDef(this,
420                                        Constants.S_XSLNAMESPACEURL,
421                                        "with-param", null /*alias */,
422                                        templateElements /* elements */,  // %template;>
423                                        new XSLTAttributeDef[]{ nameAttrRequired,
424                                                                selectAttrOpt }, new ProcessorTemplateElem(),
425                                                                                 ElemWithParam.class /* class object */, 19, true);
426        XSLTElementDef xslApplyTemplates = new XSLTElementDef(this,
427                                             Constants.S_XSLNAMESPACEURL,
428                                             "apply-templates", null /*alias */,
429                                             new XSLTElementDef[]{ xslSort,
430                                                                   xslWithParam } /* elements */, new XSLTAttributeDef[]{
431                                                                     selectAttrDefNode,
432                                                                     modeAttr }, 
433                                                                            new ProcessorTemplateElem(),
434                                             ElemApplyTemplates.class /* class object */, 20, true);
435        XSLTElementDef xslApplyImports =
436          new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "apply-imports",
437                             null /*alias */, null /* elements */,
438                             new XSLTAttributeDef[]{},
439                             new ProcessorTemplateElem(),
440                             ElemApplyImport.class /* class object */);
441        XSLTElementDef xslForEach = new XSLTElementDef(this,
442                                      Constants.S_XSLNAMESPACEURL, "for-each",
443                                      null /*alias */, templateElementsAndSort,  // (#PCDATA %instructions; %result-elements; | xsl:sort)*
444                                      new XSLTAttributeDef[]{ selectAttrRequired,
445                                                              spaceAttr }, 
446                                                   new ProcessorTemplateElem(),
447                                      ElemForEach.class /* class object */, true, false, true, 20, true);
448        XSLTElementDef xslIf = new XSLTElementDef(this,
449                                                  Constants.S_XSLNAMESPACEURL,
450                                                  "if", null /*alias */,
451                                                  templateElements /* elements */,  // %template;
452                                                  new XSLTAttributeDef[]{
453                                                    testAttrRequired,
454                                                    spaceAttr }, new ProcessorTemplateElem(),
455                                                                 ElemIf.class /* class object */, 20, true);
456        XSLTElementDef xslWhen =
457          new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "when",
458                             null /*alias */, templateElements /* elements */,  // %template;>
459                                                    new XSLTAttributeDef[]{
460                                                      testAttrRequired,
461                                                      spaceAttr }, new ProcessorTemplateElem(),
462                                                                   ElemWhen.class /* class object */,
463                                                                                                    false, true, 1, true);
464        XSLTElementDef xslOtherwise = new XSLTElementDef(this,
465                                        Constants.S_XSLNAMESPACEURL, "otherwise",
466                                        null /*alias */,
467                                        templateElements /* elements */,  // %template;>
468                                        new XSLTAttributeDef[]{ spaceAttr },
469                                        new ProcessorTemplateElem(),
470                                        ElemOtherwise.class /* class object */,
471                                                           false, false, 2, false);
472        XSLTElementDef xslChoose = new XSLTElementDef(this,
473                                     Constants.S_XSLNAMESPACEURL, "choose",
474                                     null /*alias */,
475                                     new XSLTElementDef[]{ xslWhen,
476                                                           xslOtherwise } /* elements */, 
477                                            new XSLTAttributeDef[]{ spaceAttr },
478                                     new ProcessorTemplateElem(),
479                                     ElemChoose.class /* class object */, true, false, true, 20, true);                                
480        XSLTElementDef xslAttribute = new XSLTElementDef(this,
481                                        Constants.S_XSLNAMESPACEURL, "attribute",
482                                        null /*alias */,
483                                        charTemplateElements /* elements */,  // %char-template;>
484                                        new XSLTAttributeDef[]{ nameAVTRequired,
485                                                                namespaceAVTOpt,
486                                                                spaceAttr }, 
487                                        new ProcessorTemplateElem(),
488                                        ElemAttribute.class /* class object */, 20, true);
489        XSLTElementDef xslCallTemplate =
490          new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "call-template",
491                             null /*alias */,
492                             new XSLTElementDef[]{ xslWithParam } /* elements */,
493                             new XSLTAttributeDef[]{ nameAttrRequired },
494                             new ProcessorTemplateElem(),
495                             ElemCallTemplate.class /* class object */, 20, true);
496        XSLTElementDef xslVariable = new XSLTElementDef(this,
497                                       Constants.S_XSLNAMESPACEURL, "variable",
498                                       null /*alias */,
499                                       templateElements /* elements */,  // %template;>
500                                       new XSLTAttributeDef[]{ nameAttrRequired,
501                                                               selectAttrOpt }, 
502                                      new ProcessorTemplateElem(),
503                                       ElemVariable.class /* class object */, 20, true);
504        XSLTElementDef xslParam = new XSLTElementDef(this,
505                                    Constants.S_XSLNAMESPACEURL, "param",
506                                    null /*alias */,
507                                    templateElements /* elements */,  // %template;>
508                                    new XSLTAttributeDef[]{ nameAttrRequired,
509                                                            selectAttrOpt }, 
510                                           new ProcessorTemplateElem(),
511                                    ElemParam.class /* class object */, 19, true);
512        XSLTElementDef xslText =
513          new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "text",
514                             null /*alias */,
515                             new XSLTElementDef[]{ charData } /* elements */,
516                             new XSLTAttributeDef[]{ disableOutputEscapingAttr },
517                             new ProcessorText(),
518                             ElemText.class /* class object */, 20, true);
519        XSLTElementDef xslProcessingInstruction =
520          new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL,
521                             "processing-instruction", null /*alias */,
522                             charTemplateElements /* elements */,  // %char-template;>
523                             new XSLTAttributeDef[]{
524                                                      nameAVT_NCNAMERequired,
525                                                      spaceAttr }, 
526                                            new ProcessorTemplateElem(),
527                              ElemPI.class /* class object */, 20, true);
528        XSLTElementDef xslElement = new XSLTElementDef(this,
529                                      Constants.S_XSLNAMESPACEURL, "element",
530                                      null /*alias */,
531                                      templateElements /* elements */,  // %template;
532                                      new XSLTAttributeDef[]{ nameAVTRequired,
533                                                              namespaceAVTOpt,
534                                                              useAttributeSetsAttr,
535                                                              spaceAttr }, 
536                                                   new ProcessorTemplateElem(),
537                                      ElemElement.class /* class object */, 20, true);
538        XSLTElementDef xslComment = new XSLTElementDef(this,
539                                      Constants.S_XSLNAMESPACEURL, "comment",
540                                      null /*alias */,
541                                      charTemplateElements /* elements */,  // %char-template;>
542                                      new XSLTAttributeDef[]{ spaceAttr },
543                                      new ProcessorTemplateElem(),
544                                      ElemComment.class /* class object */, 20, true);
545        XSLTElementDef xslCopy =
546          new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "copy",
547                             null /*alias */, templateElements /* elements */,  // %template;>
548                              new XSLTAttributeDef[]{
549                                                      spaceAttr,
550                                                      useAttributeSetsAttr }, 
551                                            new ProcessorTemplateElem(),
552                              ElemCopy.class /* class object */, 20, true);
553        XSLTElementDef xslMessage = new XSLTElementDef(this,
554                                      Constants.S_XSLNAMESPACEURL, "message",
555                                      null /*alias */,
556                                      templateElements /* elements */,  // %template;>
557                                      new XSLTAttributeDef[]{ terminateAttr },
558                                      new ProcessorTemplateElem(),
559                                      ElemMessage.class /* class object */, 20, true);
560        XSLTElementDef xslFallback = new XSLTElementDef(this,
561                                       Constants.S_XSLNAMESPACEURL, "fallback",
562                                       null /*alias */,
563                                       templateElements /* elements */,  // %template;>
564                                       new XSLTAttributeDef[]{ spaceAttr },
565                                       new ProcessorTemplateElem(),
566                                       ElemFallback.class /* class object */, 20, true);
567        //exslt
568        XSLTElementDef exsltFunction =
569                                      new XSLTElementDef(this, 
570                                      Constants.S_EXSLT_FUNCTIONS_URL, 
571                                      "function",
572                                      null /*alias */,
573                                      exsltFunctionElements /* elements */,
574                                      new XSLTAttributeDef[]{ nameAttrRequired },
575                                      new ProcessorExsltFunction(),
576                                      ElemExsltFunction.class /* class object */);
577        XSLTElementDef exsltResult =
578                                      new XSLTElementDef(this, 
579                                      Constants.S_EXSLT_FUNCTIONS_URL, 
580                                      "result",
581                                      null /*alias */,
582                                      templateElements /* elements */,
583                                      new XSLTAttributeDef[]{ selectAttrOpt },
584                                      new ProcessorExsltFuncResult(),
585                                      ElemExsltFuncResult.class  /* class object */);            
586        
587    
588        int i = 0;
589    
590        templateElements[i++] = charData;  // #PCDATA
591    
592        // char-instructions
593        templateElements[i++] = xslApplyTemplates;
594        templateElements[i++] = xslCallTemplate;
595        templateElements[i++] = xslApplyImports;
596        templateElements[i++] = xslForEach;
597        templateElements[i++] = xslValueOf;
598        templateElements[i++] = xslCopyOf;
599        templateElements[i++] = xslNumber;
600        templateElements[i++] = xslChoose;
601        templateElements[i++] = xslIf;
602        templateElements[i++] = xslText;
603        templateElements[i++] = xslCopy;
604        templateElements[i++] = xslVariable;
605        templateElements[i++] = xslMessage;
606        templateElements[i++] = xslFallback;
607    
608        // instructions
609        templateElements[i++] = xslProcessingInstruction;
610        templateElements[i++] = xslComment;
611        templateElements[i++] = xslElement;
612        templateElements[i++] = xslAttribute;
613        templateElements[i++] = resultElement;
614        templateElements[i++] = unknownElement;
615        templateElements[i++] = exsltFunction;
616        templateElements[i++] = exsltResult;
617    
618        System.arraycopy(templateElements, 0, templateElementsAndParams, 0, i);
619        System.arraycopy(templateElements, 0, templateElementsAndSort, 0, i);
620        System.arraycopy(templateElements, 0, exsltFunctionElements, 0, i);
621        
622        templateElementsAndParams[i] = xslParam;
623        templateElementsAndSort[i] = xslSort;
624        exsltFunctionElements[i]   = xslParam;
625    
626        i = 0;
627        charTemplateElements[i++] = charData;  // #PCDATA
628    
629        // char-instructions
630        charTemplateElements[i++] = xslApplyTemplates;
631        charTemplateElements[i++] = xslCallTemplate;
632        charTemplateElements[i++] = xslApplyImports;
633        charTemplateElements[i++] = xslForEach;
634        charTemplateElements[i++] = xslValueOf;
635        charTemplateElements[i++] = xslCopyOf;
636        charTemplateElements[i++] = xslNumber;
637        charTemplateElements[i++] = xslChoose;
638        charTemplateElements[i++] = xslIf;
639        charTemplateElements[i++] = xslText;
640        charTemplateElements[i++] = xslCopy;
641        charTemplateElements[i++] = xslVariable;
642        charTemplateElements[i++] = xslMessage;
643        charTemplateElements[i++] = xslFallback;
644    
645        XSLTElementDef importDef = new XSLTElementDef(this,
646                                     Constants.S_XSLNAMESPACEURL, "import",
647                                     null /*alias */, null /* elements */,
648                                     new XSLTAttributeDef[]{ hrefAttr },  // EMPTY
649                                     new ProcessorImport(),
650                                     null /* class object */,
651                                            1, true);
652        XSLTElementDef includeDef = new XSLTElementDef(this,
653                                      Constants.S_XSLNAMESPACEURL, "include",
654                                      null /*alias */, null /* elements */,  // EMPTY
655                                      new XSLTAttributeDef[]{ hrefAttr },
656                                      new ProcessorInclude(),
657                                      null /* class object */,
658                                                   20, true);
659        
660        XSLTAttributeDef[] scriptAttrs = new XSLTAttributeDef[]{
661                                                new XSLTAttributeDef(null, "lang", XSLTAttributeDef.T_NMTOKEN,
662                                                                     true, false,XSLTAttributeDef.WARNING),
663                                                new XSLTAttributeDef(null, "src", XSLTAttributeDef.T_URL, 
664                                                                     false, false,XSLTAttributeDef.WARNING)};
665    
666        XSLTAttributeDef[] componentAttrs = new XSLTAttributeDef[]{ 
667                                                new XSLTAttributeDef(null, "prefix", XSLTAttributeDef.T_NMTOKEN, 
668                                                                     true, false,XSLTAttributeDef.WARNING),
669                                                new XSLTAttributeDef(null, "elements", XSLTAttributeDef.T_STRINGLIST, 
670                                                                     false, false,XSLTAttributeDef.WARNING),
671                                                new XSLTAttributeDef(null, "functions", XSLTAttributeDef.T_STRINGLIST, 
672                                                                     false, false,XSLTAttributeDef.WARNING) };
673    
674        XSLTElementDef[] topLevelElements = new XSLTElementDef[]
675                                     {includeDef,
676                                      importDef,
677                                      // resultElement,
678                                      whiteSpaceOnly,
679                                      unknownElement,
680                                      new XSLTElementDef(
681                                             this,
682                                             Constants.S_XSLNAMESPACEURL,
683                                             "strip-space",
684                                             null /*alias */,
685                                             null /* elements */,
686                                             new XSLTAttributeDef[]{
687                                                    elementsAttr },
688                                                    new ProcessorStripSpace(),
689                                             null /* class object */, 20, true),
690                                      new XSLTElementDef(
691                                             this,
692                                             Constants.S_XSLNAMESPACEURL,
693                                             "preserve-space",
694                                             null /*alias */,
695                                             null /* elements */,
696                                             new XSLTAttributeDef[]{
697                                                     elementsAttr },
698                                                     new ProcessorPreserveSpace(),
699                                             null /* class object */, 20, true),
700                                      new XSLTElementDef(
701                                             this,
702                                             Constants.S_XSLNAMESPACEURL,
703                                             "output",
704                                             null /*alias */,
705                                             null /* elements */,
706                                             new XSLTAttributeDef[]{
707                                                      methodAttr,
708                                                      versionAttr,
709                                                      encodingAttr,
710                                                      omitXmlDeclarationAttr,
711                                                      standaloneAttr,
712                                                      doctypePublicAttr,
713                                                      doctypeSystemAttr,
714                                                      cdataSectionElementsAttr,
715                                                      indentAttr,
716                                                      mediaTypeAttr,
717                                                      XSLTAttributeDef.m_foreignAttr }, 
718                                              new ProcessorOutputElem(), null /* class object */, 20, true), 
719                                      new XSLTElementDef(
720                                              this,
721                                              Constants.S_XSLNAMESPACEURL,
722                                              "key",
723                                              null /*alias */,
724                                              null /* elements */,  // EMPTY
725                                              new XSLTAttributeDef[]{ nameAttrRequired,
726                                                      matchAttrRequired,
727                                                      useAttr }, 
728                                              new ProcessorKey(), null /* class object */, 20, true),
729                                      new XSLTElementDef(
730                                              this,
731                                              Constants.S_XSLNAMESPACEURL,
732                                              "decimal-format",
733                                              null /*alias */,
734                                              null /* elements */,  // EMPTY
735                                              new XSLTAttributeDef[]{
736                                                      nameAttrOpt_ERROR,
737                                                      decimalSeparatorAttr,
738                                                      groupingSeparatorAttr,
739                                                      infinityAttr,
740                                                      minusSignAttr,
741                                                      NaNAttr,
742                                                      percentAttr,
743                                                      perMilleAttr,
744                                                      zeroDigitAttr,
745                                                      digitAttr,
746                                                      patternSeparatorAttr }, 
747                                               new ProcessorDecimalFormat(),
748                                               null /* class object */, 20, true),
749                                      new XSLTElementDef(
750                                               this,
751                                               Constants.S_XSLNAMESPACEURL,
752                                               "attribute-set",
753                                               null /*alias */,
754                                               new XSLTElementDef[]{
755                                                       xslAttribute } /* elements */,
756                                               new XSLTAttributeDef[]{
757                                                       nameAttrRequired,
758                                                       useAttributeSetsAttr }, 
759                                               new ProcessorAttributeSet(),
760                                               null /* class object */, 20, true),
761                                      new XSLTElementDef(
762                                               this,
763                                               Constants.S_XSLNAMESPACEURL,
764                                               "variable",
765                                               null /*alias */,
766                                               templateElements /* elements */,
767                                               new XSLTAttributeDef[]{
768                                                       nameAttrRequired,
769                                                       selectAttrOpt }, 
770                                               new ProcessorGlobalVariableDecl(),
771                                               ElemVariable.class /* class object */, 20, true),
772                                      new XSLTElementDef(
773                                               this,
774                                               Constants.S_XSLNAMESPACEURL,
775                                               "param",
776                                               null /*alias */,
777                                               templateElements /* elements */,
778                                               new XSLTAttributeDef[]{
779                                                       nameAttrRequired,
780                                                       selectAttrOpt }, 
781                                               new ProcessorGlobalParamDecl(),
782                                               ElemParam.class /* class object */, 20, true),
783                                      new XSLTElementDef(
784                                               this,
785                                               Constants.S_XSLNAMESPACEURL,
786                                               "template",
787                                               null /*alias */,
788                                               templateElementsAndParams /* elements */,
789                                               new XSLTAttributeDef[]{
790                                                       matchAttrOpt,
791                                                       nameAttrOpt_ERROR,
792                                                       priorityAttr,
793                                                       modeAttr,
794                                                       spaceAttr }, 
795                                               new ProcessorTemplate(), ElemTemplate.class /* class object */, true, 20, true), 
796                                      new XSLTElementDef(
797                                               this,
798                                               Constants.S_XSLNAMESPACEURL,
799                                               "namespace-alias",
800                                               null /*alias */,
801                                              null /* elements */,  // EMPTY
802                                               new XSLTAttributeDef[]{ 
803                                                       stylesheetPrefixAttr,
804                                                       resultPrefixAttr }, 
805                                               new ProcessorNamespaceAlias(), null /* class object */, 20, true),
806                                      new XSLTElementDef(
807                                               this,
808                                               Constants.S_BUILTIN_EXTENSIONS_URL,
809                                               "component",
810                                               null /*alias */,
811                                               new XSLTElementDef[]{
812                                                        new XSLTElementDef(
813                                                            this,
814                                                            Constants.S_BUILTIN_EXTENSIONS_URL,
815                                                            "script",
816                                                            null /*alias */,
817                                                            new XSLTElementDef[]{ 
818                                                            charData } /* elements */,
819                                                            scriptAttrs, 
820                                                            new ProcessorLRE(),
821                                                            ElemExtensionScript.class /* class object */, 20, true) },  // EMPTY
822                                               componentAttrs, 
823                                               new ProcessorLRE(), ElemExtensionDecl.class /* class object */),
824                                      new XSLTElementDef(
825                                               this,
826                                               Constants.S_BUILTIN_OLD_EXTENSIONS_URL,
827                                               "component",
828                                               null /*alias */,
829                                               new XSLTElementDef[]{
830                                                        new XSLTElementDef(
831                                                            this,
832                                                            Constants.S_BUILTIN_OLD_EXTENSIONS_URL,
833                                                            "script",
834                                                            null /*alias */,
835                                                            new XSLTElementDef[]{ 
836                                                            charData } /* elements */,
837                                                            scriptAttrs, 
838                                                            new ProcessorLRE(),
839                                                            ElemExtensionScript.class /* class object */, 20, true) },  // EMPTY
840                                               componentAttrs, 
841                                               new ProcessorLRE(), ElemExtensionDecl.class /* class object */),
842                                      exsltFunction}/* exslt */;  //end of topevelElements
843        
844        XSLTAttributeDef excludeResultPrefixesAttr =
845          new XSLTAttributeDef(null, "exclude-result-prefixes",
846                               XSLTAttributeDef.T_PREFIXLIST, false,false,XSLTAttributeDef.WARNING);
847        XSLTAttributeDef extensionElementPrefixesAttr =
848          new XSLTAttributeDef(null, "extension-element-prefixes",
849                               XSLTAttributeDef.T_PREFIX_URLLIST, false,false,XSLTAttributeDef.WARNING);
850        XSLTAttributeDef idAttr = new XSLTAttributeDef(null, "id",
851                                    XSLTAttributeDef.T_CDATA, false,false,XSLTAttributeDef.WARNING);
852        XSLTAttributeDef versionAttrRequired = new XSLTAttributeDef(null,
853                                                 "version",
854                                                 XSLTAttributeDef.T_NMTOKEN,
855                                                 true,false,XSLTAttributeDef.WARNING);
856        XSLTElementDef stylesheetElemDef = new XSLTElementDef(this,
857                                             Constants.S_XSLNAMESPACEURL,
858                                             "stylesheet", "transform",
859                                             topLevelElements,
860                                             new XSLTAttributeDef[]{
861                                               extensionElementPrefixesAttr,
862                                               excludeResultPrefixesAttr,
863                                               idAttr,
864                                               versionAttrRequired,
865                                               spaceAttr }, new ProcessorStylesheetElement(),  /* ContentHandler */
866                                             null  /* class object */,
867                                             true, -1, false);
868    
869        importDef.setElements(new XSLTElementDef[]{ stylesheetElemDef,
870                                                    resultElement,
871                                                    unknownElement });
872        includeDef.setElements(new XSLTElementDef[]{ stylesheetElemDef,
873                                                     resultElement,
874                                                     unknownElement });
875        build(null, null, null, new XSLTElementDef[]{ stylesheetElemDef,
876                                                      whiteSpaceOnly,
877                                                      resultElement,
878                                                      unknownElement }, null,
879                                                                        new ProcessorStylesheetDoc(),  /* ContentHandler */
880                                                                        null  /* class object */
881                                                                          );
882      }
883    
884      /**
885       * A hashtable of all available built-in elements for use by the element-available
886       * function.
887       * TODO:  When we convert to Java2, this should be a Set.
888       */
889      private HashMap m_availElems = new HashMap();
890      
891      /**
892       * Get the table of available elements.
893       * 
894       * @return table of available elements, keyed by qualified names, and with 
895       * values of the same qualified names.
896       */
897      public HashMap getElemsAvailable() 
898      {
899        return m_availElems;
900      }
901    
902      /**
903       * Adds a new element name to the Hashtable of available elements.
904       * @param elemName The name of the element to add to the Hashtable of available elements.
905       */
906      void addAvailableElement(QName elemName)
907      {
908        m_availElems.put(elemName, elemName);
909      }
910    
911      /**
912       * Determines whether the passed element name is present in the list of available elements.
913       * @param elemName The name of the element to look up.
914       *
915       * @return true if an element corresponding to elemName is available.
916       */
917      public boolean elementAvailable(QName elemName)
918      {
919        return m_availElems.containsKey(elemName);
920      }
921    }
922