c185ea33b2febc3da6717db48327ba292130d328
[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 /*
24  * The in-memory structure corresponding to an XSLT Variable
25  * or Param
26  */
27
28 typedef enum {
29     XSLT_ELEM_VARIABLE=1,
30     XSLT_ELEM_PARAM
31 } xsltElem;
32
33 typedef struct _xsltStackElem xsltStackElem;
34 typedef xsltStackElem *xsltStackElemPtr;
35 struct _xsltStackElem {
36     struct _xsltStackElem *next;/* chained list */
37     xsltElem type;      /* type of the element */
38     int computed;       /* was the evaluation done */
39     xmlChar *name;      /* the local part of the name QName */
40     xmlChar *nameURI;   /* the URI part of the name QName */
41     xmlChar *select;    /* the eval string */
42     xmlNodePtr tree;    /* the tree if no eval string */
43     xmlXPathObjectPtr value; /* The value if computed */
44 };
45
46 /*
47  * The in-memory structure corresponding to an XSLT Template
48  */
49 #define XSLT_PAT_NO_PRIORITY -12345789
50
51 typedef struct _xsltTemplate xsltTemplate;
52 typedef xsltTemplate *xsltTemplatePtr;
53 struct _xsltTemplate {
54     struct _xsltTemplate *next;/* chained list sorted by priority */
55     xmlChar *match;     /* the matching string */
56     int 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 };
63
64 /*
65  * Data structure of decimal-format
66  */
67 typedef struct _xsltDecimalFormat {
68     struct _xsltDecimalFormat *next; /* chained list */
69     xmlChar *name;
70     /* Used for interpretation of pattern */
71     xmlChar *digit;
72     xmlChar *patternSeparator;
73     /* May appear in result */
74     xmlChar *minusSign;
75     xmlChar *infinity;
76     xmlChar *noNumber; /* Not-a-number */
77     /* Used for interpretation of pattern and may appear in result */
78     xmlChar *decimalPoint;
79     xmlChar *grouping;
80     xmlChar *percent;
81     xmlChar *permille;
82     xmlChar *zeroDigit;
83 } xsltDecimalFormat, *xsltDecimalFormatPtr;
84
85 /*
86  * The in-memory structure corresponding to an XSLT Stylesheet
87  * NOTE: most of the content is simply linked from the doc tree
88  *       structure, no specific allocation is made.
89  */
90 typedef struct _xsltStylesheet xsltStylesheet;
91 typedef xsltStylesheet *xsltStylesheetPtr;
92 struct _xsltStylesheet {
93     /*
94      * The stylesheet import relation is kept as a tree
95      */
96     struct _xsltStylesheet *parent;
97     struct _xsltStylesheet *next;
98     struct _xsltStylesheet *imports;
99
100     /*
101      * General data on the style sheet document
102      */
103     xmlDocPtr doc;              /* the parsed XML stylesheet */
104     xmlHashTablePtr stripSpaces;/* the hash table of the strip-space
105                                    preserve space and cdata-section elements */
106
107     /*
108      * Global variable or parameters
109      */
110     xsltStackElemPtr variables; /* linked list of param and variables */
111
112     /*
113      * Template descriptions
114      */
115     xsltTemplatePtr templates;  /* the ordered list of templates */
116     void *templatesHash;        /* hash table or wherever compiled templates
117                                    informations are stored */
118     void *rootMatch;            /* template based on / */
119     void *elemMatch;            /* template based on * */
120     void *attrMatch;            /* template based on @* */
121     void *parentMatch;          /* template based on .. */
122     void *textMatch;            /* template based on text() */
123     void *piMatch;              /* template based on processing-instruction() */
124     void *commentMatch;         /* template based on comment() */
125     
126     /*
127      * Namespace aliases
128      */
129     xmlHashTablePtr nsAliases;  /* the namespace alias hash tables */
130
131     /*
132      * Attribute sets
133      */
134     xmlHashTablePtr attributeSets;/* the attribute sets hash tables */
135
136     /*
137      * Output related stuff.
138      */
139     xmlChar *method;            /* the output method */
140     xmlChar *methodURI;         /* associated namespace if any */
141     xmlChar *version;           /* version string */
142     xmlChar *encoding;          /* encoding string */
143     int omitXmlDeclaration;     /* omit-xml-declaration = "yes" | "no" */
144
145     /* Number formatting */
146     xsltDecimalFormatPtr decimalFormat;
147     int standalone;             /* standalone = "yes" | "no" */
148     xmlChar *doctypePublic;     /* doctype-public string */
149     xmlChar *doctypeSystem;     /* doctype-system string */
150     int indent;                 /* should output being indented */
151     xmlChar *mediaType;         /* media-type string */
152 };
153
154
155 /*
156  * The in-memory structure corresponding to an XSLT Transformation
157  */
158 typedef enum {
159     XSLT_OUTPUT_XML = 0,
160     XSLT_OUTPUT_HTML,
161     XSLT_OUTPUT_TEXT
162 } xsltOutputType;
163
164 typedef enum {
165     XSLT_STATE_OK = 0,
166     XSLT_STATE_ERROR,
167     XSLT_STATE_STOPPED
168 } xsltTransformState;
169
170 typedef struct _xsltTransformContext xsltTransformContext;
171 typedef xsltTransformContext *xsltTransformContextPtr;
172 struct _xsltTransformContext {
173     xsltStylesheetPtr style;            /* the stylesheet used */
174     xsltOutputType type;                /* the type of output */
175
176     xmlDocPtr doc;                      /* the current doc */
177     xmlNodePtr node;                    /* the current node */
178     xmlNodeSetPtr nodeList;             /* the current node list */
179
180     xmlDocPtr output;                   /* the resulting document */
181     xmlNodePtr insert;                  /* the insertion node */
182
183     xmlXPathContextPtr xpathCtxt;       /* the XPath context */
184     void *variablesHash;                /* hash table or wherever variables
185                                            informations are stored */
186     xmlDocPtr extraDocs;                /* extra docs parsed by document() */
187     xsltTransformState state;           /* the current state */
188 };
189
190 #define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return;
191 #define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error;
192 #define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0);
193
194 /*
195  * Functions associated to the internal types
196 xsltDecimalFormatPtr    xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
197                                                    xmlChar *name);
198  */
199 xsltStylesheetPtr       xsltParseStylesheetFile (const xmlChar* filename);
200 void                    xsltFreeStylesheet      (xsltStylesheetPtr sheet);
201 int                     xsltIsBlank             (xmlChar *str);
202 void                    xsltFreeStackElemList   (xsltStackElemPtr elem);
203
204 xsltStylesheetPtr       xsltParseStylesheetProcess(xsltStylesheetPtr ret,
205                                                  xmlDocPtr doc);
206 xsltStylesheetPtr       xsltParseStylesheetDoc  (xmlDocPtr doc);
207 #ifdef __cplusplus
208 }
209 #endif
210
211 #endif /* __XML_XSLT_H__ */
212