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