source: trunk/third/libxslt/libxslt/xsltInternals.h @ 18543

Revision 18543, 17.0 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18542, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * xsltInternals.h: internal data structures, constants and functions used
3 *                  by the XSLT engine.
4 *                  They are not part of the API or ABI, i.e. they can change
5 *                  without prior notice, use carefully.
6 *
7 * See Copyright for the status of this software.
8 *
9 * daniel@veillard.com
10 */
11
12#ifndef __XML_XSLT_INTERNALS_H__
13#define __XML_XSLT_INTERNALS_H__
14
15#include <libxml/tree.h>
16#include <libxml/hash.h>
17#include <libxml/xpath.h>
18#include <libxml/xmlerror.h>
19#include <libxslt/xslt.h>
20#include "numbersInternals.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/**
27 * XSLT_MAX_SORT:
28 *
29 * Max number of specified xsl:sort on an element.
30 */
31#define XSLT_MAX_SORT 15
32
33/**
34 * XSLT_PAT_NO_PRIORITY:
35 *
36 * Specific value for pattern without priority expressed.
37 */
38#define XSLT_PAT_NO_PRIORITY -12345789
39
40/**
41 * xsltRuntimeExtra:
42 *
43 * Extra information added to the transformation context.
44 */
45typedef struct _xsltRuntimeExtra xsltRuntimeExtra;
46typedef xsltRuntimeExtra *xsltRuntimeExtraPtr;
47struct _xsltRuntimeExtra {
48    void       *info;           /* pointer to the extra data */
49    xmlFreeFunc deallocate;     /* pointer to the deallocation routine */
50    void       *val;            /* data not needing deallocation */
51};
52
53/**
54 * XSLT_RUNTIME_EXTRA_LST:
55 * @ctxt: the transformation context
56 * @nr: the index
57 *
58 * Macro used to access extra information stored in the context
59 */
60#define XSLT_RUNTIME_EXTRA_LST(ctxt, nr) (ctxt)->extras[(nr)].info
61/**
62 * XSLT_RUNTIME_EXTRA_FREE:
63 * @ctxt: the transformation context
64 * @nr: the index
65 *
66 * Macro used to free extra information stored in the context
67 */
68#define XSLT_RUNTIME_EXTRA_FREE(ctxt, nr) (ctxt)->extras[(nr)].deallocate
69/**
70 * XSLT_RUNTIME_EXTRA:
71 * @ctxt: the transformation context
72 * @nr: the index
73 *
74 * Macro used to define extra information stored in the context
75 */
76#define XSLT_RUNTIME_EXTRA(ctxt, nr) (ctxt)->extras[(nr)].val
77
78/**
79 * xsltTemplate:
80 *
81 * The in-memory structure corresponding to an XSLT Template.
82 */
83typedef struct _xsltTemplate xsltTemplate;
84typedef xsltTemplate *xsltTemplatePtr;
85struct _xsltTemplate {
86    struct _xsltTemplate *next;/* chained list sorted by priority */
87    struct _xsltStylesheet *style;/* the containing stylesheet */
88    xmlChar *match;     /* the matching string */
89    float priority;     /* as given from the stylesheet, not computed */
90    xmlChar *name;      /* the local part of the name QName */
91    xmlChar *nameURI;   /* the URI part of the name QName */
92    xmlChar *mode;      /* the local part of the mode QName */
93    xmlChar *modeURI;   /* the URI part of the mode QName */
94    xmlNodePtr content; /* the template replacement value */
95    xmlNodePtr elem;    /* the source element */
96
97    int inheritedNsNr;  /* number of inherited namespaces */
98    xmlNsPtr *inheritedNs;/* inherited non-excluded namespaces */
99
100    /* Profiling informations */
101    int nbCalls;        /* the number of time the template was called */
102    unsigned long time; /* the time spent in this template */
103};
104
105/**
106 * xsltDecimalFormat:
107 *
108 * Data structure of decimal-format.
109 */
110typedef struct _xsltDecimalFormat xsltDecimalFormat;
111typedef xsltDecimalFormat *xsltDecimalFormatPtr;
112struct _xsltDecimalFormat {
113    struct _xsltDecimalFormat *next; /* chained list */
114    xmlChar *name;
115    /* Used for interpretation of pattern */
116    xmlChar *digit;
117    xmlChar *patternSeparator;
118    /* May appear in result */
119    xmlChar *minusSign;
120    xmlChar *infinity;
121    xmlChar *noNumber; /* Not-a-number */
122    /* Used for interpretation of pattern and may appear in result */
123    xmlChar *decimalPoint;
124    xmlChar *grouping;
125    xmlChar *percent;
126    xmlChar *permille;
127    xmlChar *zeroDigit;
128};
129
130/**
131 * xsltDocument:
132 *
133 * Data structure associated to a parsed document.
134 */
135
136typedef struct _xsltDocument xsltDocument;
137typedef xsltDocument *xsltDocumentPtr;
138struct _xsltDocument {
139    struct _xsltDocument *next; /* documents are kept in a chained list */
140    int main;                   /* is this the main document */
141    xmlDocPtr doc;              /* the parsed document */
142    void *keys;                 /* key tables storage */
143};
144
145typedef struct _xsltTransformContext xsltTransformContext;
146typedef xsltTransformContext *xsltTransformContextPtr;
147
148/**
149 * xsltElemPreComp:
150 *
151 * The in-memory structure corresponding to element precomputed data,
152 * designed to be extended by extension implementors.
153 */
154typedef struct _xsltElemPreComp xsltElemPreComp;
155typedef xsltElemPreComp *xsltElemPreCompPtr;
156
157/**
158 * xsltTransformFunction:
159 * @ctxt: the XSLT transformation context
160 * @node: the input node
161 * @inst: the stylesheet node
162 * @comp: the compiled information from the stylesheet
163 *
164 * Signature of the function associated to elements part of the
165 * stylesheet language like xsl:if or xsl:apply-templates.
166 */
167typedef void (*xsltTransformFunction) (xsltTransformContextPtr ctxt,
168                                       xmlNodePtr node,
169                                       xmlNodePtr inst,
170                                       xsltElemPreCompPtr comp);
171
172/**
173 * xsltSortFunc:
174 * @ctxt:    a transformation context
175 * @sorts:   the node-set to sort
176 * @nbsorts: the number of sorts
177 *
178 * Signature of the function to use during sorting
179 */
180typedef void (*xsltSortFunc) (xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
181                              int nbsorts);
182
183typedef enum {
184    XSLT_FUNC_COPY=1,
185    XSLT_FUNC_SORT,
186    XSLT_FUNC_TEXT,
187    XSLT_FUNC_ELEMENT,
188    XSLT_FUNC_ATTRIBUTE,
189    XSLT_FUNC_COMMENT,
190    XSLT_FUNC_PI,
191    XSLT_FUNC_COPYOF,
192    XSLT_FUNC_VALUEOF,
193    XSLT_FUNC_NUMBER,
194    XSLT_FUNC_APPLYIMPORTS,
195    XSLT_FUNC_CALLTEMPLATE,
196    XSLT_FUNC_APPLYTEMPLATES,
197    XSLT_FUNC_CHOOSE,
198    XSLT_FUNC_IF,
199    XSLT_FUNC_FOREACH,
200    XSLT_FUNC_DOCUMENT,
201    XSLT_FUNC_WITHPARAM,
202    XSLT_FUNC_PARAM,
203    XSLT_FUNC_VARIABLE,
204    XSLT_FUNC_WHEN,
205    XSLT_FUNC_EXTENSION
206} xsltStyleType;
207
208/**
209 * xsltElemPreCompDeallocator:
210 * @comp:  the #xsltElemPreComp to free up
211 *
212 * Deallocates an #xsltElemPreComp structure.
213 */
214typedef void (*xsltElemPreCompDeallocator) (xsltElemPreCompPtr comp);
215
216/**
217 * xsltElemPreComp:
218 *
219 * The in-memory structure corresponding to element precomputed data,
220 * designed to be extended by extension implementors.
221 */
222struct _xsltElemPreComp {
223    xsltElemPreCompPtr next;            /* chained list */
224    xsltStyleType type;                 /* type of the element */
225    xsltTransformFunction func;         /* handling function */
226    xmlNodePtr inst;                    /* the instruction */
227
228    /* end of common part */
229    xsltElemPreCompDeallocator free;    /* the deallocator */
230};
231
232/**
233 * xsltStylePreComp:
234 *
235 * The in-memory structure corresponding to XSLT stylesheet constructs
236 * precomputed data.
237 */
238typedef struct _xsltStylePreComp xsltStylePreComp;
239
240typedef xsltStylePreComp *xsltStylePreCompPtr;
241
242struct _xsltStylePreComp {
243    xsltElemPreCompPtr next;    /* chained list */
244    xsltStyleType type;         /* type of the element */
245    xsltTransformFunction func; /* handling function */
246    xmlNodePtr inst;            /* the instruction */
247
248    /*
249     * Pre computed values.
250     */
251
252    xmlChar *stype;             /* sort */
253    int      has_stype;         /* sort */
254    int      number;            /* sort */
255    xmlChar *order;             /* sort */
256    int      has_order;         /* sort */
257    int      descending;        /* sort */
258    xmlChar *lang;              /* sort */
259    int      has_lang;          /* sort */
260    xmlChar *case_order;        /* sort */
261    int      lower_first;       /* sort */
262
263    xmlChar *use;               /* copy, element */
264    int      has_use;           /* copy, element */
265
266    int      noescape;          /* text */
267
268    xmlChar *name;              /* element, attribute, pi */
269    int      has_name;          /* element, attribute, pi */
270    xmlChar *ns;                /* element */
271    int      has_ns;            /* element */
272
273    xmlChar *mode;              /* apply-templates */
274    xmlChar *modeURI;           /* apply-templates */
275
276    xmlChar *test;              /* if */
277
278    xsltTemplatePtr templ;      /* call-template */
279
280    xmlChar *select;            /* sort, copy-of, value-of, apply-templates */
281
282    int      ver11;             /* document */
283    xmlChar *filename;          /* document URL */
284    int      has_filename;      /* document */
285
286    xsltNumberData numdata;     /* number */
287
288    xmlXPathCompExprPtr comp;   /* a precompiled XPath expression */
289    xmlNsPtr *nsList;           /* the namespaces in scope */
290    int nsNr;                   /* the number of namespaces in scope */
291};
292
293/*
294 * The in-memory structure corresponding to an XSLT Variable
295 * or Param.
296 */
297
298typedef struct _xsltStackElem xsltStackElem;
299typedef xsltStackElem *xsltStackElemPtr;
300struct _xsltStackElem {
301    struct _xsltStackElem *next;/* chained list */
302    xsltStylePreCompPtr comp;   /* the compiled form */
303    int computed;       /* was the evaluation done */
304    xmlChar *name;      /* the local part of the name QName */
305    xmlChar *nameURI;   /* the URI part of the name QName */
306    xmlChar *select;    /* the eval string */
307    xmlNodePtr tree;    /* the tree if no eval string or the location */
308    xmlXPathObjectPtr value; /* The value if computed */
309};
310
311/*
312 * The in-memory structure corresponding to an XSLT Stylesheet.
313 * NOTE: most of the content is simply linked from the doc tree
314 *       structure, no specific allocation is made.
315 */
316typedef struct _xsltStylesheet xsltStylesheet;
317typedef xsltStylesheet *xsltStylesheetPtr;
318struct _xsltStylesheet {
319    /*
320     * The stylesheet import relation is kept as a tree.
321     */
322    struct _xsltStylesheet *parent;
323    struct _xsltStylesheet *next;
324    struct _xsltStylesheet *imports;
325
326    xsltDocumentPtr docList;            /* the include document list */
327
328    /*
329     * General data on the style sheet document.
330     */
331    xmlDocPtr doc;              /* the parsed XML stylesheet */
332    xmlHashTablePtr stripSpaces;/* the hash table of the strip-space and
333                                   preserve space elements */
334    int             stripAll;   /* strip-space * (1) preserve-space * (-1) */
335    xmlHashTablePtr cdataSection;/* the hash table of the cdata-section */
336
337    /*
338     * Global variable or parameters.
339     */
340    xsltStackElemPtr variables; /* linked list of param and variables */
341
342    /*
343     * Template descriptions.
344     */
345    xsltTemplatePtr templates;  /* the ordered list of templates */
346    void *templatesHash;        /* hash table or wherever compiled templates
347                                   informations are stored */
348    void *rootMatch;            /* template based on / */
349    void *keyMatch;             /* template based on key() */
350    void *elemMatch;            /* template based on * */
351    void *attrMatch;            /* template based on @* */
352    void *parentMatch;          /* template based on .. */
353    void *textMatch;            /* template based on text() */
354    void *piMatch;              /* template based on processing-instruction() */
355    void *commentMatch;         /* template based on comment() */
356   
357    /*
358     * Namespace aliases.
359     */
360    xmlHashTablePtr nsAliases;  /* the namespace alias hash tables */
361
362    /*
363     * Attribute sets.
364     */
365    xmlHashTablePtr attributeSets;/* the attribute sets hash tables */
366
367    /*
368     * Namespaces.
369     */
370    xmlHashTablePtr nsHash;     /* the set of namespaces in use */
371    void           *nsDefs;     /* the namespaces defined */
372
373    /*
374     * Key definitions.
375     */
376    void *keys;                         /* key definitions */
377
378    /*
379     * Output related stuff.
380     */
381    xmlChar *method;            /* the output method */
382    xmlChar *methodURI;         /* associated namespace if any */
383    xmlChar *version;           /* version string */
384    xmlChar *encoding;          /* encoding string */
385    int omitXmlDeclaration;     /* omit-xml-declaration = "yes" | "no" */
386
387    /*
388     * Number formatting.
389     */
390    xsltDecimalFormatPtr decimalFormat;
391    int standalone;             /* standalone = "yes" | "no" */
392    xmlChar *doctypePublic;     /* doctype-public string */
393    xmlChar *doctypeSystem;     /* doctype-system string */
394    int indent;                 /* should output being indented */
395    xmlChar *mediaType;         /* media-type string */
396
397    /*
398     * Precomputed blocks.
399     */
400    xsltElemPreCompPtr preComps;/* list of precomputed blocks */
401    int warnings;               /* number of warnings found at compilation */
402    int errors;                 /* number of errors found at compilation */
403
404    xmlChar  *exclPrefix;       /* last excluded prefixes */
405    xmlChar **exclPrefixTab;    /* array of excluded prefixes */
406    int       exclPrefixNr;     /* number of excluded prefixes in scope */
407    int       exclPrefixMax;    /* size of the array */
408
409    void     *_private;         /* user defined data */
410
411    /*
412     * Extensions.
413     */
414    xmlHashTablePtr extInfos;   /* the extension data */
415    int             extrasNr;   /* the number of extras required */
416};
417
418/*
419 * The in-memory structure corresponding to an XSLT Transformation.
420 */
421typedef enum {
422    XSLT_OUTPUT_XML = 0,
423    XSLT_OUTPUT_HTML,
424    XSLT_OUTPUT_TEXT
425} xsltOutputType;
426
427typedef enum {
428    XSLT_STATE_OK = 0,
429    XSLT_STATE_ERROR,
430    XSLT_STATE_STOPPED
431} xsltTransformState;
432
433struct _xsltTransformContext {
434    xsltStylesheetPtr style;            /* the stylesheet used */
435    xsltOutputType type;                /* the type of output */
436
437    xsltTemplatePtr  templ;             /* the current template */
438    int              templNr;           /* Nb of templates in the stack */
439    int              templMax;          /* Size of the templtes stack */
440    xsltTemplatePtr *templTab;          /* the template stack */
441
442    xsltStackElemPtr  vars;             /* the current variable list */
443    int               varsNr;           /* Nb of variable list in the stack */
444    int               varsMax;          /* Size of the variable list stack */
445    xsltStackElemPtr *varsTab;          /* the variable list stack */
446    int               varsBase;         /* the var base for current templ */
447
448    /*
449     * Extensions
450     */
451    xmlHashTablePtr   extFunctions;     /* the extension functions */
452    xmlHashTablePtr   extElements;      /* the extension elements */
453    xmlHashTablePtr   extInfos;         /* the extension data */
454
455    const xmlChar *mode;                /* the current mode */
456    const xmlChar *modeURI;             /* the current mode URI */
457
458    xsltDocumentPtr docList;            /* the document list */
459
460    xsltDocumentPtr document;           /* the current document */
461    xmlNodePtr node;                    /* the current node being processed */
462    xmlNodeSetPtr nodeList;             /* the current node list */
463    /* xmlNodePtr current;                      the node */
464
465    xmlDocPtr output;                   /* the resulting document */
466    xmlNodePtr insert;                  /* the insertion node */
467
468    xmlXPathContextPtr xpathCtxt;       /* the XPath context */
469    xsltTransformState state;           /* the current state */
470
471    /*
472     * Global variables
473     */
474    xmlHashTablePtr   globalVars;       /* the global variables and params */
475
476    xmlNodePtr inst;                    /* the instruction in the stylesheet */
477
478    int xinclude;                       /* should XInclude be processed */
479
480    const char *      outputFile;       /* the output URI if known */
481
482    int profile;                        /* is this run profiled */
483    long             prof;              /* the current profiled value */
484    int              profNr;            /* Nb of templates in the stack */
485    int              profMax;           /* Size of the templtaes stack */
486    long            *profTab;           /* the profile template stack */
487
488    void            *_private;          /* user defined data */
489
490    int              extrasNr;          /* the number of extras used */
491    int              extrasMax;         /* the number of extras allocated */
492    xsltRuntimeExtraPtr extras;         /* extra per runtime informations */
493
494    xsltDocumentPtr  styleList;         /* the stylesheet docs list */
495    void                 * sec;         /* the security preferences if any */
496
497    xmlGenericErrorFunc  error;         /* a specific error handler */
498    void              * errctx;         /* context for the error handler */
499
500    xsltSortFunc      sortfunc;         /* a ctxt specific sort routine */
501};
502
503/**
504 * CHECK_STOPPED:
505 *
506 * Macro to check if the XSLT processing should be stopped.
507 * Will return from the function.
508 */
509#define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return;
510
511/**
512 * CHECK_STOPPEDE:
513 *
514 * Macro to check if the XSLT processing should be stopped.
515 * Will goto the error: label.
516 */
517#define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error;
518
519/**
520 * CHECK_STOPPED0:
521 *
522 * Macro to check if the XSLT processing should be stopped.
523 * Will return from the function with a 0 value.
524 */
525#define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0);
526
527/*
528 * Functions associated to the internal types
529xsltDecimalFormatPtr    xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
530                                                   xmlChar *name);
531 */
532xsltStylesheetPtr       xsltNewStylesheet       (void);
533xsltStylesheetPtr       xsltParseStylesheetFile (const xmlChar* filename);
534void                    xsltFreeStylesheet      (xsltStylesheetPtr sheet);
535int                     xsltIsBlank             (xmlChar *str);
536void                    xsltFreeStackElemList   (xsltStackElemPtr elem);
537xsltDecimalFormatPtr    xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
538                                                   xmlChar *name);
539
540xsltStylesheetPtr       xsltParseStylesheetProcess(xsltStylesheetPtr ret,
541                                                 xmlDocPtr doc);
542void                    xsltParseStylesheetOutput(xsltStylesheetPtr style,
543                                                  xmlNodePtr cur);
544xsltStylesheetPtr       xsltParseStylesheetDoc  (xmlDocPtr doc);
545xsltStylesheetPtr       xsltParseStylesheetImportedDoc(xmlDocPtr doc);
546xsltStylesheetPtr       xsltLoadStylesheetPI    (xmlDocPtr doc);
547void                    xsltNumberFormat        (xsltTransformContextPtr ctxt,
548                                                 xsltNumberDataPtr data,
549                                                 xmlNodePtr node);
550xmlXPathError            xsltFormatNumberConversion(xsltDecimalFormatPtr self,
551                                                 xmlChar *format,
552                                                 double number,
553                                                 xmlChar **result);
554
555void                    xsltParseTemplateContent(xsltStylesheetPtr style,
556                                                 xmlNodePtr templ);
557int                     xsltAllocateExtra       (xsltStylesheetPtr style);
558int                     xsltAllocateExtraCtxt   (xsltTransformContextPtr ctxt);
559#ifdef __cplusplus
560}
561#endif
562
563#endif /* __XML_XSLT_H__ */
564
Note: See TracBrowser for help on using the repository browser.