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