1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 /* 19 * $Id: XSLTSchema.java 476466 2006-11-18 08:22:31Z minchau $ 20 */ 21 package org.apache.xalan.processor; 22 23 import java.util.HashMap; 24 25 import org.apache.xalan.templates.Constants; 26 import org.apache.xalan.templates.ElemApplyImport; 27 import org.apache.xalan.templates.ElemApplyTemplates; 28 import org.apache.xalan.templates.ElemAttribute; 29 import org.apache.xalan.templates.ElemCallTemplate; 30 import org.apache.xalan.templates.ElemChoose; 31 import org.apache.xalan.templates.ElemComment; 32 import org.apache.xalan.templates.ElemCopy; 33 import org.apache.xalan.templates.ElemCopyOf; 34 import org.apache.xalan.templates.ElemElement; 35 import org.apache.xalan.templates.ElemExsltFuncResult; 36 import org.apache.xalan.templates.ElemExsltFunction; 37 import org.apache.xalan.templates.ElemExtensionDecl; 38 import org.apache.xalan.templates.ElemExtensionScript; 39 import org.apache.xalan.templates.ElemFallback; 40 import org.apache.xalan.templates.ElemForEach; 41 import org.apache.xalan.templates.ElemIf; 42 import org.apache.xalan.templates.ElemLiteralResult; 43 import org.apache.xalan.templates.ElemMessage; 44 import org.apache.xalan.templates.ElemNumber; 45 import org.apache.xalan.templates.ElemOtherwise; 46 import org.apache.xalan.templates.ElemPI; 47 import org.apache.xalan.templates.ElemParam; 48 import org.apache.xalan.templates.ElemSort; 49 import org.apache.xalan.templates.ElemTemplate; 50 import org.apache.xalan.templates.ElemText; 51 import org.apache.xalan.templates.ElemTextLiteral; 52 import org.apache.xalan.templates.ElemUnknown; 53 import org.apache.xalan.templates.ElemValueOf; 54 import org.apache.xalan.templates.ElemVariable; 55 import org.apache.xalan.templates.ElemWhen; 56 import org.apache.xalan.templates.ElemWithParam; 57 import org.apache.xml.utils.QName; 58 59 /** 60 * This class defines the allowed structure for a stylesheet, and the 61 * mapping between Xalan classes and the markup elements in the stylesheet. 62 * @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a> 63 */ 64 public class XSLTSchema extends XSLTElementDef 65 { 66 67 /** 68 * Construct a XSLTSchema which represents the XSLT "schema". 69 */ 70 XSLTSchema() 71 { 72 build(); 73 } 74 75 /** 76 * This method builds an XSLT "schema" according to http://www.w3.org/TR/xslt#dtd. This 77 * schema provides instructions for building the Xalan Stylesheet (Templates) structure. 78 */ 79 void build() 80 { 81 // xsl:import, xsl:include 82 XSLTAttributeDef hrefAttr = new XSLTAttributeDef(null, "href", 83 XSLTAttributeDef.T_URL, true, false,XSLTAttributeDef.ERROR); 84 85 // xsl:preserve-space, xsl:strip-space 86 XSLTAttributeDef elementsAttr = new XSLTAttributeDef(null, "elements", 87 XSLTAttributeDef.T_SIMPLEPATTERNLIST, 88 true, false, XSLTAttributeDef.ERROR); 89 90 // XSLTAttributeDef anyNamespacedAttr = new XSLTAttributeDef("*", "*", 91 // XSLTAttributeDef.T_CDATA, false); 92 93 // xsl:output 94 XSLTAttributeDef methodAttr = new XSLTAttributeDef(null, "method", 95 XSLTAttributeDef.T_QNAME, false, false,XSLTAttributeDef.ERROR); 96 XSLTAttributeDef versionAttr = new XSLTAttributeDef(null, "version", 97 XSLTAttributeDef.T_NMTOKEN, false, false,XSLTAttributeDef.ERROR); 98 XSLTAttributeDef encodingAttr = new XSLTAttributeDef(null, "encoding", 99 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 /* ,"‰" */); 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 923