2 * Summary: internal data structures, constants and functions
3 * Description: Internal data structures, constants and functions used
5 * They are not part of the API or ABI, i.e. they can change
6 * without prior notice, use carefully.
8 * Copy: See Copyright for the status of this software.
10 * Author: Daniel Veillard
13 #ifndef __XML_XSLT_INTERNALS_H__
14 #define __XML_XSLT_INTERNALS_H__
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 <libxslt/xslt.h>
22 #include "xsltexports.h"
23 #include "numbersInternals.h"
32 * Max number of specified xsl:sort on an element.
34 #define XSLT_MAX_SORT 15
37 * XSLT_PAT_NO_PRIORITY:
39 * Specific value for pattern without priority expressed.
41 #define XSLT_PAT_NO_PRIORITY -12345789
46 * Extra information added to the transformation context.
48 typedef struct _xsltRuntimeExtra xsltRuntimeExtra;
49 typedef xsltRuntimeExtra *xsltRuntimeExtraPtr;
50 struct _xsltRuntimeExtra {
51 void *info; /* pointer to the extra data */
52 xmlFreeFunc deallocate; /* pointer to the deallocation routine */
53 union { /* dual-purpose field */
54 void *ptr; /* data not needing deallocation */
55 int ival; /* integer value storage */
60 * XSLT_RUNTIME_EXTRA_LST:
61 * @ctxt: the transformation context
64 * Macro used to access extra information stored in the context
66 #define XSLT_RUNTIME_EXTRA_LST(ctxt, nr) (ctxt)->extras[(nr)].info
68 * XSLT_RUNTIME_EXTRA_FREE:
69 * @ctxt: the transformation context
72 * Macro used to free extra information stored in the context
74 #define XSLT_RUNTIME_EXTRA_FREE(ctxt, nr) (ctxt)->extras[(nr)].deallocate
77 * @ctxt: the transformation context
80 * Macro used to define extra information stored in the context
82 #define XSLT_RUNTIME_EXTRA(ctxt, nr, typ) (ctxt)->extras[(nr)].val.typ
87 * The in-memory structure corresponding to an XSLT Template.
89 typedef struct _xsltTemplate xsltTemplate;
90 typedef xsltTemplate *xsltTemplatePtr;
91 struct _xsltTemplate {
92 struct _xsltTemplate *next;/* chained list sorted by priority */
93 struct _xsltStylesheet *style;/* the containing stylesheet */
94 xmlChar *match; /* the matching string */
95 float priority; /* as given from the stylesheet, not computed */
96 xmlChar *name; /* the local part of the name QName */
97 xmlChar *nameURI; /* the URI part of the name QName */
98 const xmlChar *mode;/* the local part of the mode QName */
99 const xmlChar *modeURI;/* the URI part of the mode QName */
100 xmlNodePtr content; /* the template replacement value */
101 xmlNodePtr elem; /* the source element */
103 int inheritedNsNr; /* number of inherited namespaces */
104 xmlNsPtr *inheritedNs;/* inherited non-excluded namespaces */
106 /* Profiling informations */
107 int nbCalls; /* the number of time the template was called */
108 unsigned long time; /* the time spent in this template */
114 * Data structure of decimal-format.
116 typedef struct _xsltDecimalFormat xsltDecimalFormat;
117 typedef xsltDecimalFormat *xsltDecimalFormatPtr;
118 struct _xsltDecimalFormat {
119 struct _xsltDecimalFormat *next; /* chained list */
121 /* Used for interpretation of pattern */
123 xmlChar *patternSeparator;
124 /* May appear in result */
127 xmlChar *noNumber; /* Not-a-number */
128 /* Used for interpretation of pattern and may appear in result */
129 xmlChar *decimalPoint;
139 * Data structure associated to a parsed document.
142 typedef struct _xsltDocument xsltDocument;
143 typedef xsltDocument *xsltDocumentPtr;
144 struct _xsltDocument {
145 struct _xsltDocument *next; /* documents are kept in a chained list */
146 int main; /* is this the main document */
147 xmlDocPtr doc; /* the parsed document */
148 void *keys; /* key tables storage */
149 struct _xsltDocument *includes; /* subsidiary includes */
150 int preproc; /* pre-processing already done */
153 typedef struct _xsltTransformContext xsltTransformContext;
154 typedef xsltTransformContext *xsltTransformContextPtr;
159 * The in-memory structure corresponding to element precomputed data,
160 * designed to be extended by extension implementors.
162 typedef struct _xsltElemPreComp xsltElemPreComp;
163 typedef xsltElemPreComp *xsltElemPreCompPtr;
166 * xsltTransformFunction:
167 * @ctxt: the XSLT transformation context
168 * @node: the input node
169 * @inst: the stylesheet node
170 * @comp: the compiled information from the stylesheet
172 * Signature of the function associated to elements part of the
173 * stylesheet language like xsl:if or xsl:apply-templates.
175 typedef void (*xsltTransformFunction) (xsltTransformContextPtr ctxt,
178 xsltElemPreCompPtr comp);
182 * @ctxt: a transformation context
183 * @sorts: the node-set to sort
184 * @nbsorts: the number of sorts
186 * Signature of the function to use during sorting
188 typedef void (*xsltSortFunc) (xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
202 XSLT_FUNC_APPLYIMPORTS,
203 XSLT_FUNC_CALLTEMPLATE,
204 XSLT_FUNC_APPLYTEMPLATES,
217 * xsltElemPreCompDeallocator:
218 * @comp: the #xsltElemPreComp to free up
220 * Deallocates an #xsltElemPreComp structure.
222 typedef void (*xsltElemPreCompDeallocator) (xsltElemPreCompPtr comp);
227 * The in-memory structure corresponding to element precomputed data,
228 * designed to be extended by extension implementors.
230 struct _xsltElemPreComp {
231 xsltElemPreCompPtr next; /* chained list */
232 xsltStyleType type; /* type of the element */
233 xsltTransformFunction func; /* handling function */
234 xmlNodePtr inst; /* the instruction */
236 /* end of common part */
237 xsltElemPreCompDeallocator free; /* the deallocator */
243 * The in-memory structure corresponding to XSLT stylesheet constructs
246 typedef struct _xsltStylePreComp xsltStylePreComp;
248 typedef xsltStylePreComp *xsltStylePreCompPtr;
250 struct _xsltStylePreComp {
251 xsltElemPreCompPtr next; /* chained list */
252 xsltStyleType type; /* type of the element */
253 xsltTransformFunction func; /* handling function */
254 xmlNodePtr inst; /* the instruction */
257 * Pre computed values.
260 const xmlChar *stype; /* sort */
261 int has_stype; /* sort */
262 int number; /* sort */
263 const xmlChar *order; /* sort */
264 int has_order; /* sort */
265 int descending; /* sort */
266 const xmlChar *lang; /* sort */
267 int has_lang; /* sort */
268 const xmlChar *case_order; /* sort */
269 int lower_first; /* sort */
271 const xmlChar *use; /* copy, element */
272 int has_use; /* copy, element */
274 int noescape; /* text */
276 const xmlChar *name; /* element, attribute, pi */
277 int has_name; /* element, attribute, pi */
278 const xmlChar *ns; /* element */
279 int has_ns; /* element */
281 const xmlChar *mode; /* apply-templates */
282 const xmlChar *modeURI; /* apply-templates */
284 const xmlChar *test; /* if */
286 xsltTemplatePtr templ; /* call-template */
288 const xmlChar *select; /* sort, copy-of, value-of, apply-templates */
290 int ver11; /* document */
291 const xmlChar *filename; /* document URL */
292 int has_filename; /* document */
294 xsltNumberData numdata; /* number */
296 xmlXPathCompExprPtr comp; /* a precompiled XPath expression */
297 xmlNsPtr *nsList; /* the namespaces in scope */
298 int nsNr; /* the number of namespaces in scope */
302 * The in-memory structure corresponding to an XSLT Variable
306 typedef struct _xsltStackElem xsltStackElem;
307 typedef xsltStackElem *xsltStackElemPtr;
308 struct _xsltStackElem {
309 struct _xsltStackElem *next;/* chained list */
310 xsltStylePreCompPtr comp; /* the compiled form */
311 int computed; /* was the evaluation done */
312 const xmlChar *name; /* the local part of the name QName */
313 const xmlChar *nameURI; /* the URI part of the name QName */
314 const xmlChar *select; /* the eval string */
315 xmlNodePtr tree; /* the tree if no eval string or the location */
316 xmlXPathObjectPtr value; /* The value if computed */
320 * The in-memory structure corresponding to an XSLT Stylesheet.
321 * NOTE: most of the content is simply linked from the doc tree
322 * structure, no specific allocation is made.
324 typedef struct _xsltStylesheet xsltStylesheet;
325 typedef xsltStylesheet *xsltStylesheetPtr;
326 struct _xsltStylesheet {
328 * The stylesheet import relation is kept as a tree.
330 struct _xsltStylesheet *parent;
331 struct _xsltStylesheet *next;
332 struct _xsltStylesheet *imports;
334 xsltDocumentPtr docList; /* the include document list */
337 * General data on the style sheet document.
339 xmlDocPtr doc; /* the parsed XML stylesheet */
340 xmlHashTablePtr stripSpaces;/* the hash table of the strip-space and
341 preserve space elements */
342 int stripAll; /* strip-space * (1) preserve-space * (-1) */
343 xmlHashTablePtr cdataSection;/* the hash table of the cdata-section */
346 * Global variable or parameters.
348 xsltStackElemPtr variables; /* linked list of param and variables */
351 * Template descriptions.
353 xsltTemplatePtr templates; /* the ordered list of templates */
354 void *templatesHash; /* hash table or wherever compiled templates
355 informations are stored */
356 void *rootMatch; /* template based on / */
357 void *keyMatch; /* template based on key() */
358 void *elemMatch; /* template based on * */
359 void *attrMatch; /* template based on @* */
360 void *parentMatch; /* template based on .. */
361 void *textMatch; /* template based on text() */
362 void *piMatch; /* template based on processing-instruction() */
363 void *commentMatch; /* template based on comment() */
368 xmlHashTablePtr nsAliases; /* the namespace alias hash tables */
373 xmlHashTablePtr attributeSets;/* the attribute sets hash tables */
378 xmlHashTablePtr nsHash; /* the set of namespaces in use */
379 void *nsDefs; /* the namespaces defined */
384 void *keys; /* key definitions */
387 * Output related stuff.
389 xmlChar *method; /* the output method */
390 xmlChar *methodURI; /* associated namespace if any */
391 xmlChar *version; /* version string */
392 xmlChar *encoding; /* encoding string */
393 int omitXmlDeclaration; /* omit-xml-declaration = "yes" | "no" */
398 xsltDecimalFormatPtr decimalFormat;
399 int standalone; /* standalone = "yes" | "no" */
400 xmlChar *doctypePublic; /* doctype-public string */
401 xmlChar *doctypeSystem; /* doctype-system string */
402 int indent; /* should output being indented */
403 xmlChar *mediaType; /* media-type string */
406 * Precomputed blocks.
408 xsltElemPreCompPtr preComps;/* list of precomputed blocks */
409 int warnings; /* number of warnings found at compilation */
410 int errors; /* number of errors found at compilation */
412 xmlChar *exclPrefix; /* last excluded prefixes */
413 xmlChar **exclPrefixTab; /* array of excluded prefixes */
414 int exclPrefixNr; /* number of excluded prefixes in scope */
415 int exclPrefixMax; /* size of the array */
417 void *_private; /* user defined data */
422 xmlHashTablePtr extInfos; /* the extension data */
423 int extrasNr; /* the number of extras required */
426 * For keeping track of nested includes
428 xsltDocumentPtr includes; /* points to last nested include */
431 * dictionnary: shared between stylesheet, context and documents.
435 * precompiled attribute value templates.
439 * if namespace-alias has an alias for the default stylesheet prefix
441 const xmlChar *defaultAlias;
443 * bypass pre-processing (already done) (used in imports)
447 * all document text strings were internalized
453 * The in-memory structure corresponding to an XSLT Transformation.
465 } xsltTransformState;
467 struct _xsltTransformContext {
468 xsltStylesheetPtr style; /* the stylesheet used */
469 xsltOutputType type; /* the type of output */
471 xsltTemplatePtr templ; /* the current template */
472 int templNr; /* Nb of templates in the stack */
473 int templMax; /* Size of the templtes stack */
474 xsltTemplatePtr *templTab; /* the template stack */
476 xsltStackElemPtr vars; /* the current variable list */
477 int varsNr; /* Nb of variable list in the stack */
478 int varsMax; /* Size of the variable list stack */
479 xsltStackElemPtr *varsTab; /* the variable list stack */
480 int varsBase; /* the var base for current templ */
485 xmlHashTablePtr extFunctions; /* the extension functions */
486 xmlHashTablePtr extElements; /* the extension elements */
487 xmlHashTablePtr extInfos; /* the extension data */
489 const xmlChar *mode; /* the current mode */
490 const xmlChar *modeURI; /* the current mode URI */
492 xsltDocumentPtr docList; /* the document list */
494 xsltDocumentPtr document; /* the current document */
495 xmlNodePtr node; /* the current node being processed */
496 xmlNodeSetPtr nodeList; /* the current node list */
497 /* xmlNodePtr current; the node */
499 xmlDocPtr output; /* the resulting document */
500 xmlNodePtr insert; /* the insertion node */
502 xmlXPathContextPtr xpathCtxt; /* the XPath context */
503 xsltTransformState state; /* the current state */
508 xmlHashTablePtr globalVars; /* the global variables and params */
510 xmlNodePtr inst; /* the instruction in the stylesheet */
512 int xinclude; /* should XInclude be processed */
514 const char * outputFile; /* the output URI if known */
516 int profile; /* is this run profiled */
517 long prof; /* the current profiled value */
518 int profNr; /* Nb of templates in the stack */
519 int profMax; /* Size of the templtaes stack */
520 long *profTab; /* the profile template stack */
522 void *_private; /* user defined data */
524 int extrasNr; /* the number of extras used */
525 int extrasMax; /* the number of extras allocated */
526 xsltRuntimeExtraPtr extras; /* extra per runtime informations */
528 xsltDocumentPtr styleList; /* the stylesheet docs list */
529 void * sec; /* the security preferences if any */
531 xmlGenericErrorFunc error; /* a specific error handler */
532 void * errctx; /* context for the error handler */
534 xsltSortFunc sortfunc; /* a ctxt specific sort routine */
537 * handling of temporary Result Value Tree
539 xmlDocPtr tmpRVT; /* list of RVT without persistance */
540 xmlDocPtr persistRVT; /* list of persistant RVTs */
541 int ctxtflags; /* context processing flags */
544 * Speed optimization when coalescing text nodes
546 const xmlChar *lasttext; /* last text node content */
547 unsigned int lasttsize; /* last text node size */
548 unsigned int lasttuse; /* last text node use */
550 * Per Context Debugging
552 int debugStatus; /* the context level debug status */
553 unsigned long* traceCode; /* pointer to the variable holding the mask */
555 int parserOptions; /* parser options xmlParserOption */
558 * dictionnary: shared between stylesheet, context and documents.
562 * temporary storage for doc ptr, currently only used for
563 * global var evaluation
567 * all document text strings are internalized
575 * Macro to check if the XSLT processing should be stopped.
576 * Will return from the function.
578 #define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return;
583 * Macro to check if the XSLT processing should be stopped.
584 * Will goto the error: label.
586 #define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error;
591 * Macro to check if the XSLT processing should be stopped.
592 * Will return from the function with a 0 value.
594 #define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0);
597 * The macro XML_CAST_FPTR is a hack to avoid a gcc warning about
598 * possible incompatibilities between function pointers and object
599 * pointers. It is defined in libxml/hash.h within recent versions
600 * of libxml2, but is put here for compatibility.
602 #ifndef XML_CAST_FPTR
605 * @fptr: pointer to a function
607 * Macro to do a casting from an object pointer to a
608 * function pointer without encountering a warning from
611 * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
612 * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
613 * so it is disabled now
616 #define XML_CAST_FPTR(fptr) fptr
619 * Functions associated to the internal types
620 xsltDecimalFormatPtr xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
623 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
624 xsltNewStylesheet (void);
625 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
626 xsltParseStylesheetFile (const xmlChar* filename);
627 XSLTPUBFUN void XSLTCALL
628 xsltFreeStylesheet (xsltStylesheetPtr sheet);
629 XSLTPUBFUN int XSLTCALL
630 xsltIsBlank (xmlChar *str);
631 XSLTPUBFUN void XSLTCALL
632 xsltFreeStackElemList (xsltStackElemPtr elem);
633 XSLTPUBFUN xsltDecimalFormatPtr XSLTCALL
634 xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
637 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
638 xsltParseStylesheetProcess(xsltStylesheetPtr ret,
640 XSLTPUBFUN void XSLTCALL
641 xsltParseStylesheetOutput(xsltStylesheetPtr style,
643 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
644 xsltParseStylesheetDoc (xmlDocPtr doc);
645 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
646 xsltParseStylesheetImportedDoc(xmlDocPtr doc,
647 xsltStylesheetPtr style);
648 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
649 xsltLoadStylesheetPI (xmlDocPtr doc);
650 XSLTPUBFUN void XSLTCALL
651 xsltNumberFormat (xsltTransformContextPtr ctxt,
652 xsltNumberDataPtr data,
654 XSLTPUBFUN xmlXPathError XSLTCALL
655 xsltFormatNumberConversion(xsltDecimalFormatPtr self,
660 XSLTPUBFUN void XSLTCALL
661 xsltParseTemplateContent(xsltStylesheetPtr style,
663 XSLTPUBFUN int XSLTCALL
664 xsltAllocateExtra (xsltStylesheetPtr style);
665 XSLTPUBFUN int XSLTCALL
666 xsltAllocateExtraCtxt (xsltTransformContextPtr ctxt);
668 * Extra functions for Result Value Trees
670 XSLTPUBFUN xmlDocPtr XSLTCALL
671 xsltCreateRVT (xsltTransformContextPtr ctxt);
672 XSLTPUBFUN int XSLTCALL
673 xsltRegisterTmpRVT (xsltTransformContextPtr ctxt,
675 XSLTPUBFUN int XSLTCALL
676 xsltRegisterPersistRVT (xsltTransformContextPtr ctxt,
678 XSLTPUBFUN void XSLTCALL
679 xsltFreeRVTs (xsltTransformContextPtr ctxt);
682 * Extra functions for Attribute Value Templates
684 XSLTPUBFUN void XSLTCALL
685 xsltCompileAttr (xsltStylesheetPtr style,
687 XSLTPUBFUN xmlChar * XSLTCALL
688 xsltEvalAVT (xsltTransformContextPtr ctxt,
691 XSLTPUBFUN void XSLTCALL
692 xsltFreeAVTList (void *avt);
697 #endif /* __XML_XSLT_H__ */