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
451 * Literal Result Element as Stylesheet c.f. section 2.3
457 * The in-memory structure corresponding to an XSLT Transformation.
469 } xsltTransformState;
471 struct _xsltTransformContext {
472 xsltStylesheetPtr style; /* the stylesheet used */
473 xsltOutputType type; /* the type of output */
475 xsltTemplatePtr templ; /* the current template */
476 int templNr; /* Nb of templates in the stack */
477 int templMax; /* Size of the templtes stack */
478 xsltTemplatePtr *templTab; /* the template stack */
480 xsltStackElemPtr vars; /* the current variable list */
481 int varsNr; /* Nb of variable list in the stack */
482 int varsMax; /* Size of the variable list stack */
483 xsltStackElemPtr *varsTab; /* the variable list stack */
484 int varsBase; /* the var base for current templ */
489 xmlHashTablePtr extFunctions; /* the extension functions */
490 xmlHashTablePtr extElements; /* the extension elements */
491 xmlHashTablePtr extInfos; /* the extension data */
493 const xmlChar *mode; /* the current mode */
494 const xmlChar *modeURI; /* the current mode URI */
496 xsltDocumentPtr docList; /* the document list */
498 xsltDocumentPtr document; /* the current document */
499 xmlNodePtr node; /* the current node being processed */
500 xmlNodeSetPtr nodeList; /* the current node list */
501 /* xmlNodePtr current; the node */
503 xmlDocPtr output; /* the resulting document */
504 xmlNodePtr insert; /* the insertion node */
506 xmlXPathContextPtr xpathCtxt; /* the XPath context */
507 xsltTransformState state; /* the current state */
512 xmlHashTablePtr globalVars; /* the global variables and params */
514 xmlNodePtr inst; /* the instruction in the stylesheet */
516 int xinclude; /* should XInclude be processed */
518 const char * outputFile; /* the output URI if known */
520 int profile; /* is this run profiled */
521 long prof; /* the current profiled value */
522 int profNr; /* Nb of templates in the stack */
523 int profMax; /* Size of the templtaes stack */
524 long *profTab; /* the profile template stack */
526 void *_private; /* user defined data */
528 int extrasNr; /* the number of extras used */
529 int extrasMax; /* the number of extras allocated */
530 xsltRuntimeExtraPtr extras; /* extra per runtime informations */
532 xsltDocumentPtr styleList; /* the stylesheet docs list */
533 void * sec; /* the security preferences if any */
535 xmlGenericErrorFunc error; /* a specific error handler */
536 void * errctx; /* context for the error handler */
538 xsltSortFunc sortfunc; /* a ctxt specific sort routine */
541 * handling of temporary Result Value Tree
543 xmlDocPtr tmpRVT; /* list of RVT without persistance */
544 xmlDocPtr persistRVT; /* list of persistant RVTs */
545 int ctxtflags; /* context processing flags */
548 * Speed optimization when coalescing text nodes
550 const xmlChar *lasttext; /* last text node content */
551 unsigned int lasttsize; /* last text node size */
552 unsigned int lasttuse; /* last text node use */
554 * Per Context Debugging
556 int debugStatus; /* the context level debug status */
557 unsigned long* traceCode; /* pointer to the variable holding the mask */
559 int parserOptions; /* parser options xmlParserOption */
562 * dictionnary: shared between stylesheet, context and documents.
566 * temporary storage for doc ptr, currently only used for
567 * global var evaluation
571 * all document text strings are internalized
579 * Macro to check if the XSLT processing should be stopped.
580 * Will return from the function.
582 #define CHECK_STOPPED if (ctxt->state == XSLT_STATE_STOPPED) return;
587 * Macro to check if the XSLT processing should be stopped.
588 * Will goto the error: label.
590 #define CHECK_STOPPEDE if (ctxt->state == XSLT_STATE_STOPPED) goto error;
595 * Macro to check if the XSLT processing should be stopped.
596 * Will return from the function with a 0 value.
598 #define CHECK_STOPPED0 if (ctxt->state == XSLT_STATE_STOPPED) return(0);
601 * The macro XML_CAST_FPTR is a hack to avoid a gcc warning about
602 * possible incompatibilities between function pointers and object
603 * pointers. It is defined in libxml/hash.h within recent versions
604 * of libxml2, but is put here for compatibility.
606 #ifndef XML_CAST_FPTR
609 * @fptr: pointer to a function
611 * Macro to do a casting from an object pointer to a
612 * function pointer without encountering a warning from
615 * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
616 * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
617 * so it is disabled now
620 #define XML_CAST_FPTR(fptr) fptr
623 * Functions associated to the internal types
624 xsltDecimalFormatPtr xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
627 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
628 xsltNewStylesheet (void);
629 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
630 xsltParseStylesheetFile (const xmlChar* filename);
631 XSLTPUBFUN void XSLTCALL
632 xsltFreeStylesheet (xsltStylesheetPtr sheet);
633 XSLTPUBFUN int XSLTCALL
634 xsltIsBlank (xmlChar *str);
635 XSLTPUBFUN void XSLTCALL
636 xsltFreeStackElemList (xsltStackElemPtr elem);
637 XSLTPUBFUN xsltDecimalFormatPtr XSLTCALL
638 xsltDecimalFormatGetByName(xsltStylesheetPtr sheet,
641 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
642 xsltParseStylesheetProcess(xsltStylesheetPtr ret,
644 XSLTPUBFUN void XSLTCALL
645 xsltParseStylesheetOutput(xsltStylesheetPtr style,
647 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
648 xsltParseStylesheetDoc (xmlDocPtr doc);
649 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
650 xsltParseStylesheetImportedDoc(xmlDocPtr doc,
651 xsltStylesheetPtr style);
652 XSLTPUBFUN xsltStylesheetPtr XSLTCALL
653 xsltLoadStylesheetPI (xmlDocPtr doc);
654 XSLTPUBFUN void XSLTCALL
655 xsltNumberFormat (xsltTransformContextPtr ctxt,
656 xsltNumberDataPtr data,
658 XSLTPUBFUN xmlXPathError XSLTCALL
659 xsltFormatNumberConversion(xsltDecimalFormatPtr self,
664 XSLTPUBFUN void XSLTCALL
665 xsltParseTemplateContent(xsltStylesheetPtr style,
667 XSLTPUBFUN int XSLTCALL
668 xsltAllocateExtra (xsltStylesheetPtr style);
669 XSLTPUBFUN int XSLTCALL
670 xsltAllocateExtraCtxt (xsltTransformContextPtr ctxt);
672 * Extra functions for Result Value Trees
674 XSLTPUBFUN xmlDocPtr XSLTCALL
675 xsltCreateRVT (xsltTransformContextPtr ctxt);
676 XSLTPUBFUN int XSLTCALL
677 xsltRegisterTmpRVT (xsltTransformContextPtr ctxt,
679 XSLTPUBFUN int XSLTCALL
680 xsltRegisterPersistRVT (xsltTransformContextPtr ctxt,
682 XSLTPUBFUN void XSLTCALL
683 xsltFreeRVTs (xsltTransformContextPtr ctxt);
686 * Extra functions for Attribute Value Templates
688 XSLTPUBFUN void XSLTCALL
689 xsltCompileAttr (xsltStylesheetPtr style,
691 XSLTPUBFUN xmlChar * XSLTCALL
692 xsltEvalAVT (xsltTransformContextPtr ctxt,
695 XSLTPUBFUN void XSLTCALL
696 xsltFreeAVTList (void *avt);
701 #endif /* __XML_XSLT_H__ */