2 * xsltInternals.h: internal data structures, constants and functions used
4 * They are not part of the API or ABI, i.e. they can change
5 * without prior notice, use carefully.
7 * See Copyright for the status of this software.
12 #ifndef __XML_XSLT_INTERNALS_H__
13 #define __XML_XSLT_INTERNALS_H__
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 "xsltexports.h"
21 #include "numbersInternals.h"
30 * Max number of specified xsl:sort on an element.
32 #define XSLT_MAX_SORT 15
35 * XSLT_PAT_NO_PRIORITY:
37 * Specific value for pattern without priority expressed.
39 #define XSLT_PAT_NO_PRIORITY -12345789
44 * Extra information added to the transformation context.
46 typedef struct _xsltRuntimeExtra xsltRuntimeExtra;
47 typedef xsltRuntimeExtra *xsltRuntimeExtraPtr;
48 struct _xsltRuntimeExtra {
49 void *info; /* pointer to the extra data */
50 xmlFreeFunc deallocate; /* pointer to the deallocation routine */
51 void *val; /* data not needing deallocation */
55 * XSLT_RUNTIME_EXTRA_LST:
56 * @ctxt: the transformation context
59 * Macro used to access extra information stored in the context
61 #define XSLT_RUNTIME_EXTRA_LST(ctxt, nr) (ctxt)->extras[(nr)].info
63 * XSLT_RUNTIME_EXTRA_FREE:
64 * @ctxt: the transformation context
67 * Macro used to free extra information stored in the context
69 #define XSLT_RUNTIME_EXTRA_FREE(ctxt, nr) (ctxt)->extras[(nr)].deallocate
72 * @ctxt: the transformation context
75 * Macro used to define extra information stored in the context
77 #define XSLT_RUNTIME_EXTRA(ctxt, nr) (ctxt)->extras[(nr)].val
82 * The in-memory structure corresponding to an XSLT Template.
84 typedef struct _xsltTemplate xsltTemplate;
85 typedef xsltTemplate *xsltTemplatePtr;
86 struct _xsltTemplate {
87 struct _xsltTemplate *next;/* chained list sorted by priority */
88 struct _xsltStylesheet *style;/* the containing stylesheet */
89 xmlChar *match; /* the matching string */
90 float priority; /* as given from the stylesheet, not computed */
91 xmlChar *name; /* the local part of the name QName */
92 xmlChar *nameURI; /* the URI part of the name QName */
93 xmlChar *mode; /* the local part of the mode QName */
94 xmlChar *modeURI; /* the URI part of the mode QName */
95 xmlNodePtr content; /* the template replacement value */
96 xmlNodePtr elem; /* the source element */
98 int inheritedNsNr; /* number of inherited namespaces */
99 xmlNsPtr *inheritedNs;/* inherited non-excluded namespaces */
101 /* Profiling informations */
102 int nbCalls; /* the number of time the template was called */
103 unsigned long time; /* the time spent in this template */
109 * Data structure of decimal-format.
111 typedef struct _xsltDecimalFormat xsltDecimalFormat;
112 typedef xsltDecimalFormat *xsltDecimalFormatPtr;
113 struct _xsltDecimalFormat {
114 struct _xsltDecimalFormat *next; /* chained list */
116 /* Used for interpretation of pattern */
118 xmlChar *patternSeparator;
119 /* May appear in result */
122 xmlChar *noNumber; /* Not-a-number */
123 /* Used for interpretation of pattern and may appear in result */
124 xmlChar *decimalPoint;
134 * Data structure associated to a parsed document.
137 typedef struct _xsltDocument xsltDocument;
138 typedef xsltDocument *xsltDocumentPtr;
139 struct _xsltDocument {
140 struct _xsltDocument *next; /* documents are kept in a chained list */
141 int main; /* is this the main document */
142 xmlDocPtr doc; /* the parsed document */
143 void *keys; /* key tables storage */
144 struct _xsltDocument *includes; /* subsidiary includes */
147 typedef struct _xsltTransformContext xsltTransformContext;
148 typedef xsltTransformContext *xsltTransformContextPtr;
153 * The in-memory structure corresponding to element precomputed data,
154 * designed to be extended by extension implementors.
156 typedef struct _xsltElemPreComp xsltElemPreComp;
157 typedef xsltElemPreComp *xsltElemPreCompPtr;
160 * xsltTransformFunction:
161 * @ctxt: the XSLT transformation context
162 * @node: the input node
163 * @inst: the stylesheet node
164 * @comp: the compiled information from the stylesheet
166 * Signature of the function associated to elements part of the
167 * stylesheet language like xsl:if or xsl:apply-templates.
169 typedef void (*xsltTransformFunction) (xsltTransformContextPtr ctxt,
172 xsltElemPreCompPtr comp);
176 * @ctxt: a transformation context
177 * @sorts: the node-set to sort
178 * @nbsorts: the number of sorts
180 * Signature of the function to use during sorting
182 typedef void (*xsltSortFunc) (xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
196 XSLT_FUNC_APPLYIMPORTS,
197 XSLT_FUNC_CALLTEMPLATE,
198 XSLT_FUNC_APPLYTEMPLATES,
211 * xsltElemPreCompDeallocator:
212 * @comp: the #xsltElemPreComp to free up
214 * Deallocates an #xsltElemPreComp structure.
216 typedef void (*xsltElemPreCompDeallocator) (xsltElemPreCompPtr comp);
221 * The in-memory structure corresponding to element precomputed data,
222 * designed to be extended by extension implementors.
224 struct _xsltElemPreComp {
225 xsltElemPreCompPtr next; /* chained list */
226 xsltStyleType type; /* type of the element */
227 xsltTransformFunction func; /* handling function */
228 xmlNodePtr inst; /* the instruction */
230 /* end of common part */
231 xsltElemPreCompDeallocator free; /* the deallocator */
237 * The in-memory structure corresponding to XSLT stylesheet constructs
240 typedef struct _xsltStylePreComp xsltStylePreComp;
242 typedef xsltStylePreComp *xsltStylePreCompPtr;
244 struct _xsltStylePreComp {
245 xsltElemPreCompPtr next; /* chained list */
246 xsltStyleType type; /* type of the element */
247 xsltTransformFunction func; /* handling function */
248 xmlNodePtr inst; /* the instruction */
251 * Pre computed values.
254 xmlChar *stype; /* sort */
255 int has_stype; /* sort */
256 int number; /* sort */
257 xmlChar *order; /* sort */
258 int has_order; /* sort */
259 int descending; /* sort */
260 xmlChar *lang; /* sort */
261 int has_lang; /* sort */
262 xmlChar *case_order; /* sort */
263 int lower_first; /* sort */
265 xmlChar *use; /* copy, element */
266 int has_use; /* copy, element */
268 int noescape; /* text */
270 xmlChar *name; /* element, attribute, pi */
271 int has_name; /* element, attribute, pi */
272 xmlChar *ns; /* element */
273 int has_ns; /* element */
275 xmlChar *mode; /* apply-templates */
276 xmlChar *modeURI; /* apply-templates */
278 xmlChar *test; /* if */
280 xsltTemplatePtr templ; /* call-template */
282 xmlChar *select; /* sort, copy-of, value-of, apply-templates */
284 int ver11; /* document */
285 xmlChar *filename; /* document URL */
286 int has_filename; /* document */
288 xsltNumberData numdata; /* number */
290 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */
291 xmlNsPtr *nsList; /* the namespaces in scope */
292 int nsNr; /* the number of namespaces in scope */
296 * The in-memory structure corresponding to an XSLT Variable
300 typedef struct _xsltStackElem xsltStackElem;
301 typedef xsltStackElem *xsltStackElemPtr;
302 struct _xsltStackElem {
303 struct _xsltStackElem *next;/* chained list */
304 xsltStylePreCompPtr comp; /* the compiled form */
305 int computed; /* was the evaluation done */
306 xmlChar *name; /* the local part of the name QName */
307 xmlChar *nameURI; /* the URI part of the name QName */
308 xmlChar *select; /* the eval string */
309 xmlNodePtr tree; /* the tree if no eval string or the location */
310 xmlXPathObjectPtr value; /* The value if computed */
314 * The in-memory structure corresponding to an XSLT Stylesheet.
315 * NOTE: most of the content is simply linked from the doc tree
316 * structure, no specific allocation is made.
318 typedef struct _xsltStylesheet xsltStylesheet;
319 typedef xsltStylesheet *xsltStylesheetPtr;
320 struct _xsltStylesheet {
322 * The stylesheet import relation is kept as a tree.
324 struct _xsltStylesheet *parent;
325 struct _xsltStylesheet *next;
326 struct _xsltStylesheet *imports;
328 xsltDocumentPtr docList; /* the include document list */
331 * General data on the style sheet document.
333 xmlDocPtr doc; /* the parsed XML stylesheet */
334 xmlHashTablePtr stripSpaces;/* the hash table of the strip-space and
335 preserve space elements */
336 int stripAll; /* strip-space * (1) preserve-space * (-1) */
337 xmlHashTablePtr cdataSection;/* the hash table of the cdata-section */
340 * Global variable or parameters.
342 xsltStackElemPtr variables; /* linked list of param and variables */
345 * Template descriptions.
347 xsltTemplatePtr templates; /* the ordered list of templates */
348 void *templatesHash; /* hash table or wherever compiled templates
349 informations are stored */
350 void *rootMatch; /* template based on / */
351 void *keyMatch; /* template based on key() */
352 void *elemMatch; /* template based on * */
353 void *attrMatch; /* template based on @* */
354 void *parentMatch; /* template based on .. */
355 void *textMatch; /* template based on text() */
356 void *piMatch; /* template based on processing-instruction() */
357 void *commentMatch; /* template based on comment() */
362 xmlHashTablePtr nsAliases; /* the namespace alias hash tables */
367 xmlHashTablePtr attributeSets;/* the attribute sets hash tables */
372 xmlHashTablePtr nsHash; /* the set of namespaces in use */
373 void *nsDefs; /* the namespaces defined */
378 void *keys; /* key definitions */
381 * Output related stuff.
383 xmlChar *method; /* the output method */
384 xmlChar *methodURI; /* associated namespace if any */
385 xmlChar *version; /* version string */
386 xmlChar *encoding; /* encoding string */
387 int omitXmlDeclaration; /* omit-xml-declaration = "yes" | "no" */
392 xsltDecimalFormatPtr decimalFormat;
393 int standalone; /* standalone = "yes" | "no" */
394 xmlChar *doctypePublic; /* doctype-public string */
395 xmlChar *doctypeSystem; /* doctype-system string */
396 int indent; /* should output being indented */
397 xmlChar *mediaType; /* media-type string */
400 * Precomputed blocks.
402 xsltElemPreCompPtr preComps;/* list of precomputed blocks */
403 int warnings; /* number of warnings found at compilation */
404 int errors; /* number of errors found at compilation */
406 xmlChar *exclPrefix; /* last excluded prefixes */
407 xmlChar **exclPrefixTab; /* array of excluded prefixes */
408 int exclPrefixNr; /* number of excluded prefixes in scope */
409 int exclPrefixMax; /* size of the array */
411 void *_private; /* user defined data */
416 xmlHashTablePtr extInfos; /* the extension data */
417 int extrasNr; /* the number of extras required */
420 * For keeping track of nested includes
422 xsltDocumentPtr includes; /* points to last nested include */
426 * The in-memory structure corresponding to an XSLT Transformation.
438 } xsltTransformState;
440 struct _xsltTransformContext {
441 xsltStylesheetPtr style; /* the stylesheet used */
442 xsltOutputType type; /* the type of output */
444 xsltTemplatePtr templ; /* the current template */
445 int templNr; /* Nb of templates in the stack */
446 int templMax; /* Size of the templtes stack */
447 xsltTemplatePtr *templTab; /* the template stack */
449 xsltStackElemPtr vars; /* the current variable list */
450 int varsNr; /* Nb of variable list in the stack */
451 int varsMax; /* Size of the variable list stack */
452 xsltStackElemPtr *varsTab; /* the variable list stack */
453 int varsBase; /* the var base for current templ */
458 xmlHashTablePtr extFunctions; /* the extension functions */
459 xmlHashTablePtr extElements; /* the extension elements */
460 xmlHashTablePtr extInfos; /* the extension data */
462 const xmlChar *mode; /* the current mode */
463 const xmlChar *modeURI; /* the current mode URI */
465 xsltDocumentPtr docList; /* the document list */
467 xsltDocumentPtr document; /* the current document */
468 xmlNodePtr node; /* the current node being processed */
469 xmlNodeSetPtr nodeList; /* the current node list */
470 /* xmlNodePtr current; the node */
472 xmlDocPtr output; /* the resulting document */
473 xmlNodePtr insert; /* the insertion node */
475 xmlXPathContextPtr xpathCtxt; /* the XPath context */
476 xsltTransformState state; /* the current state */
481 xmlHashTablePtr globalVars; /* the global variables and params */
483 xmlNodePtr inst; /* the instruction in the stylesheet */
485 int xinclude; /* should XInclude be processed */
487 const char * outputFile; /* the output URI if known */
489 int profile; /* is this run profiled */
490 long prof; /* the current profiled value */
491 int profNr; /* Nb of templates in the stack */
492 int profMax; /* Size of the templtaes stack */
493 long *profTab; /* the profile template stack */
495 void *_private; /* user defined data */
497 int extrasNr; /* the number of extras used */
498 int extrasMax; /* the number of extras allocated */
499 xsltRuntimeExtraPtr extras; /* extra per runtime informations */
501 xsltDocumentPtr styleList; /* the stylesheet docs list */
502 void * sec; /* the security preferences if any */
504 xmlGenericErrorFunc error; /* a specific error handler */
505 void * errctx; /* context for the error handler */
507 xsltSortFunc sortfunc; /* a ctxt specific sort routine */
510 * handling of temporary Result Value Tree
512 xmlDocPtr tmpRVT; /* list of RVT without persistance */
513 xmlDocPtr persistRVT; /* list of persistant RVTs */
514 int ctxtflags; /* context processing flags */
517 * Speed optimization when coalescing text nodes
519 const xmlChar *lasttext; /* last text node content */
520 unsigned int lasttsize; /* last text node size */
521 unsigned int lasttuse; /* last text node use */
523 * Per Context Debugging
525 int debugStatus; /* the context level debug status */
526 unsigned long* traceCode; /* pointer to the variable holding the mask */
532 * Macro to check if the XSLT processing should be stopped.
533 * Will return from the function.
535 #define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return;
540 * Macro to check if the XSLT processing should be stopped.
541 * Will goto the error: label.
543 #define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error;
548 * Macro to check if the XSLT processing should be stopped.
549 * Will return from the function with a 0 value.
551 #define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0);
554 * Functions associated to the internal types
555 xsltDecimalFormatPtr xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
558 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
559 xsltNewStylesheet (void);
560 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
561 xsltParseStylesheetFile (const xmlChar* filename);
562 XSLTPUBFUN void XSLTCALL
563 xsltFreeStylesheet (xsltStylesheetPtr sheet);
564 XSLTPUBFUN int XSLTCALL
565 xsltIsBlank (xmlChar *str);
566 XSLTPUBFUN void XSLTCALL
567 xsltFreeStackElemList (xsltStackElemPtr elem);
568 XSLTPUBFUN xsltDecimalFormatPtr XSLTCALL
569 xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
572 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
573 xsltParseStylesheetProcess(xsltStylesheetPtr ret,
575 XSLTPUBFUN void XSLTCALL
576 xsltParseStylesheetOutput(xsltStylesheetPtr style,
578 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
579 xsltParseStylesheetDoc (xmlDocPtr doc);
580 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
581 xsltParseStylesheetImportedDoc(xmlDocPtr doc,
582 xsltStylesheetPtr style);
583 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
584 xsltLoadStylesheetPI (xmlDocPtr doc);
585 XSLTPUBFUN void XSLTCALL
586 xsltNumberFormat (xsltTransformContextPtr ctxt,
587 xsltNumberDataPtr data,
589 XSLTPUBFUN xmlXPathError XSLTCALL
590 xsltFormatNumberConversion(xsltDecimalFormatPtr self,
595 XSLTPUBFUN void XSLTCALL
596 xsltParseTemplateContent(xsltStylesheetPtr style,
598 XSLTPUBFUN int XSLTCALL
599 xsltAllocateExtra (xsltStylesheetPtr style);
600 XSLTPUBFUN int XSLTCALL
601 xsltAllocateExtraCtxt (xsltTransformContextPtr ctxt);
603 * Extra functions for Result Value Trees
605 XSLTPUBFUN xmlDocPtr XSLTCALL
606 xsltCreateRVT (xsltTransformContextPtr ctxt);
607 XSLTPUBFUN int XSLTCALL
608 xsltRegisterTmpRVT (xsltTransformContextPtr ctxt,
610 XSLTPUBFUN int XSLTCALL
611 xsltRegisterPersistRVT (xsltTransformContextPtr ctxt,
613 XSLTPUBFUN void XSLTCALL
614 xsltFreeRVTs (xsltTransformContextPtr ctxt);
620 #endif /* __XML_XSLT_H__ */