1 /* 2 * Summary: internal data structures, constants and functions 3 * Description: Internal data structures, constants and functions used 4 * by the XSLT engine. 5 * They are not part of the API or ABI, i.e. they can change 6 * without prior notice, use carefully. 7 * 8 * Copy: See Copyright for the status of this software. 9 * 10 * Author: Daniel Veillard 11 */ 12 13 #ifndef __XML_XSLT_INTERNALS_H__ 14 #define __XML_XSLT_INTERNALS_H__ 15 16 #include <libxml/tree.h> 17 #include <libxml/hash.h> 18 #include <libxml/xpath.h> 19 #include <libxml/xmlerror.h> 20 #include <libxml/dict.h> 21 #include <libxml/xmlstring.h> 22 #include <libxslt/xslt.h> 23 #include "xsltexports.h" 24 #include "xsltlocale.h" 25 #include "numbersInternals.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* #define XSLT_DEBUG_PROFILE_CACHE */ 32 33 /** 34 * XSLT_IS_TEXT_NODE: 35 * 36 * check if the argument is a text node 37 */ 38 #define XSLT_IS_TEXT_NODE(n) ((n != NULL) && \ 39 (((n)->type == XML_TEXT_NODE) || \ 40 ((n)->type == XML_CDATA_SECTION_NODE))) 41 42 43 /** 44 * XSLT_MARK_RES_TREE_FRAG: 45 * 46 * internal macro to set up tree fragments 47 */ 48 #define XSLT_MARK_RES_TREE_FRAG(n) \ 49 (n)->name = (char *) xmlStrdup(BAD_CAST " fake node libxslt"); 50 51 /** 52 * XSLT_IS_RES_TREE_FRAG: 53 * 54 * internal macro to test tree fragments 55 */ 56 #define XSLT_IS_RES_TREE_FRAG(n) \ 57 ((n != NULL) && ((n)->type == XML_DOCUMENT_NODE) && \ 58 ((n)->name != NULL) && ((n)->name[0] == ' ')) 59 60 /** 61 * XSLT_REFACTORED_KEYCOMP: 62 * 63 * Internal define to enable on-demand xsl:key computation. 64 * That's the only mode now but the define is kept for compatibility 65 */ 66 #define XSLT_REFACTORED_KEYCOMP 67 68 /** 69 * XSLT_FAST_IF: 70 * 71 * Internal define to enable usage of xmlXPathCompiledEvalToBoolean() 72 * for XSLT "tests"; e.g. in <xsl:if test="/foo/bar"> 73 */ 74 #define XSLT_FAST_IF 75 76 /** 77 * XSLT_REFACTORED: 78 * 79 * Internal define to enable the refactored parts of Libxslt. 80 */ 81 /* #define XSLT_REFACTORED */ 82 /* ==================================================================== */ 83 84 /** 85 * XSLT_REFACTORED_VARS: 86 * 87 * Internal define to enable the refactored variable part of libxslt 88 */ 89 #define XSLT_REFACTORED_VARS 90 91 #ifdef XSLT_REFACTORED 92 93 extern const xmlChar *xsltXSLTAttrMarker; 94 95 96 /* TODO: REMOVE: #define XSLT_REFACTORED_EXCLRESNS */ 97 98 /* TODO: REMOVE: #define XSLT_REFACTORED_NSALIAS */ 99 100 /** 101 * XSLT_REFACTORED_XSLT_NSCOMP 102 * 103 * Internal define to enable the pointer-comparison of 104 * namespaces of XSLT elements. 105 */ 106 /* #define XSLT_REFACTORED_XSLT_NSCOMP */ 107 108 #ifdef XSLT_REFACTORED_XSLT_NSCOMP 109 110 extern const xmlChar *xsltConstNamespaceNameXSLT; 111 112 /** 113 * IS_XSLT_ELEM_FAST: 114 * 115 * quick test to detect XSLT elements 116 */ 117 #define IS_XSLT_ELEM_FAST(n) \ 118 (((n) != NULL) && ((n)->ns != NULL) && \ 119 ((n)->ns->href == xsltConstNamespaceNameXSLT)) 120 121 /** 122 * IS_XSLT_ATTR_FAST: 123 * 124 * quick test to detect XSLT attributes 125 */ 126 #define IS_XSLT_ATTR_FAST(a) \ 127 (((a) != NULL) && ((a)->ns != NULL) && \ 128 ((a)->ns->href == xsltConstNamespaceNameXSLT)) 129 130 /** 131 * XSLT_HAS_INTERNAL_NSMAP: 132 * 133 * check for namespace mapping 134 */ 135 #define XSLT_HAS_INTERNAL_NSMAP(s) \ 136 (((s) != NULL) && ((s)->principal) && \ 137 ((s)->principal->principalData) && \ 138 ((s)->principal->principalData->nsMap)) 139 140 /** 141 * XSLT_GET_INTERNAL_NSMAP: 142 * 143 * get pointer to namespace map 144 */ 145 #define XSLT_GET_INTERNAL_NSMAP(s) ((s)->principal->principalData->nsMap) 146 147 #else /* XSLT_REFACTORED_XSLT_NSCOMP */ 148 149 /** 150 * IS_XSLT_ELEM_FAST: 151 * 152 * quick check whether this is an xslt element 153 */ 154 #define IS_XSLT_ELEM_FAST(n) \ 155 (((n) != NULL) && ((n)->ns != NULL) && \ 156 (xmlStrEqual((n)->ns->href, XSLT_NAMESPACE))) 157 158 /** 159 * IS_XSLT_ATTR_FAST: 160 * 161 * quick check for xslt namespace attribute 162 */ 163 #define IS_XSLT_ATTR_FAST(a) \ 164 (((a) != NULL) && ((a)->ns != NULL) && \ 165 (xmlStrEqual((a)->ns->href, XSLT_NAMESPACE))) 166 167 168 #endif /* XSLT_REFACTORED_XSLT_NSCOMP */ 169 170 171 /** 172 * XSLT_REFACTORED_MANDATORY_VERSION: 173 * 174 * TODO: Currently disabled to surpress regression test failures, since 175 * the old behaviour was that a missing version attribute 176 * produced a only a warning and not an error, which was incerrect. 177 * So the regression tests need to be fixed if this is enabled. 178 */ 179 /* #define XSLT_REFACTORED_MANDATORY_VERSION */ 180 181 /** 182 * xsltPointerList: 183 * 184 * Pointer-list for various purposes. 185 */ 186 typedef struct _xsltPointerList xsltPointerList; 187 typedef xsltPointerList *xsltPointerListPtr; 188 struct _xsltPointerList { 189 void **items; 190 int number; 191 int size; 192 }; 193 194 #endif 195 196 /** 197 * XSLT_REFACTORED_PARSING: 198 * 199 * Internal define to enable the refactored parts of Libxslt 200 * related to parsing. 201 */ 202 /* #define XSLT_REFACTORED_PARSING */ 203 204 /** 205 * XSLT_MAX_SORT: 206 * 207 * Max number of specified xsl:sort on an element. 208 */ 209 #define XSLT_MAX_SORT 15 210 211 /** 212 * XSLT_PAT_NO_PRIORITY: 213 * 214 * Specific value for pattern without priority expressed. 215 */ 216 #define XSLT_PAT_NO_PRIORITY -12345789 217 218 /** 219 * xsltRuntimeExtra: 220 * 221 * Extra information added to the transformation context. 222 */ 223 typedef struct _xsltRuntimeExtra xsltRuntimeExtra; 224 typedef xsltRuntimeExtra *xsltRuntimeExtraPtr; 225 struct _xsltRuntimeExtra { 226 void *info; /* pointer to the extra data */ 227 xmlFreeFunc deallocate; /* pointer to the deallocation routine */ 228 union { /* dual-purpose field */ 229 void *ptr; /* data not needing deallocation */ 230 int ival; /* integer value storage */ 231 } val; 232 }; 233 234 /** 235 * XSLT_RUNTIME_EXTRA_LST: 236 * @ctxt: the transformation context 237 * @nr: the index 238 * 239 * Macro used to access extra information stored in the context 240 */ 241 #define XSLT_RUNTIME_EXTRA_LST(ctxt, nr) (ctxt)->extras[(nr)].info 242 /** 243 * XSLT_RUNTIME_EXTRA_FREE: 244 * @ctxt: the transformation context 245 * @nr: the index 246 * 247 * Macro used to free extra information stored in the context 248 */ 249 #define XSLT_RUNTIME_EXTRA_FREE(ctxt, nr) (ctxt)->extras[(nr)].deallocate 250 /** 251 * XSLT_RUNTIME_EXTRA: 252 * @ctxt: the transformation context 253 * @nr: the index 254 * 255 * Macro used to define extra information stored in the context 256 */ 257 #define XSLT_RUNTIME_EXTRA(ctxt, nr, typ) (ctxt)->extras[(nr)].val.typ 258 259 /** 260 * xsltTemplate: 261 * 262 * The in-memory structure corresponding to an XSLT Template. 263 */ 264 typedef struct _xsltTemplate xsltTemplate; 265 typedef xsltTemplate *xsltTemplatePtr; 266 struct _xsltTemplate { 267 struct _xsltTemplate *next;/* chained list sorted by priority */ 268 struct _xsltStylesheet *style;/* the containing stylesheet */ 269 xmlChar *match; /* the matching string */ 270 float priority; /* as given from the stylesheet, not computed */ 271 const xmlChar *name; /* the local part of the name QName */ 272 const xmlChar *nameURI; /* the URI part of the name QName */ 273 const xmlChar *mode;/* the local part of the mode QName */ 274 const xmlChar *modeURI;/* the URI part of the mode QName */ 275 xmlNodePtr content; /* the template replacement value */ 276 xmlNodePtr elem; /* the source element */ 277 278 /* 279 * TODO: @inheritedNsNr and @inheritedNs won't be used in the 280 * refactored code. 281 */ 282 int inheritedNsNr; /* number of inherited namespaces */ 283 xmlNsPtr *inheritedNs;/* inherited non-excluded namespaces */ 284 285 /* Profiling information */ 286 int nbCalls; /* the number of time the template was called */ 287 unsigned long time; /* the time spent in this template */ 288 void *params; /* xsl:param instructions */ 289 290 int templNr; /* Nb of templates in the stack */ 291 int templMax; /* Size of the templtes stack */ 292 xsltTemplatePtr *templCalledTab; /* templates called */ 293 int *templCountTab; /* .. and how often */ 294 295 /* Conflict resolution */ 296 int position; 297 }; 298 299 /** 300 * xsltDecimalFormat: 301 * 302 * Data structure of decimal-format. 303 */ 304 typedef struct _xsltDecimalFormat xsltDecimalFormat; 305 typedef xsltDecimalFormat *xsltDecimalFormatPtr; 306 struct _xsltDecimalFormat { 307 struct _xsltDecimalFormat *next; /* chained list */ 308 xmlChar *name; 309 /* Used for interpretation of pattern */ 310 xmlChar *digit; 311 xmlChar *patternSeparator; 312 /* May appear in result */ 313 xmlChar *minusSign; 314 xmlChar *infinity; 315 xmlChar *noNumber; /* Not-a-number */ 316 /* Used for interpretation of pattern and may appear in result */ 317 xmlChar *decimalPoint; 318 xmlChar *grouping; 319 xmlChar *percent; 320 xmlChar *permille; 321 xmlChar *zeroDigit; 322 const xmlChar *nsUri; 323 }; 324 325 /** 326 * xsltDocument: 327 * 328 * Data structure associated to a parsed document. 329 */ 330 typedef struct _xsltDocument xsltDocument; 331 typedef xsltDocument *xsltDocumentPtr; 332 struct _xsltDocument { 333 struct _xsltDocument *next; /* documents are kept in a chained list */ 334 int main; /* is this the main document */ 335 xmlDocPtr doc; /* the parsed document */ 336 void *keys; /* key tables storage */ 337 struct _xsltDocument *includes; /* subsidiary includes */ 338 int preproc; /* pre-processing already done */ 339 int nbKeysComputed; 340 }; 341 342 /** 343 * xsltKeyDef: 344 * 345 * Representation of an xsl:key. 346 */ 347 typedef struct _xsltKeyDef xsltKeyDef; 348 typedef xsltKeyDef *xsltKeyDefPtr; 349 struct _xsltKeyDef { 350 struct _xsltKeyDef *next; 351 xmlNodePtr inst; 352 xmlChar *name; 353 xmlChar *nameURI; 354 xmlChar *match; 355 xmlChar *use; 356 xmlXPathCompExprPtr comp; 357 xmlXPathCompExprPtr usecomp; 358 xmlNsPtr *nsList; /* the namespaces in scope */ 359 int nsNr; /* the number of namespaces in scope */ 360 }; 361 362 /** 363 * xsltKeyTable: 364 * 365 * Holds the computed keys for key definitions of the same QName. 366 * Is owned by an xsltDocument. 367 */ 368 typedef struct _xsltKeyTable xsltKeyTable; 369 typedef xsltKeyTable *xsltKeyTablePtr; 370 struct _xsltKeyTable { 371 struct _xsltKeyTable *next; 372 xmlChar *name; 373 xmlChar *nameURI; 374 xmlHashTablePtr keys; 375 }; 376 377 /* 378 * The in-memory structure corresponding to an XSLT Stylesheet. 379 * NOTE: most of the content is simply linked from the doc tree 380 * structure, no specific allocation is made. 381 */ 382 typedef struct _xsltStylesheet xsltStylesheet; 383 typedef xsltStylesheet *xsltStylesheetPtr; 384 385 typedef struct _xsltTransformContext xsltTransformContext; 386 typedef xsltTransformContext *xsltTransformContextPtr; 387 388 /** 389 * xsltElemPreComp: 390 * 391 * The in-memory structure corresponding to element precomputed data, 392 * designed to be extended by extension implementors. 393 */ 394 typedef struct _xsltElemPreComp xsltElemPreComp; 395 typedef xsltElemPreComp *xsltElemPreCompPtr; 396 397 /** 398 * xsltTransformFunction: 399 * @ctxt: the XSLT transformation context 400 * @node: the input node 401 * @inst: the stylesheet node 402 * @comp: the compiled information from the stylesheet 403 * 404 * Signature of the function associated to elements part of the 405 * stylesheet language like xsl:if or xsl:apply-templates. 406 */ 407 typedef void (*xsltTransformFunction) (xsltTransformContextPtr ctxt, 408 xmlNodePtr node, 409 xmlNodePtr inst, 410 xsltElemPreCompPtr comp); 411 412 /** 413 * xsltSortFunc: 414 * @ctxt: a transformation context 415 * @sorts: the node-set to sort 416 * @nbsorts: the number of sorts 417 * 418 * Signature of the function to use during sorting 419 */ 420 typedef void (*xsltSortFunc) (xsltTransformContextPtr ctxt, xmlNodePtr *sorts, 421 int nbsorts); 422 423 typedef enum { 424 XSLT_FUNC_COPY=1, 425 XSLT_FUNC_SORT, 426 XSLT_FUNC_TEXT, 427 XSLT_FUNC_ELEMENT, 428 XSLT_FUNC_ATTRIBUTE, 429 XSLT_FUNC_COMMENT, 430 XSLT_FUNC_PI, 431 XSLT_FUNC_COPYOF, 432 XSLT_FUNC_VALUEOF, 433 XSLT_FUNC_NUMBER, 434 XSLT_FUNC_APPLYIMPORTS, 435 XSLT_FUNC_CALLTEMPLATE, 436 XSLT_FUNC_APPLYTEMPLATES, 437 XSLT_FUNC_CHOOSE, 438 XSLT_FUNC_IF, 439 XSLT_FUNC_FOREACH, 440 XSLT_FUNC_DOCUMENT, 441 XSLT_FUNC_WITHPARAM, 442 XSLT_FUNC_PARAM, 443 XSLT_FUNC_VARIABLE, 444 XSLT_FUNC_WHEN, 445 XSLT_FUNC_EXTENSION 446 #ifdef XSLT_REFACTORED 447 , 448 XSLT_FUNC_OTHERWISE, 449 XSLT_FUNC_FALLBACK, 450 XSLT_FUNC_MESSAGE, 451 XSLT_FUNC_INCLUDE, 452 XSLT_FUNC_ATTRSET, 453 XSLT_FUNC_LITERAL_RESULT_ELEMENT, 454 XSLT_FUNC_UNKOWN_FORWARDS_COMPAT 455 #endif 456 } xsltStyleType; 457 458 /** 459 * xsltElemPreCompDeallocator: 460 * @comp: the #xsltElemPreComp to free up 461 * 462 * Deallocates an #xsltElemPreComp structure. 463 */ 464 typedef void (*xsltElemPreCompDeallocator) (xsltElemPreCompPtr comp); 465 466 /** 467 * xsltElemPreComp: 468 * 469 * The basic structure for compiled items of the AST of the XSLT processor. 470 * This structure is also intended to be extended by extension implementors. 471 * TODO: This is somehow not nice, since it has a "free" field, which 472 * derived stylesheet-structs do not have. 473 */ 474 struct _xsltElemPreComp { 475 xsltElemPreCompPtr next; /* next item in the global chained 476 list held by xsltStylesheet. */ 477 xsltStyleType type; /* type of the element */ 478 xsltTransformFunction func; /* handling function */ 479 xmlNodePtr inst; /* the node in the stylesheet's tree 480 corresponding to this item */ 481 482 /* end of common part */ 483 xsltElemPreCompDeallocator free; /* the deallocator */ 484 }; 485 486 /** 487 * xsltStylePreComp: 488 * 489 * The abstract basic structure for items of the XSLT processor. 490 * This includes: 491 * 1) compiled forms of XSLT instructions (xsl:if, xsl:attribute, etc.) 492 * 2) compiled forms of literal result elements 493 * 3) compiled forms of extension elements 494 */ 495 typedef struct _xsltStylePreComp xsltStylePreComp; 496 typedef xsltStylePreComp *xsltStylePreCompPtr; 497 498 #ifdef XSLT_REFACTORED 499 500 /* 501 * Some pointer-list utility functions. 502 */ 503 XSLTPUBFUN xsltPointerListPtr XSLTCALL 504 xsltPointerListCreate (int initialSize); 505 XSLTPUBFUN void XSLTCALL 506 xsltPointerListFree (xsltPointerListPtr list); 507 XSLTPUBFUN void XSLTCALL 508 xsltPointerListClear (xsltPointerListPtr list); 509 XSLTPUBFUN int XSLTCALL 510 xsltPointerListAddSize (xsltPointerListPtr list, 511 void *item, 512 int initialSize); 513 514 /************************************************************************ 515 * * 516 * Refactored structures * 517 * * 518 ************************************************************************/ 519 520 typedef struct _xsltNsListContainer xsltNsListContainer; 521 typedef xsltNsListContainer *xsltNsListContainerPtr; 522 struct _xsltNsListContainer { 523 xmlNsPtr *list; 524 int totalNumber; 525 int xpathNumber; 526 }; 527 528 /** 529 * XSLT_ITEM_COMPATIBILITY_FIELDS: 530 * 531 * Fields for API compatibility to the structure 532 * _xsltElemPreComp which is used for extension functions. 533 * Note that @next is used for storage; it does not reflect a next 534 * sibling in the tree. 535 * TODO: Evaluate if we really need such a compatibility. 536 */ 537 #define XSLT_ITEM_COMPATIBILITY_FIELDS \ 538 xsltElemPreCompPtr next;\ 539 xsltStyleType type;\ 540 xsltTransformFunction func;\ 541 xmlNodePtr inst; 542 543 /** 544 * XSLT_ITEM_NAVIGATION_FIELDS: 545 * 546 * Currently empty. 547 * TODO: It is intended to hold navigational fields in the future. 548 */ 549 #define XSLT_ITEM_NAVIGATION_FIELDS 550 /* 551 xsltStylePreCompPtr parent;\ 552 xsltStylePreCompPtr children;\ 553 xsltStylePreCompPtr nextItem; 554 */ 555 556 /** 557 * XSLT_ITEM_NSINSCOPE_FIELDS: 558 * 559 * The in-scope namespaces. 560 */ 561 #define XSLT_ITEM_NSINSCOPE_FIELDS xsltNsListContainerPtr inScopeNs; 562 563 /** 564 * XSLT_ITEM_COMMON_FIELDS: 565 * 566 * Common fields used for all items. 567 */ 568 #define XSLT_ITEM_COMMON_FIELDS \ 569 XSLT_ITEM_COMPATIBILITY_FIELDS \ 570 XSLT_ITEM_NAVIGATION_FIELDS \ 571 XSLT_ITEM_NSINSCOPE_FIELDS 572 573 /** 574 * _xsltStylePreComp: 575 * 576 * The abstract basic structure for items of the XSLT processor. 577 * This includes: 578 * 1) compiled forms of XSLT instructions (e.g. xsl:if, xsl:attribute, etc.) 579 * 2) compiled forms of literal result elements 580 * 3) various properties for XSLT instructions (e.g. xsl:when, 581 * xsl:with-param) 582 * 583 * REVISIT TODO: Keep this structure equal to the fields 584 * defined by XSLT_ITEM_COMMON_FIELDS 585 */ 586 struct _xsltStylePreComp { 587 xsltElemPreCompPtr next; /* next item in the global chained 588 list held by xsltStylesheet */ 589 xsltStyleType type; /* type of the item */ 590 xsltTransformFunction func; /* handling function */ 591 xmlNodePtr inst; /* the node in the stylesheet's tree 592 corresponding to this item. */ 593 /* Currently no navigational fields. */ 594 xsltNsListContainerPtr inScopeNs; 595 }; 596 597 /** 598 * xsltStyleBasicEmptyItem: 599 * 600 * Abstract structure only used as a short-cut for 601 * XSLT items with no extra fields. 602 * NOTE that it is intended that this structure looks the same as 603 * _xsltStylePreComp. 604 */ 605 typedef struct _xsltStyleBasicEmptyItem xsltStyleBasicEmptyItem; 606 typedef xsltStyleBasicEmptyItem *xsltStyleBasicEmptyItemPtr; 607 608 struct _xsltStyleBasicEmptyItem { 609 XSLT_ITEM_COMMON_FIELDS 610 }; 611 612 /** 613 * xsltStyleBasicExpressionItem: 614 * 615 * Abstract structure only used as a short-cut for 616 * XSLT items with just an expression. 617 */ 618 typedef struct _xsltStyleBasicExpressionItem xsltStyleBasicExpressionItem; 619 typedef xsltStyleBasicExpressionItem *xsltStyleBasicExpressionItemPtr; 620 621 struct _xsltStyleBasicExpressionItem { 622 XSLT_ITEM_COMMON_FIELDS 623 624 const xmlChar *select; /* TODO: Change this to "expression". */ 625 xmlXPathCompExprPtr comp; /* TODO: Change this to compExpr. */ 626 }; 627 628 /************************************************************************ 629 * * 630 * XSLT-instructions/declarations * 631 * * 632 ************************************************************************/ 633 634 /** 635 * xsltStyleItemElement: 636 * 637 * <!-- Category: instruction --> 638 * <xsl:element 639 * name = { qname } 640 * namespace = { uri-reference } 641 * use-attribute-sets = qnames> 642 * <!-- Content: template --> 643 * </xsl:element> 644 */ 645 typedef struct _xsltStyleItemElement xsltStyleItemElement; 646 typedef xsltStyleItemElement *xsltStyleItemElementPtr; 647 648 struct _xsltStyleItemElement { 649 XSLT_ITEM_COMMON_FIELDS 650 651 const xmlChar *use; 652 int has_use; 653 const xmlChar *name; 654 int has_name; 655 const xmlChar *ns; 656 const xmlChar *nsPrefix; 657 int has_ns; 658 }; 659 660 /** 661 * xsltStyleItemAttribute: 662 * 663 * <!-- Category: instruction --> 664 * <xsl:attribute 665 * name = { qname } 666 * namespace = { uri-reference }> 667 * <!-- Content: template --> 668 * </xsl:attribute> 669 */ 670 typedef struct _xsltStyleItemAttribute xsltStyleItemAttribute; 671 typedef xsltStyleItemAttribute *xsltStyleItemAttributePtr; 672 673 struct _xsltStyleItemAttribute { 674 XSLT_ITEM_COMMON_FIELDS 675 const xmlChar *name; 676 int has_name; 677 const xmlChar *ns; 678 const xmlChar *nsPrefix; 679 int has_ns; 680 }; 681 682 /** 683 * xsltStyleItemText: 684 * 685 * <!-- Category: instruction --> 686 * <xsl:text 687 * disable-output-escaping = "yes" | "no"> 688 * <!-- Content: #PCDATA --> 689 * </xsl:text> 690 */ 691 typedef struct _xsltStyleItemText xsltStyleItemText; 692 typedef xsltStyleItemText *xsltStyleItemTextPtr; 693 694 struct _xsltStyleItemText { 695 XSLT_ITEM_COMMON_FIELDS 696 int noescape; /* text */ 697 }; 698 699 /** 700 * xsltStyleItemComment: 701 * 702 * <!-- Category: instruction --> 703 * <xsl:comment> 704 * <!-- Content: template --> 705 * </xsl:comment> 706 */ 707 typedef xsltStyleBasicEmptyItem xsltStyleItemComment; 708 typedef xsltStyleItemComment *xsltStyleItemCommentPtr; 709 710 /** 711 * xsltStyleItemPI: 712 * 713 * <!-- Category: instruction --> 714 * <xsl:processing-instruction 715 * name = { ncname }> 716 * <!-- Content: template --> 717 * </xsl:processing-instruction> 718 */ 719 typedef struct _xsltStyleItemPI xsltStyleItemPI; 720 typedef xsltStyleItemPI *xsltStyleItemPIPtr; 721 722 struct _xsltStyleItemPI { 723 XSLT_ITEM_COMMON_FIELDS 724 const xmlChar *name; 725 int has_name; 726 }; 727 728 /** 729 * xsltStyleItemApplyImports: 730 * 731 * <!-- Category: instruction --> 732 * <xsl:apply-imports /> 733 */ 734 typedef xsltStyleBasicEmptyItem xsltStyleItemApplyImports; 735 typedef xsltStyleItemApplyImports *xsltStyleItemApplyImportsPtr; 736 737 /** 738 * xsltStyleItemApplyTemplates: 739 * 740 * <!-- Category: instruction --> 741 * <xsl:apply-templates 742 * select = node-set-expression 743 * mode = qname> 744 * <!-- Content: (xsl:sort | xsl:with-param)* --> 745 * </xsl:apply-templates> 746 */ 747 typedef struct _xsltStyleItemApplyTemplates xsltStyleItemApplyTemplates; 748 typedef xsltStyleItemApplyTemplates *xsltStyleItemApplyTemplatesPtr; 749 750 struct _xsltStyleItemApplyTemplates { 751 XSLT_ITEM_COMMON_FIELDS 752 753 const xmlChar *mode; /* apply-templates */ 754 const xmlChar *modeURI; /* apply-templates */ 755 const xmlChar *select; /* sort, copy-of, value-of, apply-templates */ 756 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */ 757 /* TODO: with-params */ 758 }; 759 760 /** 761 * xsltStyleItemCallTemplate: 762 * 763 * <!-- Category: instruction --> 764 * <xsl:call-template 765 * name = qname> 766 * <!-- Content: xsl:with-param* --> 767 * </xsl:call-template> 768 */ 769 typedef struct _xsltStyleItemCallTemplate xsltStyleItemCallTemplate; 770 typedef xsltStyleItemCallTemplate *xsltStyleItemCallTemplatePtr; 771 772 struct _xsltStyleItemCallTemplate { 773 XSLT_ITEM_COMMON_FIELDS 774 775 xsltTemplatePtr templ; /* call-template */ 776 const xmlChar *name; /* element, attribute, pi */ 777 int has_name; /* element, attribute, pi */ 778 const xmlChar *ns; /* element */ 779 int has_ns; /* element */ 780 /* TODO: with-params */ 781 }; 782 783 /** 784 * xsltStyleItemCopy: 785 * 786 * <!-- Category: instruction --> 787 * <xsl:copy 788 * use-attribute-sets = qnames> 789 * <!-- Content: template --> 790 * </xsl:copy> 791 */ 792 typedef struct _xsltStyleItemCopy xsltStyleItemCopy; 793 typedef xsltStyleItemCopy *xsltStyleItemCopyPtr; 794 795 struct _xsltStyleItemCopy { 796 XSLT_ITEM_COMMON_FIELDS 797 const xmlChar *use; /* copy, element */ 798 int has_use; /* copy, element */ 799 }; 800 801 /** 802 * xsltStyleItemIf: 803 * 804 * <!-- Category: instruction --> 805 * <xsl:if 806 * test = boolean-expression> 807 * <!-- Content: template --> 808 * </xsl:if> 809 */ 810 typedef struct _xsltStyleItemIf xsltStyleItemIf; 811 typedef xsltStyleItemIf *xsltStyleItemIfPtr; 812 813 struct _xsltStyleItemIf { 814 XSLT_ITEM_COMMON_FIELDS 815 816 const xmlChar *test; /* if */ 817 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */ 818 }; 819 820 821 /** 822 * xsltStyleItemCopyOf: 823 * 824 * <!-- Category: instruction --> 825 * <xsl:copy-of 826 * select = expression /> 827 */ 828 typedef xsltStyleBasicExpressionItem xsltStyleItemCopyOf; 829 typedef xsltStyleItemCopyOf *xsltStyleItemCopyOfPtr; 830 831 /** 832 * xsltStyleItemValueOf: 833 * 834 * <!-- Category: instruction --> 835 * <xsl:value-of 836 * select = string-expression 837 * disable-output-escaping = "yes" | "no" /> 838 */ 839 typedef struct _xsltStyleItemValueOf xsltStyleItemValueOf; 840 typedef xsltStyleItemValueOf *xsltStyleItemValueOfPtr; 841 842 struct _xsltStyleItemValueOf { 843 XSLT_ITEM_COMMON_FIELDS 844 845 const xmlChar *select; 846 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */ 847 int noescape; 848 }; 849 850 /** 851 * xsltStyleItemNumber: 852 * 853 * <!-- Category: instruction --> 854 * <xsl:number 855 * level = "single" | "multiple" | "any" 856 * count = pattern 857 * from = pattern 858 * value = number-expression 859 * format = { string } 860 * lang = { nmtoken } 861 * letter-value = { "alphabetic" | "traditional" } 862 * grouping-separator = { char } 863 * grouping-size = { number } /> 864 */ 865 typedef struct _xsltStyleItemNumber xsltStyleItemNumber; 866 typedef xsltStyleItemNumber *xsltStyleItemNumberPtr; 867 868 struct _xsltStyleItemNumber { 869 XSLT_ITEM_COMMON_FIELDS 870 xsltNumberData numdata; /* number */ 871 }; 872 873 /** 874 * xsltStyleItemChoose: 875 * 876 * <!-- Category: instruction --> 877 * <xsl:choose> 878 * <!-- Content: (xsl:when+, xsl:otherwise?) --> 879 * </xsl:choose> 880 */ 881 typedef xsltStyleBasicEmptyItem xsltStyleItemChoose; 882 typedef xsltStyleItemChoose *xsltStyleItemChoosePtr; 883 884 /** 885 * xsltStyleItemFallback: 886 * 887 * <!-- Category: instruction --> 888 * <xsl:fallback> 889 * <!-- Content: template --> 890 * </xsl:fallback> 891 */ 892 typedef xsltStyleBasicEmptyItem xsltStyleItemFallback; 893 typedef xsltStyleItemFallback *xsltStyleItemFallbackPtr; 894 895 /** 896 * xsltStyleItemForEach: 897 * 898 * <!-- Category: instruction --> 899 * <xsl:for-each 900 * select = node-set-expression> 901 * <!-- Content: (xsl:sort*, template) --> 902 * </xsl:for-each> 903 */ 904 typedef xsltStyleBasicExpressionItem xsltStyleItemForEach; 905 typedef xsltStyleItemForEach *xsltStyleItemForEachPtr; 906 907 /** 908 * xsltStyleItemMessage: 909 * 910 * <!-- Category: instruction --> 911 * <xsl:message 912 * terminate = "yes" | "no"> 913 * <!-- Content: template --> 914 * </xsl:message> 915 */ 916 typedef struct _xsltStyleItemMessage xsltStyleItemMessage; 917 typedef xsltStyleItemMessage *xsltStyleItemMessagePtr; 918 919 struct _xsltStyleItemMessage { 920 XSLT_ITEM_COMMON_FIELDS 921 int terminate; 922 }; 923 924 /** 925 * xsltStyleItemDocument: 926 * 927 * NOTE: This is not an instruction of XSLT 1.0. 928 */ 929 typedef struct _xsltStyleItemDocument xsltStyleItemDocument; 930 typedef xsltStyleItemDocument *xsltStyleItemDocumentPtr; 931 932 struct _xsltStyleItemDocument { 933 XSLT_ITEM_COMMON_FIELDS 934 int ver11; /* assigned: in xsltDocumentComp; 935 read: nowhere; 936 TODO: Check if we need. */ 937 const xmlChar *filename; /* document URL */ 938 int has_filename; 939 }; 940 941 /************************************************************************ 942 * * 943 * Non-instructions (actually properties of instructions/declarations) * 944 * * 945 ************************************************************************/ 946 947 /** 948 * xsltStyleBasicItemVariable: 949 * 950 * Basic struct for xsl:variable, xsl:param and xsl:with-param. 951 * It's currently important to have equal fields, since 952 * xsltParseStylesheetCallerParam() is used with xsl:with-param from 953 * the xslt side and with xsl:param from the exslt side (in 954 * exsltFuncFunctionFunction()). 955 * 956 * FUTURE NOTE: In XSLT 2.0 xsl:param, xsl:variable and xsl:with-param 957 * have additional different fields. 958 */ 959 typedef struct _xsltStyleBasicItemVariable xsltStyleBasicItemVariable; 960 typedef xsltStyleBasicItemVariable *xsltStyleBasicItemVariablePtr; 961 962 struct _xsltStyleBasicItemVariable { 963 XSLT_ITEM_COMMON_FIELDS 964 965 const xmlChar *select; 966 xmlXPathCompExprPtr comp; 967 968 const xmlChar *name; 969 int has_name; 970 const xmlChar *ns; 971 int has_ns; 972 }; 973 974 /** 975 * xsltStyleItemVariable: 976 * 977 * <!-- Category: top-level-element --> 978 * <xsl:param 979 * name = qname 980 * select = expression> 981 * <!-- Content: template --> 982 * </xsl:param> 983 */ 984 typedef xsltStyleBasicItemVariable xsltStyleItemVariable; 985 typedef xsltStyleItemVariable *xsltStyleItemVariablePtr; 986 987 /** 988 * xsltStyleItemParam: 989 * 990 * <!-- Category: top-level-element --> 991 * <xsl:param 992 * name = qname 993 * select = expression> 994 * <!-- Content: template --> 995 * </xsl:param> 996 */ 997 typedef struct _xsltStyleItemParam xsltStyleItemParam; 998 typedef xsltStyleItemParam *xsltStyleItemParamPtr; 999 1000 struct _xsltStyleItemParam { 1001 XSLT_ITEM_COMMON_FIELDS 1002 1003 const xmlChar *select; 1004 xmlXPathCompExprPtr comp; 1005 1006 const xmlChar *name; 1007 int has_name; 1008 const xmlChar *ns; 1009 int has_ns; 1010 }; 1011 1012 /** 1013 * xsltStyleItemWithParam: 1014 * 1015 * <xsl:with-param 1016 * name = qname 1017 * select = expression> 1018 * <!-- Content: template --> 1019 * </xsl:with-param> 1020 */ 1021 typedef xsltStyleBasicItemVariable xsltStyleItemWithParam; 1022 typedef xsltStyleItemWithParam *xsltStyleItemWithParamPtr; 1023 1024 /** 1025 * xsltStyleItemSort: 1026 * 1027 * Reflects the XSLT xsl:sort item. 1028 * Allowed parents: xsl:apply-templates, xsl:for-each 1029 * <xsl:sort 1030 * select = string-expression 1031 * lang = { nmtoken } 1032 * data-type = { "text" | "number" | qname-but-not-ncname } 1033 * order = { "ascending" | "descending" } 1034 * case-order = { "upper-first" | "lower-first" } /> 1035 */ 1036 typedef struct _xsltStyleItemSort xsltStyleItemSort; 1037 typedef xsltStyleItemSort *xsltStyleItemSortPtr; 1038 1039 struct _xsltStyleItemSort { 1040 XSLT_ITEM_COMMON_FIELDS 1041 1042 const xmlChar *stype; /* sort */ 1043 int has_stype; /* sort */ 1044 int number; /* sort */ 1045 const xmlChar *order; /* sort */ 1046 int has_order; /* sort */ 1047 int descending; /* sort */ 1048 const xmlChar *lang; /* sort */ 1049 int has_lang; /* sort */ 1050 xsltLocale locale; /* sort */ 1051 const xmlChar *case_order; /* sort */ 1052 int lower_first; /* sort */ 1053 1054 const xmlChar *use; 1055 int has_use; 1056 1057 const xmlChar *select; /* sort, copy-of, value-of, apply-templates */ 1058 1059 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */ 1060 }; 1061 1062 1063 /** 1064 * xsltStyleItemWhen: 1065 * 1066 * <xsl:when 1067 * test = boolean-expression> 1068 * <!-- Content: template --> 1069 * </xsl:when> 1070 * Allowed parent: xsl:choose 1071 */ 1072 typedef struct _xsltStyleItemWhen xsltStyleItemWhen; 1073 typedef xsltStyleItemWhen *xsltStyleItemWhenPtr; 1074 1075 struct _xsltStyleItemWhen { 1076 XSLT_ITEM_COMMON_FIELDS 1077 1078 const xmlChar *test; 1079 xmlXPathCompExprPtr comp; 1080 }; 1081 1082 /** 1083 * xsltStyleItemOtherwise: 1084 * 1085 * Allowed parent: xsl:choose 1086 * <xsl:otherwise> 1087 * <!-- Content: template --> 1088 * </xsl:otherwise> 1089 */ 1090 typedef struct _xsltStyleItemOtherwise xsltStyleItemOtherwise; 1091 typedef xsltStyleItemOtherwise *xsltStyleItemOtherwisePtr; 1092 1093 struct _xsltStyleItemOtherwise { 1094 XSLT_ITEM_COMMON_FIELDS 1095 }; 1096 1097 typedef struct _xsltStyleItemInclude xsltStyleItemInclude; 1098 typedef xsltStyleItemInclude *xsltStyleItemIncludePtr; 1099 1100 struct _xsltStyleItemInclude { 1101 XSLT_ITEM_COMMON_FIELDS 1102 xsltDocumentPtr include; 1103 }; 1104 1105 /************************************************************************ 1106 * * 1107 * XSLT elements in forwards-compatible mode * 1108 * * 1109 ************************************************************************/ 1110 1111 typedef struct _xsltStyleItemUknown xsltStyleItemUknown; 1112 typedef xsltStyleItemUknown *xsltStyleItemUknownPtr; 1113 struct _xsltStyleItemUknown { 1114 XSLT_ITEM_COMMON_FIELDS 1115 }; 1116 1117 1118 /************************************************************************ 1119 * * 1120 * Extension elements * 1121 * * 1122 ************************************************************************/ 1123 1124 /* 1125 * xsltStyleItemExtElement: 1126 * 1127 * Reflects extension elements. 1128 * 1129 * NOTE: Due to the fact that the structure xsltElemPreComp is most 1130 * probably already heavily in use out there by users, so we cannot 1131 * easily change it, we'll create an intermediate structure which will 1132 * hold an xsltElemPreCompPtr. 1133 * BIG NOTE: The only problem I see here is that the user processes the 1134 * content of the stylesheet tree, possibly he'll lookup the node->psvi 1135 * fields in order to find subsequent extension functions. 1136 * In this case, the user's code will break, since the node->psvi 1137 * field will hold now the xsltStyleItemExtElementPtr and not 1138 * the xsltElemPreCompPtr. 1139 * However the place where the structure is anchored in the node-tree, 1140 * namely node->psvi, has beed already once been moved from node->_private 1141 * to node->psvi, so we have a precedent here, which, I think, should allow 1142 * us to change such semantics without headaches. 1143 */ 1144 typedef struct _xsltStyleItemExtElement xsltStyleItemExtElement; 1145 typedef xsltStyleItemExtElement *xsltStyleItemExtElementPtr; 1146 struct _xsltStyleItemExtElement { 1147 XSLT_ITEM_COMMON_FIELDS 1148 xsltElemPreCompPtr item; 1149 }; 1150 1151 /************************************************************************ 1152 * * 1153 * Literal result elements * 1154 * * 1155 ************************************************************************/ 1156 1157 typedef struct _xsltEffectiveNs xsltEffectiveNs; 1158 typedef xsltEffectiveNs *xsltEffectiveNsPtr; 1159 struct _xsltEffectiveNs { 1160 xsltEffectiveNsPtr nextInStore; /* storage next */ 1161 xsltEffectiveNsPtr next; /* next item in the list */ 1162 const xmlChar *prefix; 1163 const xmlChar *nsName; 1164 /* 1165 * Indicates if eclared on the literal result element; dunno if really 1166 * needed. 1167 */ 1168 int holdByElem; 1169 }; 1170 1171 /* 1172 * Info for literal result elements. 1173 * This will be set on the elem->psvi field and will be 1174 * shared by literal result elements, which have the same 1175 * excluded result namespaces; i.e., this *won't* be created uniquely 1176 * for every literal result element. 1177 */ 1178 typedef struct _xsltStyleItemLRElementInfo xsltStyleItemLRElementInfo; 1179 typedef xsltStyleItemLRElementInfo *xsltStyleItemLRElementInfoPtr; 1180 struct _xsltStyleItemLRElementInfo { 1181 XSLT_ITEM_COMMON_FIELDS 1182 /* 1183 * @effectiveNs is the set of effective ns-nodes 1184 * on the literal result element, which will be added to the result 1185 * element if not already existing in the result tree. 1186 * This means that excluded namespaces (via exclude-result-prefixes, 1187 * extension-element-prefixes and the XSLT namespace) not added 1188 * to the set. 1189 * Namespace-aliasing was applied on the @effectiveNs. 1190 */ 1191 xsltEffectiveNsPtr effectiveNs; 1192 1193 }; 1194 1195 #ifdef XSLT_REFACTORED 1196 1197 typedef struct _xsltNsAlias xsltNsAlias; 1198 typedef xsltNsAlias *xsltNsAliasPtr; 1199 struct _xsltNsAlias { 1200 xsltNsAliasPtr next; /* next in the list */ 1201 xmlNsPtr literalNs; 1202 xmlNsPtr targetNs; 1203 xmlDocPtr docOfTargetNs; 1204 }; 1205 #endif 1206 1207 #ifdef XSLT_REFACTORED_XSLT_NSCOMP 1208 1209 typedef struct _xsltNsMap xsltNsMap; 1210 typedef xsltNsMap *xsltNsMapPtr; 1211 struct _xsltNsMap { 1212 xsltNsMapPtr next; /* next in the list */ 1213 xmlDocPtr doc; 1214 xmlNodePtr elem; /* the element holding the ns-decl */ 1215 xmlNsPtr ns; /* the xmlNs structure holding the XML namespace name */ 1216 const xmlChar *origNsName; /* the original XML namespace name */ 1217 const xmlChar *newNsName; /* the mapped XML namespace name */ 1218 }; 1219 #endif 1220 1221 /************************************************************************ 1222 * * 1223 * Compile-time structures for *internal* use only * 1224 * * 1225 ************************************************************************/ 1226 1227 typedef struct _xsltPrincipalStylesheetData xsltPrincipalStylesheetData; 1228 typedef xsltPrincipalStylesheetData *xsltPrincipalStylesheetDataPtr; 1229 1230 typedef struct _xsltNsList xsltNsList; 1231 typedef xsltNsList *xsltNsListPtr; 1232 struct _xsltNsList { 1233 xsltNsListPtr next; /* next in the list */ 1234 xmlNsPtr ns; 1235 }; 1236 1237 /* 1238 * xsltVarInfo: 1239 * 1240 * Used at compilation time for parameters and variables. 1241 */ 1242 typedef struct _xsltVarInfo xsltVarInfo; 1243 typedef xsltVarInfo *xsltVarInfoPtr; 1244 struct _xsltVarInfo { 1245 xsltVarInfoPtr next; /* next in the list */ 1246 xsltVarInfoPtr prev; 1247 int depth; /* the depth in the tree */ 1248 const xmlChar *name; 1249 const xmlChar *nsName; 1250 }; 1251 1252 /** 1253 * xsltCompilerNodeInfo: 1254 * 1255 * Per-node information during compile-time. 1256 */ 1257 typedef struct _xsltCompilerNodeInfo xsltCompilerNodeInfo; 1258 typedef xsltCompilerNodeInfo *xsltCompilerNodeInfoPtr; 1259 struct _xsltCompilerNodeInfo { 1260 xsltCompilerNodeInfoPtr next; 1261 xsltCompilerNodeInfoPtr prev; 1262 xmlNodePtr node; 1263 int depth; 1264 xsltTemplatePtr templ; /* The owning template */ 1265 int category; /* XSLT element, LR-element or 1266 extension element */ 1267 xsltStyleType type; 1268 xsltElemPreCompPtr item; /* The compiled information */ 1269 /* The current in-scope namespaces */ 1270 xsltNsListContainerPtr inScopeNs; 1271 /* The current excluded result namespaces */ 1272 xsltPointerListPtr exclResultNs; 1273 /* The current extension instruction namespaces */ 1274 xsltPointerListPtr extElemNs; 1275 1276 /* The current info for literal result elements. */ 1277 xsltStyleItemLRElementInfoPtr litResElemInfo; 1278 /* 1279 * Set to 1 if in-scope namespaces changed, 1280 * or excluded result namespaces changed, 1281 * or extension element namespaces changed. 1282 * This will trigger creation of new infos 1283 * for literal result elements. 1284 */ 1285 int nsChanged; 1286 int preserveWhitespace; 1287 int stripWhitespace; 1288 int isRoot; /* whether this is the stylesheet's root node */ 1289 int forwardsCompat; /* whether forwards-compatible mode is enabled */ 1290 /* whether the content of an extension element was processed */ 1291 int extContentHandled; 1292 /* the type of the current child */ 1293 xsltStyleType curChildType; 1294 }; 1295 1296 /** 1297 * XSLT_CCTXT: 1298 * 1299 * get pointer to compiler context 1300 */ 1301 #define XSLT_CCTXT(style) ((xsltCompilerCtxtPtr) style->compCtxt) 1302 1303 typedef enum { 1304 XSLT_ERROR_SEVERITY_ERROR = 0, 1305 XSLT_ERROR_SEVERITY_WARNING 1306 } xsltErrorSeverityType; 1307 1308 typedef struct _xsltCompilerCtxt xsltCompilerCtxt; 1309 typedef xsltCompilerCtxt *xsltCompilerCtxtPtr; 1310 struct _xsltCompilerCtxt { 1311 void *errorCtxt; /* user specific error context */ 1312 /* 1313 * used for error/warning reports; e.g. XSLT_ERROR_SEVERITY_WARNING */ 1314 xsltErrorSeverityType errSeverity; 1315 int warnings; /* TODO: number of warnings found at 1316 compilation */ 1317 int errors; /* TODO: number of errors found at 1318 compilation */ 1319 xmlDictPtr dict; 1320 xsltStylesheetPtr style; 1321 int simplified; /* whether this is a simplified stylesheet */ 1322 /* TODO: structured/unstructured error contexts. */ 1323 int depth; /* Current depth of processing */ 1324 1325 xsltCompilerNodeInfoPtr inode; 1326 xsltCompilerNodeInfoPtr inodeList; 1327 xsltCompilerNodeInfoPtr inodeLast; 1328 xsltPointerListPtr tmpList; /* Used for various purposes */ 1329 /* 1330 * The XSLT version as specified by the stylesheet's root element. 1331 */ 1332 int isInclude; 1333 int hasForwardsCompat; /* whether forwards-compatible mode was used 1334 in a parsing episode */ 1335 int maxNodeInfos; /* TEMP TODO: just for the interest */ 1336 int maxLREs; /* TEMP TODO: just for the interest */ 1337 /* 1338 * In order to keep the old behaviour, applying strict rules of 1339 * the spec can be turned off. This has effect only on special 1340 * mechanisms like whitespace-stripping in the stylesheet. 1341 */ 1342 int strict; 1343 xsltPrincipalStylesheetDataPtr psData; 1344 xsltStyleItemUknownPtr unknownItem; 1345 int hasNsAliases; /* Indicator if there was an xsl:namespace-alias. */ 1346 xsltNsAliasPtr nsAliases; 1347 xsltVarInfoPtr ivars; /* Storage of local in-scope variables/params. */ 1348 xsltVarInfoPtr ivar; /* topmost local variable/param. */ 1349 }; 1350 1351 #else /* XSLT_REFACTORED */ 1352 /* 1353 * The old structures before refactoring. 1354 */ 1355 1356 /** 1357 * _xsltStylePreComp: 1358 * 1359 * The in-memory structure corresponding to XSLT stylesheet constructs 1360 * precomputed data. 1361 */ 1362 struct _xsltStylePreComp { 1363 xsltElemPreCompPtr next; /* chained list */ 1364 xsltStyleType type; /* type of the element */ 1365 xsltTransformFunction func; /* handling function */ 1366 xmlNodePtr inst; /* the instruction */ 1367 1368 /* 1369 * Pre computed values. 1370 */ 1371 1372 const xmlChar *stype; /* sort */ 1373 int has_stype; /* sort */ 1374 int number; /* sort */ 1375 const xmlChar *order; /* sort */ 1376 int has_order; /* sort */ 1377 int descending; /* sort */ 1378 const xmlChar *lang; /* sort */ 1379 int has_lang; /* sort */ 1380 xsltLocale locale; /* sort */ 1381 const xmlChar *case_order; /* sort */ 1382 int lower_first; /* sort */ 1383 1384 const xmlChar *use; /* copy, element */ 1385 int has_use; /* copy, element */ 1386 1387 int noescape; /* text */ 1388 1389 const xmlChar *name; /* element, attribute, pi */ 1390 int has_name; /* element, attribute, pi */ 1391 const xmlChar *ns; /* element */ 1392 int has_ns; /* element */ 1393 1394 const xmlChar *mode; /* apply-templates */ 1395 const xmlChar *modeURI; /* apply-templates */ 1396 1397 const xmlChar *test; /* if */ 1398 1399 xsltTemplatePtr templ; /* call-template */ 1400 1401 const xmlChar *select; /* sort, copy-of, value-of, apply-templates */ 1402 1403 int ver11; /* document */ 1404 const xmlChar *filename; /* document URL */ 1405 int has_filename; /* document */ 1406 1407 xsltNumberData numdata; /* number */ 1408 1409 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */ 1410 xmlNsPtr *nsList; /* the namespaces in scope */ 1411 int nsNr; /* the number of namespaces in scope */ 1412 }; 1413 1414 #endif /* XSLT_REFACTORED */ 1415 1416 1417 /* 1418 * The in-memory structure corresponding to an XSLT Variable 1419 * or Param. 1420 */ 1421 typedef struct _xsltStackElem xsltStackElem; 1422 typedef xsltStackElem *xsltStackElemPtr; 1423 struct _xsltStackElem { 1424 struct _xsltStackElem *next;/* chained list */ 1425 xsltStylePreCompPtr comp; /* the compiled form */ 1426 int computed; /* was the evaluation done */ 1427 const xmlChar *name; /* the local part of the name QName */ 1428 const xmlChar *nameURI; /* the URI part of the name QName */ 1429 const xmlChar *select; /* the eval string */ 1430 xmlNodePtr tree; /* the sequence constructor if no eval 1431 string or the location */ 1432 xmlXPathObjectPtr value; /* The value if computed */ 1433 xmlDocPtr fragment; /* The Result Tree Fragments (needed for XSLT 1.0) 1434 which are bound to the variable's lifetime. */ 1435 int level; /* the depth in the tree; 1436 -1 if persistent (e.g. a given xsl:with-param) */ 1437 xsltTransformContextPtr context; /* The transformation context; needed to cache 1438 the variables */ 1439 int flags; 1440 }; 1441 1442 #ifdef XSLT_REFACTORED 1443 1444 struct _xsltPrincipalStylesheetData { 1445 /* 1446 * Namespace dictionary for ns-prefixes and ns-names: 1447 * TODO: Shared between stylesheets, and XPath mechanisms. 1448 * Not used yet. 1449 */ 1450 xmlDictPtr namespaceDict; 1451 /* 1452 * Global list of in-scope namespaces. 1453 */ 1454 xsltPointerListPtr inScopeNamespaces; 1455 /* 1456 * Global list of information for [xsl:]excluded-result-prefixes. 1457 */ 1458 xsltPointerListPtr exclResultNamespaces; 1459 /* 1460 * Global list of information for [xsl:]extension-element-prefixes. 1461 */ 1462 xsltPointerListPtr extElemNamespaces; 1463 xsltEffectiveNsPtr effectiveNs; 1464 #ifdef XSLT_REFACTORED_XSLT_NSCOMP 1465 /* 1466 * Namespace name map to get rid of string comparison of namespace names. 1467 */ 1468 xsltNsMapPtr nsMap; 1469 #endif 1470 }; 1471 1472 1473 #endif 1474 /* 1475 * Note that we added a @compCtxt field to anchor an stylesheet compilation 1476 * context, since, due to historical reasons, various compile-time function 1477 * take only the stylesheet as argument and not a compilation context. 1478 */ 1479 struct _xsltStylesheet { 1480 /* 1481 * The stylesheet import relation is kept as a tree. 1482 */ 1483 struct _xsltStylesheet *parent; 1484 struct _xsltStylesheet *next; 1485 struct _xsltStylesheet *imports; 1486 1487 xsltDocumentPtr docList; /* the include document list */ 1488 1489 /* 1490 * General data on the style sheet document. 1491 */ 1492 xmlDocPtr doc; /* the parsed XML stylesheet */ 1493 xmlHashTablePtr stripSpaces;/* the hash table of the strip-space and 1494 preserve space elements */ 1495 int stripAll; /* strip-space * (1) preserve-space * (-1) */ 1496 xmlHashTablePtr cdataSection;/* the hash table of the cdata-section */ 1497 1498 /* 1499 * Global variable or parameters. 1500 */ 1501 xsltStackElemPtr variables; /* linked list of param and variables */ 1502 1503 /* 1504 * Template descriptions. 1505 */ 1506 xsltTemplatePtr templates; /* the ordered list of templates */ 1507 xmlHashTablePtr templatesHash; /* hash table or wherever compiled 1508 templates information is stored */ 1509 struct _xsltCompMatch *rootMatch; /* template based on / */ 1510 struct _xsltCompMatch *keyMatch; /* template based on key() */ 1511 struct _xsltCompMatch *elemMatch; /* template based on * */ 1512 struct _xsltCompMatch *attrMatch; /* template based on @* */ 1513 struct _xsltCompMatch *parentMatch; /* template based on .. */ 1514 struct _xsltCompMatch *textMatch; /* template based on text() */ 1515 struct _xsltCompMatch *piMatch; /* template based on 1516 processing-instruction() */ 1517 struct _xsltCompMatch *commentMatch; /* template based on comment() */ 1518 1519 /* 1520 * Namespace aliases. 1521 * NOTE: Not used in the refactored code. 1522 */ 1523 xmlHashTablePtr nsAliases; /* the namespace alias hash tables */ 1524 1525 /* 1526 * Attribute sets. 1527 */ 1528 xmlHashTablePtr attributeSets;/* the attribute sets hash tables */ 1529 1530 /* 1531 * Namespaces. 1532 * TODO: Eliminate this. 1533 */ 1534 xmlHashTablePtr nsHash; /* the set of namespaces in use: 1535 ATTENTION: This is used for 1536 execution of XPath expressions; unfortunately 1537 it restricts the stylesheet to have distinct 1538 prefixes. 1539 TODO: We need to get rid of this. 1540 */ 1541 void *nsDefs; /* ATTENTION TODO: This is currently used to store 1542 xsltExtDefPtr (in extensions.c) and 1543 *not* xmlNsPtr. 1544 */ 1545 1546 /* 1547 * Key definitions. 1548 */ 1549 void *keys; /* key definitions */ 1550 1551 /* 1552 * Output related stuff. 1553 */ 1554 xmlChar *method; /* the output method */ 1555 xmlChar *methodURI; /* associated namespace if any */ 1556 xmlChar *version; /* version string */ 1557 xmlChar *encoding; /* encoding string */ 1558 int omitXmlDeclaration; /* omit-xml-declaration = "yes" | "no" */ 1559 1560 /* 1561 * Number formatting. 1562 */ 1563 xsltDecimalFormatPtr decimalFormat; 1564 int standalone; /* standalone = "yes" | "no" */ 1565 xmlChar *doctypePublic; /* doctype-public string */ 1566 xmlChar *doctypeSystem; /* doctype-system string */ 1567 int indent; /* should output being indented */ 1568 xmlChar *mediaType; /* media-type string */ 1569 1570 /* 1571 * Precomputed blocks. 1572 */ 1573 xsltElemPreCompPtr preComps;/* list of precomputed blocks */ 1574 int warnings; /* number of warnings found at compilation */ 1575 int errors; /* number of errors found at compilation */ 1576 1577 xmlChar *exclPrefix; /* last excluded prefixes */ 1578 xmlChar **exclPrefixTab; /* array of excluded prefixes */ 1579 int exclPrefixNr; /* number of excluded prefixes in scope */ 1580 int exclPrefixMax; /* size of the array */ 1581 1582 void *_private; /* user defined data */ 1583 1584 /* 1585 * Extensions. 1586 */ 1587 xmlHashTablePtr extInfos; /* the extension data */ 1588 int extrasNr; /* the number of extras required */ 1589 1590 /* 1591 * For keeping track of nested includes 1592 */ 1593 xsltDocumentPtr includes; /* points to last nested include */ 1594 1595 /* 1596 * dictionary: shared between stylesheet, context and documents. 1597 */ 1598 xmlDictPtr dict; 1599 /* 1600 * precompiled attribute value templates. 1601 */ 1602 void *attVTs; 1603 /* 1604 * if namespace-alias has an alias for the default stylesheet prefix 1605 * NOTE: Not used in the refactored code. 1606 */ 1607 const xmlChar *defaultAlias; 1608 /* 1609 * bypass pre-processing (already done) (used in imports) 1610 */ 1611 int nopreproc; 1612 /* 1613 * all document text strings were internalized 1614 */ 1615 int internalized; 1616 /* 1617 * Literal Result Element as Stylesheet c.f. section 2.3 1618 */ 1619 int literal_result; 1620 /* 1621 * The principal stylesheet 1622 */ 1623 xsltStylesheetPtr principal; 1624 #ifdef XSLT_REFACTORED 1625 /* 1626 * Compilation context used during compile-time. 1627 */ 1628 xsltCompilerCtxtPtr compCtxt; /* TODO: Change this to (void *). */ 1629 1630 xsltPrincipalStylesheetDataPtr principalData; 1631 #endif 1632 /* 1633 * Forwards-compatible processing 1634 */ 1635 int forwards_compatible; 1636 1637 xmlHashTablePtr namedTemplates; /* hash table of named templates */ 1638 1639 xmlXPathContextPtr xpathCtxt; 1640 }; 1641 1642 typedef struct _xsltTransformCache xsltTransformCache; 1643 typedef xsltTransformCache *xsltTransformCachePtr; 1644 struct _xsltTransformCache { 1645 xmlDocPtr RVT; 1646 int nbRVT; 1647 xsltStackElemPtr stackItems; 1648 int nbStackItems; 1649 #ifdef XSLT_DEBUG_PROFILE_CACHE 1650 int dbgCachedRVTs; 1651 int dbgReusedRVTs; 1652 int dbgCachedVars; 1653 int dbgReusedVars; 1654 #endif 1655 }; 1656 1657 /* 1658 * The in-memory structure corresponding to an XSLT Transformation. 1659 */ 1660 typedef enum { 1661 XSLT_OUTPUT_XML = 0, 1662 XSLT_OUTPUT_HTML, 1663 XSLT_OUTPUT_TEXT 1664 } xsltOutputType; 1665 1666 typedef enum { 1667 XSLT_STATE_OK = 0, 1668 XSLT_STATE_ERROR, 1669 XSLT_STATE_STOPPED 1670 } xsltTransformState; 1671 1672 struct _xsltTransformContext { 1673 xsltStylesheetPtr style; /* the stylesheet used */ 1674 xsltOutputType type; /* the type of output */ 1675 1676 xsltTemplatePtr templ; /* the current template */ 1677 int templNr; /* Nb of templates in the stack */ 1678 int templMax; /* Size of the templtes stack */ 1679 xsltTemplatePtr *templTab; /* the template stack */ 1680 1681 xsltStackElemPtr vars; /* the current variable list */ 1682 int varsNr; /* Nb of variable list in the stack */ 1683 int varsMax; /* Size of the variable list stack */ 1684 xsltStackElemPtr *varsTab; /* the variable list stack */ 1685 int varsBase; /* the var base for current templ */ 1686 1687 /* 1688 * Extensions 1689 */ 1690 xmlHashTablePtr extFunctions; /* the extension functions */ 1691 xmlHashTablePtr extElements; /* the extension elements */ 1692 xmlHashTablePtr extInfos; /* the extension data */ 1693 1694 const xmlChar *mode; /* the current mode */ 1695 const xmlChar *modeURI; /* the current mode URI */ 1696 1697 xsltDocumentPtr docList; /* the document list */ 1698 1699 xsltDocumentPtr document; /* the current source document; can be NULL if an RTF */ 1700 xmlNodePtr node; /* the current node being processed */ 1701 xmlNodeSetPtr nodeList; /* the current node list */ 1702 /* xmlNodePtr current; the node */ 1703 1704 xmlDocPtr output; /* the resulting document */ 1705 xmlNodePtr insert; /* the insertion node */ 1706 1707 xmlXPathContextPtr xpathCtxt; /* the XPath context */ 1708 xsltTransformState state; /* the current state */ 1709 1710 /* 1711 * Global variables 1712 */ 1713 xmlHashTablePtr globalVars; /* the global variables and params */ 1714 1715 xmlNodePtr inst; /* the instruction in the stylesheet */ 1716 1717 int xinclude; /* should XInclude be processed */ 1718 1719 const char * outputFile; /* the output URI if known */ 1720 1721 int profile; /* is this run profiled */ 1722 long prof; /* the current profiled value */ 1723 int profNr; /* Nb of templates in the stack */ 1724 int profMax; /* Size of the templtaes stack */ 1725 long *profTab; /* the profile template stack */ 1726 1727 void *_private; /* user defined data */ 1728 1729 int extrasNr; /* the number of extras used */ 1730 int extrasMax; /* the number of extras allocated */ 1731 xsltRuntimeExtraPtr extras; /* extra per runtime information */ 1732 1733 xsltDocumentPtr styleList; /* the stylesheet docs list */ 1734 void * sec; /* the security preferences if any */ 1735 1736 xmlGenericErrorFunc error; /* a specific error handler */ 1737 void * errctx; /* context for the error handler */ 1738 1739 xsltSortFunc sortfunc; /* a ctxt specific sort routine */ 1740 1741 /* 1742 * handling of temporary Result Value Tree 1743 * (XSLT 1.0 term: "Result Tree Fragment") 1744 */ 1745 xmlDocPtr tmpRVT; /* list of RVT without persistance */ 1746 xmlDocPtr persistRVT; /* list of persistant RVTs */ 1747 int ctxtflags; /* context processing flags */ 1748 1749 /* 1750 * Speed optimization when coalescing text nodes 1751 */ 1752 const xmlChar *lasttext; /* last text node content */ 1753 int lasttsize; /* last text node size */ 1754 int lasttuse; /* last text node use */ 1755 /* 1756 * Per Context Debugging 1757 */ 1758 int debugStatus; /* the context level debug status */ 1759 unsigned long* traceCode; /* pointer to the variable holding the mask */ 1760 1761 int parserOptions; /* parser options xmlParserOption */ 1762 1763 /* 1764 * dictionary: shared between stylesheet, context and documents. 1765 */ 1766 xmlDictPtr dict; 1767 xmlDocPtr tmpDoc; /* Obsolete; not used in the library. */ 1768 /* 1769 * all document text strings are internalized 1770 */ 1771 int internalized; 1772 int nbKeys; 1773 int hasTemplKeyPatterns; 1774 xsltTemplatePtr currentTemplateRule; /* the Current Template Rule */ 1775 xmlNodePtr initialContextNode; 1776 xmlDocPtr initialContextDoc; 1777 xsltTransformCachePtr cache; 1778 void *contextVariable; /* the current variable item */ 1779 xmlDocPtr localRVT; /* list of local tree fragments; will be freed when 1780 the instruction which created the fragment 1781 exits */ 1782 xmlDocPtr localRVTBase; /* Obsolete */ 1783 int keyInitLevel; /* Needed to catch recursive keys issues */ 1784 int depth; /* Needed to catch recursions */ 1785 int maxTemplateDepth; 1786 int maxTemplateVars; 1787 unsigned long opLimit; 1788 unsigned long opCount; 1789 }; 1790 1791 /** 1792 * CHECK_STOPPED: 1793 * 1794 * Macro to check if the XSLT processing should be stopped. 1795 * Will return from the function. 1796 */ 1797 #define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return; 1798 1799 /** 1800 * CHECK_STOPPEDE: 1801 * 1802 * Macro to check if the XSLT processing should be stopped. 1803 * Will goto the error: label. 1804 */ 1805 #define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error; 1806 1807 /** 1808 * CHECK_STOPPED0: 1809 * 1810 * Macro to check if the XSLT processing should be stopped. 1811 * Will return from the function with a 0 value. 1812 */ 1813 #define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0); 1814 1815 /* 1816 * The macro XML_CAST_FPTR is a hack to avoid a gcc warning about 1817 * possible incompatibilities between function pointers and object 1818 * pointers. It is defined in libxml/hash.h within recent versions 1819 * of libxml2, but is put here for compatibility. 1820 */ 1821 #ifndef XML_CAST_FPTR 1822 /** 1823 * XML_CAST_FPTR: 1824 * @fptr: pointer to a function 1825 * 1826 * Macro to do a casting from an object pointer to a 1827 * function pointer without encountering a warning from 1828 * gcc 1829 * 1830 * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr)) 1831 * This macro violated ISO C aliasing rules (gcc4 on s390 broke) 1832 * so it is disabled now 1833 */ 1834 1835 #define XML_CAST_FPTR(fptr) fptr 1836 #endif 1837 /* 1838 * Functions associated to the internal types 1839 xsltDecimalFormatPtr xsltDecimalFormatGetByName(xsltStylesheetPtr sheet, 1840 xmlChar *name); 1841 */ 1842 XSLTPUBFUN xsltStylesheetPtr XSLTCALL 1843 xsltNewStylesheet (void); 1844 XSLTPUBFUN xsltStylesheetPtr XSLTCALL 1845 xsltParseStylesheetFile (const xmlChar* filename); 1846 XSLTPUBFUN void XSLTCALL 1847 xsltFreeStylesheet (xsltStylesheetPtr style); 1848 XSLTPUBFUN int XSLTCALL 1849 xsltIsBlank (xmlChar *str); 1850 XSLTPUBFUN void XSLTCALL 1851 xsltFreeStackElemList (xsltStackElemPtr elem); 1852 XSLTPUBFUN xsltDecimalFormatPtr XSLTCALL 1853 xsltDecimalFormatGetByName(xsltStylesheetPtr style, 1854 xmlChar *name); 1855 XSLTPUBFUN xsltDecimalFormatPtr XSLTCALL 1856 xsltDecimalFormatGetByQName(xsltStylesheetPtr style, 1857 const xmlChar *nsUri, 1858 const xmlChar *name); 1859 1860 XSLTPUBFUN xsltStylesheetPtr XSLTCALL 1861 xsltParseStylesheetProcess(xsltStylesheetPtr ret, 1862 xmlDocPtr doc); 1863 XSLTPUBFUN void XSLTCALL 1864 xsltParseStylesheetOutput(xsltStylesheetPtr style, 1865 xmlNodePtr cur); 1866 XSLTPUBFUN xsltStylesheetPtr XSLTCALL 1867 xsltParseStylesheetDoc (xmlDocPtr doc); 1868 XSLTPUBFUN xsltStylesheetPtr XSLTCALL 1869 xsltParseStylesheetImportedDoc(xmlDocPtr doc, 1870 xsltStylesheetPtr style); 1871 XSLTPUBFUN int XSLTCALL 1872 xsltParseStylesheetUser(xsltStylesheetPtr style, 1873 xmlDocPtr doc); 1874 XSLTPUBFUN xsltStylesheetPtr XSLTCALL 1875 xsltLoadStylesheetPI (xmlDocPtr doc); 1876 XSLTPUBFUN void XSLTCALL 1877 xsltNumberFormat (xsltTransformContextPtr ctxt, 1878 xsltNumberDataPtr data, 1879 xmlNodePtr node); 1880 XSLTPUBFUN xmlXPathError XSLTCALL 1881 xsltFormatNumberConversion(xsltDecimalFormatPtr self, 1882 xmlChar *format, 1883 double number, 1884 xmlChar **result); 1885 1886 XSLTPUBFUN void XSLTCALL 1887 xsltParseTemplateContent(xsltStylesheetPtr style, 1888 xmlNodePtr templ); 1889 XSLTPUBFUN int XSLTCALL 1890 xsltAllocateExtra (xsltStylesheetPtr style); 1891 XSLTPUBFUN int XSLTCALL 1892 xsltAllocateExtraCtxt (xsltTransformContextPtr ctxt); 1893 /* 1894 * Extra functions for Result Value Trees 1895 */ 1896 XSLTPUBFUN xmlDocPtr XSLTCALL 1897 xsltCreateRVT (xsltTransformContextPtr ctxt); 1898 XSLTPUBFUN int XSLTCALL 1899 xsltRegisterTmpRVT (xsltTransformContextPtr ctxt, 1900 xmlDocPtr RVT); 1901 XSLTPUBFUN int XSLTCALL 1902 xsltRegisterLocalRVT (xsltTransformContextPtr ctxt, 1903 xmlDocPtr RVT); 1904 XSLTPUBFUN int XSLTCALL 1905 xsltRegisterPersistRVT (xsltTransformContextPtr ctxt, 1906 xmlDocPtr RVT); 1907 XSLTPUBFUN int XSLTCALL 1908 xsltExtensionInstructionResultRegister( 1909 xsltTransformContextPtr ctxt, 1910 xmlXPathObjectPtr obj); 1911 XSLTPUBFUN int XSLTCALL 1912 xsltExtensionInstructionResultFinalize( 1913 xsltTransformContextPtr ctxt); 1914 XSLTPUBFUN int XSLTCALL 1915 xsltFlagRVTs( 1916 xsltTransformContextPtr ctxt, 1917 xmlXPathObjectPtr obj, 1918 void *val); 1919 XSLTPUBFUN void XSLTCALL 1920 xsltFreeRVTs (xsltTransformContextPtr ctxt); 1921 XSLTPUBFUN void XSLTCALL 1922 xsltReleaseRVT (xsltTransformContextPtr ctxt, 1923 xmlDocPtr RVT); 1924 /* 1925 * Extra functions for Attribute Value Templates 1926 */ 1927 XSLTPUBFUN void XSLTCALL 1928 xsltCompileAttr (xsltStylesheetPtr style, 1929 xmlAttrPtr attr); 1930 XSLTPUBFUN xmlChar * XSLTCALL 1931 xsltEvalAVT (xsltTransformContextPtr ctxt, 1932 void *avt, 1933 xmlNodePtr node); 1934 XSLTPUBFUN void XSLTCALL 1935 xsltFreeAVTList (void *avt); 1936 1937 /* 1938 * Extra function for successful xsltCleanupGlobals / xsltInit sequence. 1939 */ 1940 1941 XSLTPUBFUN void XSLTCALL 1942 xsltUninit (void); 1943 1944 /************************************************************************ 1945 * * 1946 * Compile-time functions for *internal* use only * 1947 * * 1948 ************************************************************************/ 1949 1950 #ifdef XSLT_REFACTORED 1951 XSLTPUBFUN void XSLTCALL 1952 xsltParseSequenceConstructor( 1953 xsltCompilerCtxtPtr cctxt, 1954 xmlNodePtr start); 1955 XSLTPUBFUN int XSLTCALL 1956 xsltParseAnyXSLTElem (xsltCompilerCtxtPtr cctxt, 1957 xmlNodePtr elem); 1958 #ifdef XSLT_REFACTORED_XSLT_NSCOMP 1959 XSLTPUBFUN int XSLTCALL 1960 xsltRestoreDocumentNamespaces( 1961 xsltNsMapPtr ns, 1962 xmlDocPtr doc); 1963 #endif 1964 #endif /* XSLT_REFACTORED */ 1965 1966 /************************************************************************ 1967 * * 1968 * Transformation-time functions for *internal* use only * 1969 * * 1970 ************************************************************************/ 1971 XSLTPUBFUN int XSLTCALL 1972 xsltInitCtxtKey (xsltTransformContextPtr ctxt, 1973 xsltDocumentPtr doc, 1974 xsltKeyDefPtr keyd); 1975 XSLTPUBFUN int XSLTCALL 1976 xsltInitAllDocKeys (xsltTransformContextPtr ctxt); 1977 #ifdef __cplusplus 1978 } 1979 #endif 1980 1981 #endif /* __XML_XSLT_H__ */ 1982 1983