This should speed up and correct a few problems:
[platform/upstream/libxslt.git] / libxslt / xsltInternals.h
1 /*
2  * xsltInternals.h: internal data structures, constants and functions used
3  *                  by the XSLT engine
4  *
5  * See Copyright for the status of this software.
6  *
7  * Daniel.Veillard@imag.fr
8  */
9
10 #ifndef __XML_XSLT_INTERNALS_H__
11 #define __XML_XSLT_INTERNALS_H__
12
13 #include <libxml/tree.h>
14 #include <libxml/hash.h>
15 #include <libxml/xpath.h>
16 #include <libxslt/xslt.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /*
23  * The in-memory structure corresponding to an XSLT Variable
24  * or Param
25  */
26
27 typedef enum {
28     XSLT_ELEM_VARIABLE=1,
29     XSLT_ELEM_PARAM
30 } xsltElem;
31
32 typedef struct _xsltStackElem xsltStackElem;
33 typedef xsltStackElem *xsltStackElemPtr;
34 struct _xsltStackElem {
35     struct _xsltStackElem *next;/* chained list */
36     xsltElem type;      /* type of the element */
37     int computed;       /* was the evaluation done */
38     xmlChar *name;      /* the local part of the name QName */
39     xmlChar *nameURI;   /* the URI part of the name QName */
40     xmlChar *select;    /* the eval string */
41     xmlNodePtr tree;    /* the tree if no eval string */
42     xmlXPathObjectPtr value; /* The value if computed */
43 };
44
45 /*
46  * The in-memory structure corresponding to an XSLT Template
47  */
48 #define XSLT_PAT_NO_PRIORITY -12345789
49
50 typedef struct _xsltTemplate xsltTemplate;
51 typedef xsltTemplate *xsltTemplatePtr;
52 struct _xsltTemplate {
53     struct _xsltTemplate *next;/* chained list sorted by priority */
54     struct _xsltStylesheet *style;/* the containing stylesheet */
55     xmlChar *match;     /* the matching string */
56     float priority;     /* as given from the stylesheet, not computed */
57     xmlChar *name;      /* the local part of the name QName */
58     xmlChar *nameURI;   /* the URI part of the name QName */
59     xmlChar *mode;      /* the local part of the mode QName */
60     xmlChar *modeURI;   /* the URI part of the mode QName */
61     xmlNodePtr content; /* the template replacement value */
62     xmlNodePtr elem;    /* the source element */
63 };
64
65 /*
66  * Data structure of decimal-format
67  */
68 typedef struct _xsltDecimalFormat {
69     struct _xsltDecimalFormat *next; /* chained list */
70     xmlChar *name;
71     /* Used for interpretation of pattern */
72     xmlChar *digit;
73     xmlChar *patternSeparator;
74     /* May appear in result */
75     xmlChar *minusSign;
76     xmlChar *infinity;
77     xmlChar *noNumber; /* Not-a-number */
78     /* Used for interpretation of pattern and may appear in result */
79     xmlChar *decimalPoint;
80     xmlChar *grouping;
81     xmlChar *percent;
82     xmlChar *permille;
83     xmlChar *zeroDigit;
84 } xsltDecimalFormat, *xsltDecimalFormatPtr;
85
86 /*
87  * Data structure associated to a document
88  */
89
90 typedef struct _xsltDocument xsltDocument;
91 typedef xsltDocument *xsltDocumentPtr;
92 struct _xsltDocument {
93     struct _xsltDocument *next; /* documents are kept in a chained list */
94     int main;                   /* is this the main document */
95     xmlDocPtr doc;              /* the parsed document */
96     void *keys;                 /* key tables storage */
97 };
98
99 /*
100  * The in-memory structure corresponding to an XSLT Stylesheet
101  * NOTE: most of the content is simply linked from the doc tree
102  *       structure, no specific allocation is made.
103  */
104 typedef struct _xsltStylesheet xsltStylesheet;
105 typedef xsltStylesheet *xsltStylesheetPtr;
106 struct _xsltStylesheet {
107     /*
108      * The stylesheet import relation is kept as a tree
109      */
110     struct _xsltStylesheet *parent;
111     struct _xsltStylesheet *next;
112     struct _xsltStylesheet *imports;
113
114     xsltDocumentPtr docList;            /* the include document list */
115
116     /*
117      * General data on the style sheet document
118      */
119     xmlDocPtr doc;              /* the parsed XML stylesheet */
120     xmlHashTablePtr stripSpaces;/* the hash table of the strip-space
121                                    preserve space and cdata-section elements */
122
123     /*
124      * Global variable or parameters
125      */
126     xsltStackElemPtr variables; /* linked list of param and variables */
127
128     /*
129      * Template descriptions
130      */
131     xsltTemplatePtr templates;  /* the ordered list of templates */
132     void *templatesHash;        /* hash table or wherever compiled templates
133                                    informations are stored */
134     void *rootMatch;            /* template based on / */
135     void *keyMatch;             /* template based on key() */
136     void *elemMatch;            /* template based on * */
137     void *attrMatch;            /* template based on @* */
138     void *parentMatch;          /* template based on .. */
139     void *textMatch;            /* template based on text() */
140     void *piMatch;              /* template based on processing-instruction() */
141     void *commentMatch;         /* template based on comment() */
142     
143     /*
144      * Namespace aliases
145      */
146     xmlHashTablePtr nsAliases;  /* the namespace alias hash tables */
147
148     /*
149      * Attribute sets
150      */
151     xmlHashTablePtr attributeSets;/* the attribute sets hash tables */
152
153     /*
154      * Attribute sets
155      */
156     xmlHashTablePtr nsHash;     /* the set of namespaces in use */
157
158     /*
159      * Key definitions
160      */
161     void *keys;                         /* key definitions */
162
163     /*
164      * Output related stuff.
165      */
166     xmlChar *method;            /* the output method */
167     xmlChar *methodURI;         /* associated namespace if any */
168     xmlChar *version;           /* version string */
169     xmlChar *encoding;          /* encoding string */
170     int omitXmlDeclaration;     /* omit-xml-declaration = "yes" | "no" */
171
172     /* Number formatting */
173     xsltDecimalFormatPtr decimalFormat;
174     int standalone;             /* standalone = "yes" | "no" */
175     xmlChar *doctypePublic;     /* doctype-public string */
176     xmlChar *doctypeSystem;     /* doctype-system string */
177     int indent;                 /* should output being indented */
178     xmlChar *mediaType;         /* media-type string */
179 };
180
181
182 /*
183  * The in-memory structure corresponding to an XSLT Transformation
184  */
185 typedef enum {
186     XSLT_OUTPUT_XML = 0,
187     XSLT_OUTPUT_HTML,
188     XSLT_OUTPUT_TEXT
189 } xsltOutputType;
190
191 typedef enum {
192     XSLT_STATE_OK = 0,
193     XSLT_STATE_ERROR,
194     XSLT_STATE_STOPPED
195 } xsltTransformState;
196
197 typedef struct _xsltTransformContext xsltTransformContext;
198 typedef xsltTransformContext *xsltTransformContextPtr;
199 struct _xsltTransformContext {
200     xsltStylesheetPtr style;            /* the stylesheet used */
201     xsltOutputType type;                /* the type of output */
202
203     xsltTemplatePtr  templ;             /* the current template */
204     int              templNr;           /* Nb of templates in the stack */
205     int              templMax;          /* Size of the templtes stack */
206     xsltTemplatePtr *templTab;          /* the template stack */
207
208     xsltStackElemPtr  vars;             /* the current variable list */
209     int               varsNr;           /* Nb of variable list in the stack */
210     int               varsMax;          /* Size of the variable list stack */
211     xsltStackElemPtr *varsTab;          /* the variable list stack */
212     int               varsComputed;     /* switched during param template
213                                            evaluation */
214
215     /*
216      * Extensions
217      */
218     xmlHashTablePtr   extFunctions;     /* the extension functions */
219     xmlHashTablePtr   extElements;      /* the extension elements */
220
221     const xmlChar *mode;                /* the current mode */
222     const xmlChar *modeURI;             /* the current mode URI */
223
224     xsltDocumentPtr docList;            /* the document list */
225
226     xsltDocumentPtr document;           /* the current document */
227     xmlNodePtr node;                    /* the node being processed */
228     xmlNodeSetPtr nodeList;             /* the current node list */
229     xmlNodePtr current;                 /* the current node */
230
231     xmlDocPtr output;                   /* the resulting document */
232     xmlNodePtr insert;                  /* the insertion node */
233
234     xmlXPathContextPtr xpathCtxt;       /* the XPath context */
235     xsltTransformState state;           /* the current state */
236 };
237
238 typedef void (*xsltTransformFunction) (xsltTransformContextPtr ctxt,
239                                        xmlNodePtr node, xmlNodePtr inst);
240
241 #define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return;
242 #define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error;
243 #define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0);
244
245 /*
246  * Functions associated to the internal types
247 xsltDecimalFormatPtr    xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
248                                                    xmlChar *name);
249  */
250 xsltStylesheetPtr       xsltParseStylesheetFile (const xmlChar* filename);
251 void                    xsltFreeStylesheet      (xsltStylesheetPtr sheet);
252 int                     xsltIsBlank             (xmlChar *str);
253 void                    xsltFreeStackElemList   (xsltStackElemPtr elem);
254 xsltDecimalFormatPtr    xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
255                                                    xmlChar *name);
256
257 xsltStylesheetPtr       xsltParseStylesheetProcess(xsltStylesheetPtr ret,
258                                                  xmlDocPtr doc);
259 xsltStylesheetPtr       xsltParseStylesheetDoc  (xmlDocPtr doc);
260 #ifdef __cplusplus
261 }
262 #endif
263
264 #endif /* __XML_XSLT_H__ */
265