KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > processor > XSLTSchema


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: XSLTSchema.java,v 1.35 2004/02/11 18:15:50 minchau Exp $
18  */

19 package org.apache.xalan.processor;
20
21 import java.util.Hashtable JavaDoc;
22
23 import org.apache.xalan.templates.Constants;
24 import org.apache.xalan.templates.ElemApplyImport;
25 import org.apache.xalan.templates.ElemApplyTemplates;
26 import org.apache.xalan.templates.ElemAttribute;
27 import org.apache.xalan.templates.ElemCallTemplate;
28 import org.apache.xalan.templates.ElemChoose;
29 import org.apache.xalan.templates.ElemComment;
30 import org.apache.xalan.templates.ElemCopy;
31 import org.apache.xalan.templates.ElemCopyOf;
32 import org.apache.xalan.templates.ElemElement;
33 import org.apache.xalan.templates.ElemExsltFuncResult;
34 import org.apache.xalan.templates.ElemExsltFunction;
35 import org.apache.xalan.templates.ElemExtensionDecl;
36 import org.apache.xalan.templates.ElemExtensionScript;
37 import org.apache.xalan.templates.ElemFallback;
38 import org.apache.xalan.templates.ElemForEach;
39 import org.apache.xalan.templates.ElemIf;
40 import org.apache.xalan.templates.ElemLiteralResult;
41 import org.apache.xalan.templates.ElemMessage;
42 import org.apache.xalan.templates.ElemNumber;
43 import org.apache.xalan.templates.ElemOtherwise;
44 import org.apache.xalan.templates.ElemPI;
45 import org.apache.xalan.templates.ElemParam;
46 import org.apache.xalan.templates.ElemSort;
47 import org.apache.xalan.templates.ElemTemplate;
48 import org.apache.xalan.templates.ElemText;
49 import org.apache.xalan.templates.ElemTextLiteral;
50 import org.apache.xalan.templates.ElemUnknown;
51 import org.apache.xalan.templates.ElemValueOf;
52 import org.apache.xalan.templates.ElemVariable;
53 import org.apache.xalan.templates.ElemWhen;
54 import org.apache.xalan.templates.ElemWithParam;
55 import org.apache.xml.utils.QName;
56
57 /**
58  * This class defines the allowed structure for a stylesheet, and the
59  * mapping between Xalan classes and the markup elements in the stylesheet.
60  * @see <a HREF="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
61  */

62 public class XSLTSchema extends XSLTElementDef
63 {
64
65   /**
66    * Construct a XSLTSchema which represents the XSLT "schema".
67    */

68   XSLTSchema()
69   {
70     build();
71   }
72
73   /**
74    * This method builds an XSLT "schema" according to http://www.w3.org/TR/xslt#dtd. This
75    * schema provides instructions for building the Xalan Stylesheet (Templates) structure.
76    */

77   void build()
78   {
79     // xsl:import, xsl:include
80
XSLTAttributeDef hrefAttr = new XSLTAttributeDef(null, "href",
81                                   XSLTAttributeDef.T_URL, true, false,XSLTAttributeDef.ERROR);
82                                   
83     // xsl:preserve-space, xsl:strip-space
84
XSLTAttributeDef elementsAttr = new XSLTAttributeDef(null, "elements",
85                                       XSLTAttributeDef.T_SIMPLEPATTERNLIST,
86                                       true, false, XSLTAttributeDef.ERROR);
87                                       
88     // XSLTAttributeDef anyNamespacedAttr = new XSLTAttributeDef("*", "*",
89
// XSLTAttributeDef.T_CDATA, false);
90

91     // xsl:output
92
XSLTAttributeDef methodAttr = new XSLTAttributeDef(null, "method",
93                                     XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR);
94     XSLTAttributeDef versionAttr = new XSLTAttributeDef(null, "version",
95                                      XSLTAttributeDef.T_NMTOKEN, false, false,XSLTAttributeDef.ERROR);
96     XSLTAttributeDef encodingAttr = new XSLTAttributeDef(null, "encoding",
97                                       XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
98     XSLTAttributeDef omitXmlDeclarationAttr = new XSLTAttributeDef(null,
99                                                 "omit-xml-declaration",
100                                                 XSLTAttributeDef.T_YESNO,
101                                                 false, false,XSLTAttributeDef.ERROR);
102     XSLTAttributeDef standaloneAttr = new XSLTAttributeDef(null,
103                                         "standalone",
104                                         XSLTAttributeDef.T_YESNO, false, false,XSLTAttributeDef.ERROR);
105     XSLTAttributeDef doctypePublicAttr = new XSLTAttributeDef(null,
106                                            "doctype-public",
107                                            XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
108     XSLTAttributeDef doctypeSystemAttr = new XSLTAttributeDef(null,
109                                            "doctype-system",
110                                            XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
111     XSLTAttributeDef cdataSectionElementsAttr = new XSLTAttributeDef(null,
112                                                   "cdata-section-elements",
113                                                   XSLTAttributeDef.T_QNAMES_RESOLVE_NULL,
114                                                   false, false,XSLTAttributeDef.ERROR);
115     XSLTAttributeDef indentAttr = new XSLTAttributeDef(null, "indent",
116                                     XSLTAttributeDef.T_YESNO, false, false,XSLTAttributeDef.ERROR);
117     XSLTAttributeDef mediaTypeAttr = new XSLTAttributeDef(null, "media-type",
118                                        XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.ERROR);
119                                        
120                   
121     // Required.
122
// It is an error if the name attribute is invalid on any of these elements
123
// xsl:key, xsl:attribute-set, xsl:call-template, xsl:with-param, xsl:variable, xsl:param
124
XSLTAttributeDef nameAttrRequired = new XSLTAttributeDef(null, "name",
125                                           XSLTAttributeDef.T_QNAME, true, false,XSLTAttributeDef.ERROR);
126     // Required.
127
// Support AVT
128
// xsl:element, xsl:attribute
129
XSLTAttributeDef nameAVTRequired = new XSLTAttributeDef(null, "name",
130                                          XSLTAttributeDef.T_AVT_QNAME, true, true,XSLTAttributeDef.WARNING);
131             
132
133     // Required.
134
// Support AVT
135
// xsl:processing-instruction
136
XSLTAttributeDef nameAVT_NCNAMERequired = new XSLTAttributeDef(null, "name",
137                                          XSLTAttributeDef.T_NCNAME, true, true,XSLTAttributeDef.WARNING);
138                                         
139     // Optional.
140
// Static error if invalid
141
// xsl:template, xsl:decimal-format
142
XSLTAttributeDef nameAttrOpt_ERROR = new XSLTAttributeDef(null, "name",
143                                      XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR);
144
145     // xsl:key
146
XSLTAttributeDef useAttr = new XSLTAttributeDef(null, "use",
147                                  XSLTAttributeDef.T_EXPR, true, false,XSLTAttributeDef.ERROR);
148            
149     // xsl:element, xsl:attribute
150
XSLTAttributeDef namespaceAVTOpt = new XSLTAttributeDef(null,
151                                          "namespace",XSLTAttributeDef.T_URL,
152                                          false, true,XSLTAttributeDef.WARNING);
153     // xsl:decimal-format
154
XSLTAttributeDef decimalSeparatorAttr = new XSLTAttributeDef(null,
155                                               "decimal-separator",
156                                               XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, ".");
157     XSLTAttributeDef infinityAttr = new XSLTAttributeDef(null, "infinity",
158                                       XSLTAttributeDef.T_CDATA, false,XSLTAttributeDef.ERROR,"Infinity");
159     XSLTAttributeDef minusSignAttr = new XSLTAttributeDef(null, "minus-sign",
160                                        XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR,"-");
161     XSLTAttributeDef NaNAttr = new XSLTAttributeDef(null, "NaN",
162                                  XSLTAttributeDef.T_CDATA, false,XSLTAttributeDef.ERROR, "NaN");
163     XSLTAttributeDef percentAttr = new XSLTAttributeDef(null, "percent",
164                                      XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, "%");
165     XSLTAttributeDef perMilleAttr = new XSLTAttributeDef(null, "per-mille",
166                                       XSLTAttributeDef.T_CHAR,
167                                       false, false,XSLTAttributeDef.ERROR /* ,"&#x2030;" */);
168     XSLTAttributeDef zeroDigitAttr = new XSLTAttributeDef(null, "zero-digit",
169                                        XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, "0");
170     XSLTAttributeDef digitAttr = new XSLTAttributeDef(null, "digit",
171                                    XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, "#");
172     XSLTAttributeDef patternSeparatorAttr = new XSLTAttributeDef(null,
173                                               "pattern-separator",
174                                               XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR, ";");
175     // xsl:decimal-format
176
XSLTAttributeDef groupingSeparatorAttr = new XSLTAttributeDef(null,
177                                                "grouping-separator",
178                                                XSLTAttributeDef.T_CHAR, false,XSLTAttributeDef.ERROR,",");
179
180                                               
181     // xsl:element, xsl:attribute-set, xsl:copy
182
XSLTAttributeDef useAttributeSetsAttr = new XSLTAttributeDef(null,
183                                               "use-attribute-sets",
184                                               XSLTAttributeDef.T_QNAMES,
185                                               false, false, XSLTAttributeDef.ERROR);
186
187     // xsl:if, xsl:when
188
XSLTAttributeDef testAttrRequired = new XSLTAttributeDef(null, "test",
189                                           XSLTAttributeDef.T_EXPR, true, false,XSLTAttributeDef.ERROR);
190       
191       
192     // Required.
193
// xsl:value-of, xsl:for-each, xsl:copy-of
194
XSLTAttributeDef selectAttrRequired = new XSLTAttributeDef(null,
195                                             "select",
196                                             XSLTAttributeDef.T_EXPR, true, false,XSLTAttributeDef.ERROR);
197
198     // Optional.
199
// xsl:variable, xsl:param, xsl:with-param
200
XSLTAttributeDef selectAttrOpt = new XSLTAttributeDef(null, "select",
201                                        XSLTAttributeDef.T_EXPR, false, false,XSLTAttributeDef.ERROR);
202
203     // Optional.
204
// Default: "node()"
205
// xsl:apply-templates
206
XSLTAttributeDef selectAttrDefNode = new XSLTAttributeDef(null, "select",
207                                            XSLTAttributeDef.T_EXPR, false,XSLTAttributeDef.ERROR, "node()");
208     // Optional.
209
// Default: "."
210
// xsl:sort
211
XSLTAttributeDef selectAttrDefDot = new XSLTAttributeDef(null, "select",
212                                           XSLTAttributeDef.T_EXPR, false,XSLTAttributeDef.ERROR, ".");
213     // xsl:key
214
XSLTAttributeDef matchAttrRequired = new XSLTAttributeDef(null, "match",
215                                            XSLTAttributeDef.T_PATTERN, true, false,XSLTAttributeDef.ERROR);
216     // xsl:template
217
XSLTAttributeDef matchAttrOpt = new XSLTAttributeDef(null, "match",
218                                       XSLTAttributeDef.T_PATTERN, false, false,XSLTAttributeDef.ERROR);
219     // xsl:template
220
XSLTAttributeDef priorityAttr = new XSLTAttributeDef(null, "priority",
221                                      XSLTAttributeDef.T_NUMBER, false, false,XSLTAttributeDef.ERROR);
222                                      
223     // xsl:template, xsl:apply-templates
224
XSLTAttributeDef modeAttr = new XSLTAttributeDef(null, "mode",
225                                      XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR);
226    
227     XSLTAttributeDef spaceAttr =
228       new XSLTAttributeDef(Constants.S_XMLNAMESPACEURI, "space", false, false, false, XSLTAttributeDef.WARNING,
229                            "default", Constants.ATTRVAL_STRIP, "preserve",
230                            Constants.ATTRVAL_PRESERVE);
231                            
232                          
233     XSLTAttributeDef spaceAttrLiteral =
234       new XSLTAttributeDef(Constants.S_XMLNAMESPACEURI, "space",
235                                           XSLTAttributeDef.T_URL, false, true,XSLTAttributeDef.ERROR);
236     // xsl:namespace-alias
237
XSLTAttributeDef stylesheetPrefixAttr = new XSLTAttributeDef(null,
238                                               "stylesheet-prefix",
239                                               XSLTAttributeDef.T_CDATA, true, false,XSLTAttributeDef.ERROR);
240     XSLTAttributeDef resultPrefixAttr = new XSLTAttributeDef(null,
241                                           "result-prefix",
242                                           XSLTAttributeDef.T_CDATA, true, false,XSLTAttributeDef.ERROR);
243                                           
244     // xsl:text, xsl:value-of
245
XSLTAttributeDef disableOutputEscapingAttr = new XSLTAttributeDef(null,
246                                                    "disable-output-escaping",
247                                                    XSLTAttributeDef.T_YESNO,
248                                                    false, false,XSLTAttributeDef.ERROR);
249                                                    
250     // xsl:number
251
XSLTAttributeDef levelAttr = new XSLTAttributeDef(null, "level", false, false, false, XSLTAttributeDef.ERROR,
252                                    "single", Constants.NUMBERLEVEL_SINGLE,
253                                    "multiple", Constants.NUMBERLEVEL_MULTI,
254                                    "any", Constants.NUMBERLEVEL_ANY);
255     levelAttr.setDefault("single");
256     XSLTAttributeDef countAttr = new XSLTAttributeDef(null, "count",
257                                    XSLTAttributeDef.T_PATTERN, false, false,XSLTAttributeDef.ERROR);
258     XSLTAttributeDef fromAttr = new XSLTAttributeDef(null, "from",
259                                   XSLTAttributeDef.T_PATTERN, false, false,XSLTAttributeDef.ERROR);
260     XSLTAttributeDef valueAttr = new XSLTAttributeDef(null, "value",
261                                    XSLTAttributeDef.T_EXPR, false, false,XSLTAttributeDef.ERROR);
262     XSLTAttributeDef formatAttr = new XSLTAttributeDef(null, "format",
263                                     XSLTAttributeDef.T_CDATA, false, true,XSLTAttributeDef.ERROR);
264     formatAttr.setDefault("1");
265     
266     // xsl:number, xsl:sort
267
XSLTAttributeDef langAttr = new XSLTAttributeDef(null, "lang",
268                                   XSLTAttributeDef.T_NMTOKEN, false, true,XSLTAttributeDef.ERROR);
269    
270     // xsl:number
271
XSLTAttributeDef letterValueAttr = new XSLTAttributeDef(null,
272                                          "letter-value",
273                                          false, true, false, XSLTAttributeDef.ERROR,
274                                          "alphabetic", Constants.NUMBERLETTER_ALPHABETIC,
275                                          "traditional", Constants.NUMBERLETTER_TRADITIONAL);
276     // xsl:number
277
XSLTAttributeDef groupingSeparatorAVT = new XSLTAttributeDef(null,
278                                               "grouping-separator",
279                                               XSLTAttributeDef.T_CHAR, false, true,XSLTAttributeDef.ERROR);
280     // xsl:number
281
XSLTAttributeDef groupingSizeAttr = new XSLTAttributeDef(null,
282                                           "grouping-size",
283                                           XSLTAttributeDef.T_NUMBER, false, true,XSLTAttributeDef.ERROR);
284    
285    // xsl:sort
286
XSLTAttributeDef dataTypeAttr = new XSLTAttributeDef(null, "data-type", false, true, true, XSLTAttributeDef.ERROR,
287                                     "text", Constants.SORTDATATYPE_TEXT ,"number", Constants.SORTDATATYPE_TEXT);
288     dataTypeAttr.setDefault("text");
289     
290     // xsl:sort
291
XSLTAttributeDef orderAttr = new XSLTAttributeDef(null, "order", false, true, false,XSLTAttributeDef.ERROR,
292                                     "ascending", Constants.SORTORDER_ASCENDING,
293                                     "descending", Constants.SORTORDER_DESCENDING);
294     orderAttr.setDefault("ascending");
295
296     // xsl:sort
297
XSLTAttributeDef caseOrderAttr = new XSLTAttributeDef(null, "case-order", false, true, false,XSLTAttributeDef.ERROR,
298                                        "upper-first", Constants.SORTCASEORDER_UPPERFIRST ,
299                                        "lower-first", Constants.SORTCASEORDER_LOWERFIRST);
300         
301     // xsl:message
302
XSLTAttributeDef terminateAttr = new XSLTAttributeDef(null, "terminate",
303                                        XSLTAttributeDef.T_YESNO, false, false,XSLTAttributeDef.ERROR);
304     terminateAttr.setDefault("no");
305
306     // top level attributes
307
XSLTAttributeDef xslExcludeResultPrefixesAttr =
308       new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL,
309                            "exclude-result-prefixes",
310                            XSLTAttributeDef.T_PREFIXLIST, false, false,XSLTAttributeDef.ERROR);
311     XSLTAttributeDef xslExtensionElementPrefixesAttr =
312       new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL,
313                            "extension-element-prefixes",
314                            XSLTAttributeDef.T_PREFIX_URLLIST, false, false,XSLTAttributeDef.ERROR);
315     // result-element-atts
316
XSLTAttributeDef xslUseAttributeSetsAttr =
317       new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "use-attribute-sets",
318                            XSLTAttributeDef.T_QNAMES, false, false,XSLTAttributeDef.ERROR);
319     XSLTAttributeDef xslVersionAttr =
320       new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "version",
321                            XSLTAttributeDef.T_NMTOKEN, false, false,XSLTAttributeDef.ERROR);
322                            
323     XSLTElementDef charData = new XSLTElementDef(this, null, "text()",
324                                 null /*alias */, null /* elements */, null, /* attributes */
325                                 new ProcessorCharacters(),
326                                 ElemTextLiteral.class /* class object */);
327
328     charData.setType(XSLTElementDef.T_PCDATA);
329
330     XSLTElementDef whiteSpaceOnly = new XSLTElementDef(this, null, "text()",
331                                       null /*alias */, null /* elements */,
332                                       null, /* attributes */
333                                       null,
334                                       ElemTextLiteral.class /* should be null? -sb */);
335
336     charData.setType(XSLTElementDef.T_PCDATA);
337
338     XSLTAttributeDef resultAttr = new XSLTAttributeDef(null, "*",
339                                     XSLTAttributeDef.T_AVT, false, true,XSLTAttributeDef.WARNING);
340     XSLTAttributeDef xslResultAttr =
341       new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "*",
342                            XSLTAttributeDef.T_CDATA, false, false,XSLTAttributeDef.WARNING);
343                            
344     XSLTElementDef[] templateElements = new XSLTElementDef[23];
345     XSLTElementDef[] templateElementsAndParams = new XSLTElementDef[24];
346     XSLTElementDef[] templateElementsAndSort = new XSLTElementDef[24];
347     //exslt
348
XSLTElementDef[] exsltFunctionElements = new XSLTElementDef[24];
349     
350     XSLTElementDef[] charTemplateElements = new XSLTElementDef[15];
351     XSLTElementDef resultElement = new XSLTElementDef(this, null, "*",
352                                      null /*alias */,
353                                      templateElements /* elements */,
354                                      new XSLTAttributeDef[]{
355                                        spaceAttrLiteral, // special
356
xslExcludeResultPrefixesAttr,
357                                        xslExtensionElementPrefixesAttr,
358                                        xslUseAttributeSetsAttr,
359                                        xslVersionAttr,
360                                        xslResultAttr,
361                                        resultAttr },
362                                         new ProcessorLRE(),
363                                      ElemLiteralResult.class /* class object */, 20, true);
364     XSLTElementDef unknownElement =
365       new XSLTElementDef(this, "*", "unknown", null /*alias */,
366                          templateElementsAndParams /* elements */,
367                          new XSLTAttributeDef[]{ xslExcludeResultPrefixesAttr,
368                                                  xslExtensionElementPrefixesAttr,
369                                                  xslUseAttributeSetsAttr,
370                                                  xslVersionAttr,
371                                                  xslResultAttr,
372                                                  resultAttr },
373                                                                                                  new ProcessorUnknown(),
374                          ElemUnknown.class /* class object */, 20, true);
375     XSLTElementDef xslValueOf = new XSLTElementDef(this,
376                                   Constants.S_XSLNAMESPACEURL, "value-of",
377                                   null /*alias */, null /* elements */,
378                                   new XSLTAttributeDef[]{ selectAttrRequired,
379                                                           disableOutputEscapingAttr },
380                                                new ProcessorTemplateElem(),
381                                   ElemValueOf.class /* class object */, 20, true);
382     XSLTElementDef xslCopyOf = new XSLTElementDef(this,
383                                  Constants.S_XSLNAMESPACEURL, "copy-of",
384                                  null /*alias */, null /* elements */,
385                                  new XSLTAttributeDef[]{ selectAttrRequired },
386                                  new ProcessorTemplateElem(),
387                                  ElemCopyOf.class /* class object */, 20, true);
388     XSLTElementDef xslNumber = new XSLTElementDef(this,
389                                  Constants.S_XSLNAMESPACEURL, "number",
390                                  null /*alias */, null /* elements */,
391                                  new XSLTAttributeDef[]{ levelAttr,
392                                                          countAttr,
393                                                          fromAttr,
394                                                          valueAttr,
395                                                          formatAttr,
396                                                          langAttr,
397                                                          letterValueAttr,
398                                                          groupingSeparatorAVT,
399                                                          groupingSizeAttr },
400                                         new ProcessorTemplateElem(),
401                                  ElemNumber.class /* class object */, 20, true);
402
403     // <!-- xsl:sort cannot occur after any other elements or
404
// any non-whitespace character -->
405
XSLTElementDef xslSort = new XSLTElementDef(this,
406                                                 Constants.S_XSLNAMESPACEURL,
407                                                 "sort", null /*alias */,
408                                                 null /* elements */,
409                                                 new XSLTAttributeDef[]{
410                                                   selectAttrDefDot,
411                                                   langAttr,
412                                                   dataTypeAttr,
413                                                   orderAttr,
414                                                   caseOrderAttr },
415                                        new ProcessorTemplateElem(),
416                                                 ElemSort.class/* class object */, 19, true );
417     XSLTElementDef xslWithParam = new XSLTElementDef(this,
418                                     Constants.S_XSLNAMESPACEURL,
419                                     "with-param", null /*alias */,
420                                     templateElements /* elements */, // %template;>
421
new XSLTAttributeDef[]{ nameAttrRequired,
422                                                             selectAttrOpt }, new ProcessorTemplateElem(),
423                                                                              ElemWithParam.class /* class object */, 19, true);
424     XSLTElementDef xslApplyTemplates = new XSLTElementDef(this,
425                                          Constants.S_XSLNAMESPACEURL,
426                                          "apply-templates", null /*alias */,
427                                          new XSLTElementDef[]{ xslSort,
428                                                                xslWithParam } /* elements */, new XSLTAttributeDef[]{
429                                                                  selectAttrDefNode,
430                                                                  modeAttr },
431                                                                         new ProcessorTemplateElem(),
432                                          ElemApplyTemplates.class /* class object */, 20, true);
433     XSLTElementDef xslApplyImports =
434       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "apply-imports",
435                          null /*alias */, null /* elements */,
436                          new XSLTAttributeDef[]{},
437                          new ProcessorTemplateElem(),
438                          ElemApplyImport.class /* class object */);
439     XSLTElementDef xslForEach = new XSLTElementDef(this,
440                                   Constants.S_XSLNAMESPACEURL, "for-each",
441                                   null /*alias */, templateElementsAndSort, // (#PCDATA %instructions; %result-elements; | xsl:sort)*
442
new XSLTAttributeDef[]{ selectAttrRequired,
443                                                           spaceAttr },
444                                                new ProcessorTemplateElem(),
445                                   ElemForEach.class /* class object */, true, false, true, 20, true);
446     XSLTElementDef xslIf = new XSLTElementDef(this,
447                                               Constants.S_XSLNAMESPACEURL,
448                                               "if", null /*alias */,
449                                               templateElements /* elements */, // %template;
450
new XSLTAttributeDef[]{
451                                                 testAttrRequired,
452                                                 spaceAttr }, new ProcessorTemplateElem(),
453                                                              ElemIf.class /* class object */, 20, true);
454     XSLTElementDef xslWhen =
455       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "when",
456                          null /*alias */, templateElements /* elements */, // %template;>
457
new XSLTAttributeDef[]{
458                                                   testAttrRequired,
459                                                   spaceAttr }, new ProcessorTemplateElem(),
460                                                                ElemWhen.class /* class object */,
461                                                                                                 false, true, 1, true);
462     XSLTElementDef xslOtherwise = new XSLTElementDef(this,
463                                     Constants.S_XSLNAMESPACEURL, "otherwise",
464                                     null /*alias */,
465                                     templateElements /* elements */, // %template;>
466
new XSLTAttributeDef[]{ spaceAttr },
467                                     new ProcessorTemplateElem(),
468                                     ElemOtherwise.class /* class object */,
469                                                        false, false, 2, false);
470     XSLTElementDef xslChoose = new XSLTElementDef(this,
471                                  Constants.S_XSLNAMESPACEURL, "choose",
472                                  null /*alias */,
473                                  new XSLTElementDef[]{ xslWhen,
474                                                        xslOtherwise } /* elements */,
475                                         new XSLTAttributeDef[]{ spaceAttr },
476                                  new ProcessorTemplateElem(),
477                                  ElemChoose.class /* class object */, true, false, true, 20, true);
478     XSLTElementDef xslAttribute = new XSLTElementDef(this,
479                                     Constants.S_XSLNAMESPACEURL, "attribute",
480                                     null /*alias */,
481                                     charTemplateElements /* elements */, // %char-template;>
482
new XSLTAttributeDef[]{ nameAVTRequired,
483                                                             namespaceAVTOpt,
484                                                             spaceAttr },
485                                     new ProcessorTemplateElem(),
486                                     ElemAttribute.class /* class object */, 20, true);
487     XSLTElementDef xslCallTemplate =
488       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "call-template",
489                          null /*alias */,
490                          new XSLTElementDef[]{ xslWithParam } /* elements */,
491                          new XSLTAttributeDef[]{ nameAttrRequired },
492                          new ProcessorTemplateElem(),
493                          ElemCallTemplate.class /* class object */, 20, true);
494     XSLTElementDef xslVariable = new XSLTElementDef(this,
495                                    Constants.S_XSLNAMESPACEURL, "variable",
496                                    null /*alias */,
497                                    templateElements /* elements */, // %template;>
498
new XSLTAttributeDef[]{ nameAttrRequired,
499                                                            selectAttrOpt },
500                                   new ProcessorTemplateElem(),
501                                    ElemVariable.class /* class object */, 20, true);
502     XSLTElementDef xslParam = new XSLTElementDef(this,
503                                 Constants.S_XSLNAMESPACEURL, "param",
504                                 null /*alias */,
505                                 templateElements /* elements */, // %template;>
506
new XSLTAttributeDef[]{ nameAttrRequired,
507                                                         selectAttrOpt },
508                                        new ProcessorTemplateElem(),
509                                 ElemParam.class /* class object */, 19, true);
510     XSLTElementDef xslText =
511       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "text",
512                          null /*alias */,
513                          new XSLTElementDef[]{ charData } /* elements */,
514                          new XSLTAttributeDef[]{ disableOutputEscapingAttr },
515                          new ProcessorText(),
516                          ElemText.class /* class object */, 20, true);
517     XSLTElementDef xslProcessingInstruction =
518       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL,
519                          "processing-instruction", null /*alias */,
520                          charTemplateElements /* elements */, // %char-template;>
521
new XSLTAttributeDef[]{
522                                                   nameAVT_NCNAMERequired,
523                                                   spaceAttr },
524                                         new ProcessorTemplateElem(),
525                           ElemPI.class /* class object */, 20, true);
526     XSLTElementDef xslElement = new XSLTElementDef(this,
527                                   Constants.S_XSLNAMESPACEURL, "element",
528                                   null /*alias */,
529                                   templateElements /* elements */, // %template;
530
new XSLTAttributeDef[]{ nameAVTRequired,
531                                                           namespaceAVTOpt,
532                                                           useAttributeSetsAttr,
533                                                           spaceAttr },
534                                                new ProcessorTemplateElem(),
535                                   ElemElement.class /* class object */, 20, true);
536     XSLTElementDef xslComment = new XSLTElementDef(this,
537                                   Constants.S_XSLNAMESPACEURL, "comment",
538                                   null /*alias */,
539                                   charTemplateElements /* elements */, // %char-template;>
540
new XSLTAttributeDef[]{ spaceAttr },
541                                   new ProcessorTemplateElem(),
542                                   ElemComment.class /* class object */, 20, true);
543     XSLTElementDef xslCopy =
544       new XSLTElementDef(this, Constants.S_XSLNAMESPACEURL, "copy",
545                          null /*alias */, templateElements /* elements */, // %template;>
546
new XSLTAttributeDef[]{
547                                                   spaceAttr,
548                                                   useAttributeSetsAttr },
549                                         new ProcessorTemplateElem(),
550                           ElemCopy.class /* class object */, 20, true);
551     XSLTElementDef xslMessage = new XSLTElementDef(this,
552                                   Constants.S_XSLNAMESPACEURL, "message",
553                                   null /*alias */,
554                                   templateElements /* elements */, // %template;>
555
new XSLTAttributeDef[]{ terminateAttr },
556                                   new ProcessorTemplateElem(),
557                                   ElemMessage.class /* class object */, 20, true);
558     XSLTElementDef xslFallback = new XSLTElementDef(this,
559                                    Constants.S_XSLNAMESPACEURL, "fallback",
560                                    null /*alias */,
561                                    templateElements /* elements */, // %template;>
562
new XSLTAttributeDef[]{ spaceAttr },
563                                    new ProcessorTemplateElem(),
564                                    ElemFallback.class /* class object */, 20, true);
565     //exslt
566
XSLTElementDef exsltFunction =
567                                   new XSLTElementDef(this,
568                                   Constants.S_EXSLT_FUNCTIONS_URL,
569                                   "function",
570                                   null /*alias */,
571                                   exsltFunctionElements /* elements */,
572                                   new XSLTAttributeDef[]{ nameAttrRequired },
573                                   new ProcessorExsltFunction(),
574                                   ElemExsltFunction.class /* class object */);
575     XSLTElementDef exsltResult =
576                                   new XSLTElementDef(this,
577                                   Constants.S_EXSLT_FUNCTIONS_URL,
578                                   "result",
579                                   null /*alias */,
580                                   templateElements /* elements */,
581                                   new XSLTAttributeDef[]{ selectAttrOpt },
582                                   new ProcessorExsltFuncResult(),
583                                   ElemExsltFuncResult.class /* class object */);
584     
585
586     int i = 0;
587
588     templateElements[i++] = charData; // #PCDATA
589

590     // char-instructions
591
templateElements[i++] = xslApplyTemplates;
592     templateElements[i++] = xslCallTemplate;
593     templateElements[i++] = xslApplyImports;
594     templateElements[i++] = xslForEach;
595     templateElements[i++] = xslValueOf;
596     templateElements[i++] = xslCopyOf;
597     templateElements[i++] = xslNumber;
598     templateElements[i++] = xslChoose;
599     templateElements[i++] = xslIf;
600     templateElements[i++] = xslText;
601     templateElements[i++] = xslCopy;
602     templateElements[i++] = xslVariable;
603     templateElements[i++] = xslMessage;
604     templateElements[i++] = xslFallback;
605
606     // instructions
607
templateElements[i++] = xslProcessingInstruction;
608     templateElements[i++] = xslComment;
609     templateElements[i++] = xslElement;
610     templateElements[i++] = xslAttribute;
611     templateElements[i++] = resultElement;
612     templateElements[i++] = unknownElement;
613     templateElements[i++] = exsltFunction;
614     templateElements[i++] = exsltResult;
615
616     int k;
617
618     for (k = 0; k < i; k++)
619     {
620       templateElementsAndParams[k] = templateElements[k];
621       templateElementsAndSort[k] = templateElements[k];
622       exsltFunctionElements[k] = templateElements[k];
623
624     }
625
626     templateElementsAndParams[k] = xslParam;
627     templateElementsAndSort[k] = xslSort;
628     exsltFunctionElements[k] = xslParam;
629
630     i = 0;
631     charTemplateElements[i++] = charData; // #PCDATA
632

633     // char-instructions
634
charTemplateElements[i++] = xslApplyTemplates;
635     charTemplateElements[i++] = xslCallTemplate;
636     charTemplateElements[i++] = xslApplyImports;
637     charTemplateElements[i++] = xslForEach;
638     charTemplateElements[i++] = xslValueOf;
639     charTemplateElements[i++] = xslCopyOf;
640     charTemplateElements[i++] = xslNumber;
641     charTemplateElements[i++] = xslChoose;
642     charTemplateElements[i++] = xslIf;
643     charTemplateElements[i++] = xslText;
644     charTemplateElements[i++] = xslCopy;
645     charTemplateElements[i++] = xslVariable;
646     charTemplateElements[i++] = xslMessage;
647     charTemplateElements[i++] = xslFallback;
648
649     XSLTElementDef importDef = new XSLTElementDef(this,
650                                  Constants.S_XSLNAMESPACEURL, "import",
651                                  null /*alias */, null /* elements */,
652                                  new XSLTAttributeDef[]{ hrefAttr }, // EMPTY
653
new ProcessorImport(),
654                                  null /* class object */,
655                                         1, true);
656     XSLTElementDef includeDef = new XSLTElementDef(this,
657                                   Constants.S_XSLNAMESPACEURL, "include",
658                                   null /*alias */, null /* elements */, // EMPTY
659
new XSLTAttributeDef[]{ hrefAttr },
660                                   new ProcessorInclude(),
661                                   null /* class object */,
662                                                20, true);
663     
664     XSLTAttributeDef[] scriptAttrs = new XSLTAttributeDef[]{
665                             new XSLTAttributeDef(null, "lang", XSLTAttributeDef.T_NMTOKEN,
666                                                                  true, false,XSLTAttributeDef.WARNING),
667                                             new XSLTAttributeDef(null, "src", XSLTAttributeDef.T_URL,
668                                                          false, false,XSLTAttributeDef.WARNING)};
669
670     XSLTAttributeDef[] componentAttrs = new XSLTAttributeDef[]{
671                                             new XSLTAttributeDef(null, "prefix", XSLTAttributeDef.T_NMTOKEN,
672                                                          true, false,XSLTAttributeDef.WARNING),
673                                             new XSLTAttributeDef(null, "elements", XSLTAttributeDef.T_STRINGLIST,
674                                                          false, false,XSLTAttributeDef.WARNING),
675                                             new XSLTAttributeDef(null, "functions", XSLTAttributeDef.T_STRINGLIST,
676                                                          false, false,XSLTAttributeDef.WARNING) };
677
678     XSLTElementDef[] topLevelElements = new XSLTElementDef[]
679                                  {includeDef,
680                                   importDef,
681                                   // resultElement,
682
whiteSpaceOnly,
683                                   unknownElement,
684                                   new XSLTElementDef(
685                                          this,
686                                          Constants.S_XSLNAMESPACEURL,
687                                          "strip-space",
688                                          null /*alias */,
689                                          null /* elements */,
690                                          new XSLTAttributeDef[]{
691                                                 elementsAttr },
692                                                 new ProcessorStripSpace(),
693                                          null /* class object */, 20, true),
694                                   new XSLTElementDef(
695                                          this,
696                                          Constants.S_XSLNAMESPACEURL,
697                                          "preserve-space",
698                                          null /*alias */,
699                                          null /* elements */,
700                                          new XSLTAttributeDef[]{
701                                                  elementsAttr },
702                                                  new ProcessorPreserveSpace(),
703                                          null /* class object */, 20, true),
704                                   new XSLTElementDef(
705                                          this,
706                                          Constants.S_XSLNAMESPACEURL,
707                                          "output",
708                                          null /*alias */,
709                                          null /* elements */,
710                                          new XSLTAttributeDef[]{
711                                                   methodAttr,
712                                                   versionAttr,
713                                                   encodingAttr,
714                                                   omitXmlDeclarationAttr,
715                                                   standaloneAttr,
716                                                   doctypePublicAttr,
717                                                   doctypeSystemAttr,
718                                                   cdataSectionElementsAttr,
719                                                   indentAttr,
720                                                   mediaTypeAttr,
721                                                   XSLTAttributeDef.m_foreignAttr },
722                                           new ProcessorOutputElem(), null /* class object */, 20, true),
723                                   new XSLTElementDef(
724                                           this,
725                                           Constants.S_XSLNAMESPACEURL,
726                                           "key",
727                                           null /*alias */,
728                                           null /* elements */, // EMPTY
729
new XSLTAttributeDef[]{ nameAttrRequired,
730                                                   matchAttrRequired,
731                                                   useAttr },
732                                           new ProcessorKey(), null /* class object */, 20, true),
733                                   new XSLTElementDef(
734                                           this,
735                                           Constants.S_XSLNAMESPACEURL,
736                                           "decimal-format",
737                                           null /*alias */,
738                                           null /* elements */, // EMPTY
739
new XSLTAttributeDef[]{
740                                                   nameAttrOpt_ERROR,
741                                                   decimalSeparatorAttr,
742                                                   groupingSeparatorAttr,
743                                                   infinityAttr,
744                                                   minusSignAttr,
745                                                   NaNAttr,
746                                                   percentAttr,
747                                                   perMilleAttr,
748                                                   zeroDigitAttr,
749                                                   digitAttr,
750                                                   patternSeparatorAttr },
751                                            new ProcessorDecimalFormat(),
752                                            null /* class object */, 20, true),
753                                   new XSLTElementDef(
754                                            this,
755                                            Constants.S_XSLNAMESPACEURL,
756                                            "attribute-set",
757                                            null /*alias */,
758                                            new XSLTElementDef[]{
759                                                    xslAttribute } /* elements */,
760                                            new XSLTAttributeDef[]{
761                                                    nameAttrRequired,
762                                                    useAttributeSetsAttr },
763                                            new ProcessorAttributeSet(),
764                                            null /* class object */, 20, true),
765                                   new XSLTElementDef(
766                                            this,
767                                            Constants.S_XSLNAMESPACEURL,
768                                            "variable",
769                                            null /*alias */,
770                                            templateElements /* elements */,
771                                            new XSLTAttributeDef[]{
772                                                    nameAttrRequired,
773                                                    selectAttrOpt },
774                                            new ProcessorGlobalVariableDecl(),
775                                            ElemVariable.class /* class object */, 20, true),
776                                   new XSLTElementDef(
777                                            this,
778                                            Constants.S_XSLNAMESPACEURL,
779                                            "param",
780                                            null /*alias */,
781                                            templateElements /* elements */,
782                                            new XSLTAttributeDef[]{
783                                                    nameAttrRequired,
784                                                    selectAttrOpt },
785                                            new ProcessorGlobalParamDecl(),
786                                            ElemParam.class /* class object */, 20, true),
787                                   new XSLTElementDef(
788                                            this,
789                                            Constants.S_XSLNAMESPACEURL,
790                                            "template",
791                                            null /*alias */,
792                                            templateElementsAndParams /* elements */,
793                                            new XSLTAttributeDef[]{
794                                                    matchAttrOpt,
795                                                    nameAttrOpt_ERROR,
796                                                    priorityAttr,
797                                                    modeAttr,
798                                                    spaceAttr },
799                                            new ProcessorTemplate(), ElemTemplate.class /* class object */, true, 20, true),
800                                   new XSLTElementDef(
801                                            this,
802                                            Constants.S_XSLNAMESPACEURL,
803                                            "namespace-alias",
804                                            null /*alias */,
805                                           null /* elements */, // EMPTY
806
new XSLTAttributeDef[]{
807                                                    stylesheetPrefixAttr,
808                                                    resultPrefixAttr },
809                                            new ProcessorNamespaceAlias(), null /* class object */, 20, true),
810                                   new XSLTElementDef(
811                                            this,
812                                            Constants.S_BUILTIN_EXTENSIONS_URL,
813                                            "component",
814                                            null /*alias */,
815                                            new XSLTElementDef[]{
816                                                     new XSLTElementDef(
817                                                         this,
818                                                         Constants.S_BUILTIN_EXTENSIONS_URL,
819                                                         "script",
820                                                         null /*alias */,
821                                                         new XSLTElementDef[]{
822                                                         charData } /* elements */,
823                                                         scriptAttrs,
824                                                         new ProcessorLRE(),
825                                                         ElemExtensionScript.class /* class object */, 20, true) }, // EMPTY
826
componentAttrs,
827                                            new ProcessorLRE(), ElemExtensionDecl.class /* class object */),
828                                   new XSLTElementDef(
829                                            this,
830                                            Constants.S_BUILTIN_OLD_EXTENSIONS_URL,
831                                            "component",
832                                            null /*alias */,
833                                            new XSLTElementDef[]{
834                                                     new XSLTElementDef(
835                                                         this,
836                                                         Constants.S_BUILTIN_OLD_EXTENSIONS_URL,
837                                                         "script",
838                                                         null /*alias */,
839                                                         new XSLTElementDef[]{
840                                                         charData } /* elements */,
841                                                         scriptAttrs,
842                                                         new ProcessorLRE(),
843                                                         ElemExtensionScript.class /* class object */, 20, true) }, // EMPTY
844
componentAttrs,
845                                            new ProcessorLRE(), ElemExtensionDecl.class /* class object */),
846                                   exsltFunction}/* exslt */; //end of topevelElements
847

848     XSLTAttributeDef excludeResultPrefixesAttr =
849       new XSLTAttributeDef(null, "exclude-result-prefixes",
850                            XSLTAttributeDef.T_PREFIXLIST, false,false,XSLTAttributeDef.WARNING);
851     XSLTAttributeDef extensionElementPrefixesAttr =
852       new XSLTAttributeDef(null, "extension-element-prefixes",
853                            XSLTAttributeDef.T_PREFIX_URLLIST, false,false,XSLTAttributeDef.WARNING);
854     XSLTAttributeDef idAttr = new XSLTAttributeDef(null, "id",
855                                 XSLTAttributeDef.T_CDATA, false,false,XSLTAttributeDef.WARNING);
856     XSLTAttributeDef versionAttrRequired = new XSLTAttributeDef(null,
857                                              "version",
858                                              XSLTAttributeDef.T_NMTOKEN,
859                                              true,false,XSLTAttributeDef.WARNING);
860     XSLTElementDef stylesheetElemDef = new XSLTElementDef(this,
861                                          Constants.S_XSLNAMESPACEURL,
862                                          "stylesheet", "transform",
863                                          topLevelElements,
864                                          new XSLTAttributeDef[]{
865                                            extensionElementPrefixesAttr,
866                                            excludeResultPrefixesAttr,
867                                            idAttr,
868                                            versionAttrRequired,
869                                            spaceAttr }, new ProcessorStylesheetElement(), /* ContentHandler */
870                                          null /* class object */,
871                                          true, -1, false);
872
873     importDef.setElements(new XSLTElementDef[]{ stylesheetElemDef,
874                                                 resultElement,
875                                                 unknownElement });
876     includeDef.setElements(new XSLTElementDef[]{ stylesheetElemDef,
877                                                  resultElement,
878                                                  unknownElement });
879     build(null, null, null, new XSLTElementDef[]{ stylesheetElemDef,
880                                                   whiteSpaceOnly,
881                                                   resultElement,
882                                                   unknownElement }, null,
883                                                                     new ProcessorStylesheetDoc(), /* ContentHandler */
884                                                                     null /* class object */
885                                                                       );
886   }
887
888   /**
889    * A hashtable of all available built-in elements for use by the element-available
890    * function.
891    * TODO: When we convert to Java2, this should be a Set.
892    */

893   private Hashtable JavaDoc m_availElems = new Hashtable JavaDoc();
894   
895   /**
896    * Get the table of available elements.
897    *
898    * @return table of available elements, keyed by qualified names, and with
899    * values of the same qualified names.
900    */

901   public Hashtable JavaDoc getElemsAvailable()
902   {
903     return m_availElems;
904   }
905
906   /**
907    * Adds a new element name to the Hashtable of available elements.
908    * @param elemName The name of the element to add to the Hashtable of available elements.
909    */

910   void addAvailableElement(QName elemName)
911   {
912     m_availElems.put(elemName, elemName);
913   }
914
915   /**
916    * Determines whether the passed element name is present in the list of available elements.
917    * @param elemName The name of the element to look up.
918    *
919    * @return true if an element corresponding to elemName is available.
920    */

921   public boolean elementAvailable(QName elemName)
922   {
923     return m_availElems.containsKey(elemName);
924   }
925 }
926
927
Popular Tags