2 * pattern.c: Implemetation of the template match compilation and lookup
5 * http://www.w3.org/TR/1999/REC-xslt-19991116
7 * See Copyright for the status of this software.
13 * TODO: handle pathological cases like *[*[@a="b"]]
14 * TODO: detect [number] at compilation, optimize accordingly
21 #include <libxml/xmlmemory.h>
22 #include <libxml/tree.h>
23 #include <libxml/valid.h>
24 #include <libxml/hash.h>
25 #include <libxml/xmlerror.h>
26 #include <libxml/parserInternals.h>
28 #include "xsltInternals.h"
29 #include "xsltutils.h"
31 #include "templates.h"
35 #ifdef WITH_XSLT_DEBUG
36 #define WITH_XSLT_DEBUG_PATTERN
63 typedef struct _xsltStepOp xsltStepOp;
64 typedef xsltStepOp *xsltStepOpPtr;
70 xmlXPathCompExprPtr comp;
72 * Optimisations for count
79 struct _xsltCompMatch {
80 struct _xsltCompMatch *next; /* siblings in the name hash */
81 float priority; /* the priority */
82 const xmlChar *pattern; /* the pattern */
83 const xmlChar *mode; /* the mode */
84 const xmlChar *modeURI; /* the mode URI */
85 xsltTemplatePtr template; /* the associated template */
87 /* TODO fix the statically allocated size steps[] */
90 xmlNsPtr *nsList; /* the namespaces in scope */
91 int nsNr; /* the number of namespaces in scope */
92 xsltStepOp steps[20]; /* ops for computation */
95 typedef struct _xsltParserContext xsltParserContext;
96 typedef xsltParserContext *xsltParserContextPtr;
97 struct _xsltParserContext {
98 const xmlChar *cur; /* the current char being parsed */
99 const xmlChar *base; /* the full expression */
100 xmlDocPtr doc; /* the source document */
101 xmlNodePtr elem; /* the source element */
102 int error; /* error code */
103 xsltCompMatchPtr comp; /* the result */
106 /************************************************************************
110 ************************************************************************/
115 * Create a new XSLT CompMatch
117 * Returns the newly allocated xsltCompMatchPtr or NULL in case of error
119 static xsltCompMatchPtr
120 xsltNewCompMatch(void) {
121 xsltCompMatchPtr cur;
123 cur = (xsltCompMatchPtr) xmlMalloc(sizeof(xsltCompMatch));
125 xsltPrintErrorContext(NULL, NULL, NULL);
126 xsltGenericError(xsltGenericErrorContext,
127 "xsltNewCompMatch : malloc failed\n");
130 memset(cur, 0, sizeof(xsltCompMatch));
139 * @comp: an XSLT comp
141 * Free up the memory allocated by @comp
144 xsltFreeCompMatch(xsltCompMatchPtr comp) {
150 if (comp->pattern != NULL)
151 xmlFree((xmlChar *)comp->pattern);
152 if (comp->mode != NULL)
153 xmlFree((xmlChar *)comp->mode);
154 if (comp->modeURI != NULL)
155 xmlFree((xmlChar *)comp->modeURI);
156 if (comp->nsList != NULL)
157 xmlFree(comp->nsList);
158 for (i = 0;i < comp->nbStep;i++) {
159 op = &comp->steps[i];
160 if (op->value != NULL)
162 if (op->value2 != NULL)
164 if (op->value3 != NULL)
166 if (op->comp != NULL)
167 xmlXPathFreeCompExpr(op->comp);
169 memset(comp, -1, sizeof(xsltCompMatch));
174 * xsltFreeCompMatchList:
175 * @comp: an XSLT comp list
177 * Free up the memory allocated by all the elements of @comp
180 xsltFreeCompMatchList(xsltCompMatchPtr comp) {
181 xsltCompMatchPtr cur;
183 while (comp != NULL) {
186 xsltFreeCompMatch(cur);
191 * xsltNewParserContext:
193 * Create a new XSLT ParserContext
195 * Returns the newly allocated xsltParserContextPtr or NULL in case of error
197 static xsltParserContextPtr
198 xsltNewParserContext(void) {
199 xsltParserContextPtr cur;
201 cur = (xsltParserContextPtr) xmlMalloc(sizeof(xsltParserContext));
203 xsltPrintErrorContext(NULL, NULL, NULL);
204 xsltGenericError(xsltGenericErrorContext,
205 "xsltNewParserContext : malloc failed\n");
208 memset(cur, 0, sizeof(xsltParserContext));
213 * xsltFreeParserContext:
214 * @ctxt: an XSLT parser context
216 * Free up the memory allocated by @ctxt
219 xsltFreeParserContext(xsltParserContextPtr ctxt) {
222 memset(ctxt, -1, sizeof(xsltParserContext));
228 * @comp: the compiled match expression
230 * @value: the first value
231 * @value2: the second value
233 * Add an step to an XSLT Compiled Match
235 * Returns -1 in case of failure, 0 otherwise.
238 xsltCompMatchAdd(xsltCompMatchPtr comp, xsltOp op, xmlChar *value,
240 if (comp->nbStep >= 20) {
241 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
242 xsltGenericError(xsltGenericErrorContext,
243 "xsltCompMatchAdd: overflow\n");
246 comp->steps[comp->nbStep].op = op;
247 comp->steps[comp->nbStep].value = value;
248 comp->steps[comp->nbStep].value2 = value2;
254 * xsltSwapTopCompMatch:
255 * @comp: the compiled match expression
257 * reverse the two top steps.
260 xsltSwapTopCompMatch(xsltCompMatchPtr comp) {
262 int j = comp->nbStep - 1;
265 register xmlChar *tmp;
268 tmp = comp->steps[i].value;
269 comp->steps[i].value = comp->steps[j].value;
270 comp->steps[j].value = tmp;
271 tmp = comp->steps[i].value2;
272 comp->steps[i].value2 = comp->steps[j].value2;
273 comp->steps[j].value2 = tmp;
274 op = comp->steps[i].op;
275 comp->steps[i].op = comp->steps[j].op;
276 comp->steps[j].op = op;
281 * xsltReverseCompMatch:
282 * @comp: the compiled match expression
284 * reverse all the stack of expressions
287 xsltReverseCompMatch(xsltCompMatchPtr comp) {
289 int j = comp->nbStep - 1;
292 register xmlChar *tmp;
294 tmp = comp->steps[i].value;
295 comp->steps[i].value = comp->steps[j].value;
296 comp->steps[j].value = tmp;
297 tmp = comp->steps[i].value2;
298 comp->steps[i].value2 = comp->steps[j].value2;
299 comp->steps[j].value2 = tmp;
300 op = comp->steps[i].op;
301 comp->steps[i].op = comp->steps[j].op;
302 comp->steps[j].op = op;
306 comp->steps[comp->nbStep++].op = XSLT_OP_END;
310 * xsltCleanupCompMatch:
311 * @comp: the compiled match expression
313 * remove all computation state from the pattern
316 xsltCleanupCompMatch(xsltCompMatchPtr comp) {
319 for (i = 0;i < comp->nbStep;i++) {
320 comp->steps[i].previous = NULL;
324 /************************************************************************
326 * The interpreter for the precompiled patterns *
328 ************************************************************************/
332 * @ctxt: a XSLT process context
333 * @comp: the precompiled pattern
335 * @mode: the mode name or NULL
336 * @modeURI: the mode URI or NULL
338 * Test wether the node matches the pattern
340 * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure
343 xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp,
344 xmlNodePtr node, const xmlChar *mode,
345 const xmlChar *modeURI) {
347 xsltStepOpPtr step, select = NULL;
349 if ((comp == NULL) || (node == NULL) || (ctxt == NULL)) {
350 xsltPrintErrorContext(ctxt, NULL, node);
351 xsltGenericError(xsltGenericErrorContext,
352 "xsltTestCompMatch: null arg\n");
356 if (comp->mode == NULL)
358 if ((comp->mode != mode) && (!xmlStrEqual(comp->mode, mode)))
361 if (comp->mode != NULL)
364 if (modeURI != NULL) {
365 if (comp->modeURI == NULL)
367 if ((comp->modeURI != modeURI) &&
368 (!xmlStrEqual(comp->modeURI, modeURI)))
371 if (comp->modeURI != NULL)
374 for (i = 0;i < comp->nbStep;i++) {
375 step = &comp->steps[i];
376 if (step->op != XSLT_OP_PREDICATE)
382 if ((node->type == XML_DOCUMENT_NODE) ||
383 #ifdef LIBXML_DOCB_ENABLED
384 (node->type == XML_DOCB_DOCUMENT_NODE) ||
386 (node->type == XML_HTML_DOCUMENT_NODE))
390 if (node->type != XML_ELEMENT_NODE)
392 if (step->value == NULL)
394 if (!xmlStrEqual(step->value, node->name))
398 if (node->ns == NULL) {
399 if (step->value2 != NULL)
401 } else if (node->ns->href != NULL) {
402 if (step->value2 == NULL)
404 if (!xmlStrEqual(step->value2, node->ns->href))
408 case XSLT_OP_CHILD: {
411 if ((node->type != XML_ELEMENT_NODE) &&
412 (node->type != XML_DOCUMENT_NODE) &&
413 #ifdef LIBXML_DOCB_ENABLED
414 (node->type != XML_DOCB_DOCUMENT_NODE) &&
416 (node->type != XML_HTML_DOCUMENT_NODE))
419 lst = node->children;
421 if (step->value != NULL) {
422 while (lst != NULL) {
423 if ((lst->type == XML_ELEMENT_NODE) &&
424 (xmlStrEqual(step->value, lst->name)))
434 if (node->type != XML_ATTRIBUTE_NODE)
436 if (step->value == NULL)
438 if (!xmlStrEqual(step->value, node->name))
442 if (node->ns == NULL) {
443 if (step->value2 != NULL)
445 } else if (node->ns->href != NULL) {
446 if (step->value2 == NULL)
448 if (!xmlStrEqual(step->value2, node->ns->href))
453 if ((node->type != XML_ELEMENT_NODE) &&
454 (node->type != XML_ATTRIBUTE_NODE))
459 if (step->value == NULL)
461 if (!xmlStrEqual(step->value, node->name))
464 if (node->ns == NULL) {
465 if (step->value2 != NULL)
467 } else if (node->ns->href != NULL) {
468 if (step->value2 == NULL)
470 if (!xmlStrEqual(step->value2, node->ns->href))
474 case XSLT_OP_ANCESTOR:
475 /* TODO: implement coalescing of ANCESTOR/NODE ops */
476 if (step->value == NULL) {
478 step = &comp->steps[i];
479 if (step->op == XSLT_OP_ROOT)
481 if (step->op != XSLT_OP_ELEM)
483 if (step->value == NULL)
489 while (node != NULL) {
492 if (xmlStrEqual(step->value, node->name)) {
494 if (node->ns == NULL) {
495 if (step->value2 == NULL)
497 } else if (node->ns->href != NULL) {
498 if ((step->value2 != NULL) &&
499 (xmlStrEqual(step->value2, node->ns->href)))
509 /* TODO Handle IDs decently, must be done differently */
512 if (node->type != XML_ELEMENT_NODE)
515 id = xmlGetID(node->doc, step->value);
516 if ((id == NULL) || (id->parent != node))
524 list = xsltGetKey(ctxt, step->value,
525 step->value3, step->value2);
528 for (indx = 0;indx < list->nodeNr;indx++)
529 if (list->nodeTab[indx] == node)
531 if (indx >= list->nodeNr)
536 if (node->type != XML_ELEMENT_NODE)
538 if (node->ns == NULL) {
539 if (step->value != NULL)
541 } else if (node->ns->href != NULL) {
542 if (step->value == NULL)
544 if (!xmlStrEqual(step->value, node->ns->href))
549 if (node->type != XML_ELEMENT_NODE)
552 case XSLT_OP_PREDICATE: {
555 int pos = 0, len = 0;
557 * Depending on the last selection, one may need to
558 * recompute contextSize and proximityPosition.
560 * TODO: make this thread safe !
562 oldCS = ctxt->xpathCtxt->contextSize;
563 oldCP = ctxt->xpathCtxt->proximityPosition;
564 if ((select != NULL) &&
565 (select->op == XSLT_OP_ELEM) &&
566 (select->value != NULL) &&
567 (node->type == XML_ELEMENT_NODE) &&
568 (node->parent != NULL)) {
570 if ((select->previous != NULL) &&
571 (select->previous->parent == node->parent)) {
573 * just walk back to adjust the index
576 xmlNodePtr sibling = node;
578 while (sibling != NULL) {
579 if (sibling == select->previous)
581 if (xmlStrEqual(node->name, sibling->name)) {
582 if ((select->value2 == NULL) ||
583 ((sibling->ns != NULL) &&
584 (xmlStrEqual(select->value2,
585 sibling->ns->href))))
588 sibling = sibling->prev;
590 if (sibling == NULL) {
591 /* hum going backward in document order ... */
594 while (sibling != NULL) {
595 if (sibling == select->previous)
597 if ((select->value2 == NULL) ||
598 ((sibling->ns != NULL) &&
599 (xmlStrEqual(select->value2,
600 sibling->ns->href))))
602 sibling = sibling->next;
605 if (sibling != NULL) {
606 pos = select->index + indx;
608 select->previous = node;
614 * recompute the index
616 xmlNodePtr siblings = node->parent->children;
618 while (siblings != NULL) {
619 if (siblings->type == XML_ELEMENT_NODE) {
620 if (siblings == node) {
623 } else if (xmlStrEqual(node->name,
625 if ((select->value2 == NULL) ||
626 ((siblings->ns != NULL) &&
627 (xmlStrEqual(select->value2,
628 siblings->ns->href))))
632 siblings = siblings->next;
636 ctxt->xpathCtxt->contextSize = len;
637 ctxt->xpathCtxt->proximityPosition = pos;
638 select->previous = node;
642 } else if ((select != NULL) && (select->op == XSLT_OP_ALL) &&
643 (node->type == XML_ELEMENT_NODE)) {
644 if ((select->previous != NULL) &&
645 (select->previous->parent == node->parent)) {
647 * just walk back to adjust the index
650 xmlNodePtr sibling = node;
652 while (sibling != NULL) {
653 if (sibling == select->previous)
655 if (sibling->type == XML_ELEMENT_NODE)
657 sibling = sibling->prev;
659 if (sibling == NULL) {
660 /* hum going backward in document order ... */
663 while (sibling != NULL) {
664 if (sibling == select->previous)
666 if (sibling->type == XML_ELEMENT_NODE)
668 sibling = sibling->next;
671 if (sibling != NULL) {
672 pos = select->index + indx;
674 select->previous = node;
680 * recompute the index
682 xmlNodePtr siblings = node->parent->children;
684 while (siblings != NULL) {
685 if (siblings->type == XML_ELEMENT_NODE) {
687 if (siblings == node) {
691 siblings = siblings->next;
695 ctxt->xpathCtxt->contextSize = len;
696 ctxt->xpathCtxt->proximityPosition = pos;
697 select->previous = node;
702 oldNode = ctxt->node;
705 if (step->value == NULL)
708 if (step->comp == NULL) {
709 step->comp = xmlXPathCompile(step->value);
710 if (step->comp == NULL)
713 if (comp->nsList == NULL) {
716 comp->nsList = xmlGetNsList(node->doc, node);
717 if (comp->nsList != NULL) {
718 while (comp->nsList[j] != NULL)
723 if (!xsltEvalXPathPredicate(ctxt, step->comp, comp->nsList,
728 ctxt->xpathCtxt->contextSize = oldCS;
729 ctxt->xpathCtxt->proximityPosition = oldCP;
731 ctxt->node = oldNode;
735 ctxt->xpathCtxt->contextSize = oldCS;
736 ctxt->xpathCtxt->proximityPosition = oldCP;
738 ctxt->node = oldNode;
742 if (node->type != XML_PI_NODE)
744 if (step->value != NULL) {
745 if (!xmlStrEqual(step->value, node->name))
749 case XSLT_OP_COMMENT:
750 if (node->type != XML_COMMENT_NODE)
754 if ((node->type != XML_TEXT_NODE) &&
755 (node->type != XML_CDATA_SECTION_NODE))
759 switch (node->type) {
760 case XML_DOCUMENT_NODE:
761 case XML_HTML_DOCUMENT_NODE:
762 #ifdef LIBXML_DOCB_ENABLED
763 case XML_DOCB_DOCUMENT_NODE:
765 case XML_ELEMENT_NODE:
766 case XML_CDATA_SECTION_NODE:
768 case XML_COMMENT_NODE:
770 case XML_ATTRIBUTE_NODE:
782 * xsltTestCompMatchList:
783 * @ctxt: a XSLT process context
785 * @comp: the precompiled pattern list
787 * Test wether the node matches one of the patterns in the list
789 * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure
792 xsltTestCompMatchList(xsltTransformContextPtr ctxt, xmlNodePtr node,
793 xsltCompMatchPtr comp) {
796 if ((ctxt == NULL) || (node == NULL))
798 while (comp != NULL) {
799 ret = xsltTestCompMatch(ctxt, comp, node, NULL, NULL);
807 /************************************************************************
809 * Dedicated parser for templates *
811 ************************************************************************/
813 #define CUR (*ctxt->cur)
814 #define SKIP(val) ctxt->cur += (val)
815 #define NXT(val) ctxt->cur[(val)]
816 #define CUR_PTR ctxt->cur
818 #define SKIP_BLANKS \
819 while (IS_BLANK(CUR)) NEXT
821 #define CURRENT (*ctxt->cur)
822 #define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
825 #define PUSH(op, val, val2) \
826 if (xsltCompMatchAdd(ctxt->comp, (op), (val), (val2))) goto error;
829 xsltSwapTopCompMatch(ctxt->comp);
831 #define XSLT_ERROR(X) \
832 { xsltError(ctxt, __FILE__, __LINE__, X); \
833 ctxt->error = (X); return; }
835 #define XSLT_ERROR0(X) \
836 { xsltError(ctxt, __FILE__, __LINE__, X); \
837 ctxt->error = (X); return(0); }
841 * @ctxt: the XPath Parser context
843 * Parse an XPath Litteral:
845 * [29] Literal ::= '"' [^"]* '"'
848 * Returns the Literal parsed or NULL
852 xsltScanLiteral(xsltParserContextPtr ctxt) {
860 while ((IS_CHAR(CUR)) && (CUR != '"'))
863 /* XP_ERROR(XPATH_UNFINISHED_LITERAL_ERROR); */
867 ret = xmlStrndup(q, CUR_PTR - q);
870 } else if (CUR == '\'') {
873 while ((IS_CHAR(CUR)) && (CUR != '\''))
876 /* XP_ERROR(XPATH_UNFINISHED_LITERAL_ERROR); */
880 ret = xmlStrndup(q, CUR_PTR - q);
884 /* XP_ERROR(XPATH_START_LITERAL_ERROR); */
893 * @ctxt: the XPath Parser context
895 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' |
896 * CombiningChar | Extender
898 * [5] Name ::= (Letter | '_' | ':') (NameChar)*
900 * [6] Names ::= Name (S Name)*
902 * Returns the Name parsed or NULL
906 xsltScanName(xsltParserContextPtr ctxt) {
907 xmlChar buf[XML_MAX_NAMELEN];
911 if (!IS_LETTER(CUR) && (CUR != '_') &&
916 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
917 (NXT(len) == '.') || (NXT(len) == '-') ||
919 (IS_COMBINING(NXT(len))) ||
920 (IS_EXTENDER(NXT(len)))) {
923 if (len >= XML_MAX_NAMELEN) {
924 xmlGenericError(xmlGenericErrorContext,
925 "xsltScanName: reached XML_MAX_NAMELEN limit\n");
926 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
927 (NXT(len) == '.') || (NXT(len) == '-') ||
928 (NXT(len) == '_') || (NXT(len) == ':') ||
929 (IS_COMBINING(NXT(len))) ||
930 (IS_EXTENDER(NXT(len))))
936 return(xmlStrndup(buf, len));
941 * @ctxt: the XPath Parser context
943 * Parses a non qualified name
945 * Returns the Name parsed or NULL
949 xsltScanNCName(xsltParserContextPtr ctxt) {
950 xmlChar buf[XML_MAX_NAMELEN];
954 if (!IS_LETTER(CUR) && (CUR != '_')) {
958 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
959 (NXT(len) == '.') || (NXT(len) == '-') ||
961 (IS_COMBINING(NXT(len))) ||
962 (IS_EXTENDER(NXT(len)))) {
965 if (len >= XML_MAX_NAMELEN) {
966 xmlGenericError(xmlGenericErrorContext,
967 "xsltScanNCName: reached XML_MAX_NAMELEN limit\n");
968 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
969 (NXT(len) == '.') || (NXT(len) == '-') ||
971 (IS_COMBINING(NXT(len))) ||
972 (IS_EXTENDER(NXT(len))))
978 return(xmlStrndup(buf, len));
983 * @ctxt: the XPath Parser context
984 * @prefix: the place to store the prefix
986 * Parse a qualified name
988 * Returns the Name parsed or NULL
992 xsltScanQName(xsltParserContextPtr ctxt, xmlChar **prefix) {
996 ret = xsltScanNCName(ctxt);
1000 ret = xsltScanNCName(ctxt);
1006 * xsltCompileIdKeyPattern:
1007 * @ctxt: the compilation context
1008 * @name: a preparsed name
1009 * @aid: whether id/key are allowed there
1011 * Compile the XSLT LocationIdKeyPattern
1012 * [3] IdKeyPattern ::= 'id' '(' Literal ')'
1013 * | 'key' '(' Literal ',' Literal ')'
1015 * also handle NodeType and PI from:
1017 * [7] NodeTest ::= NameTest
1018 * | NodeType '(' ')'
1019 * | 'processing-instruction' '(' Literal ')'
1022 xsltCompileIdKeyPattern(xsltParserContextPtr ctxt, xmlChar *name, int aid) {
1023 xmlChar *lit = NULL;
1024 xmlChar *lit2 = NULL;
1027 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1028 xsltGenericError(xsltGenericErrorContext,
1029 "xsltCompileIdKeyPattern : ( expected\n");
1033 if ((aid) && (xmlStrEqual(name, (const xmlChar *)"id"))) {
1036 lit = xsltScanLiteral(ctxt);
1041 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1042 xsltGenericError(xsltGenericErrorContext,
1043 "xsltCompileIdKeyPattern : ) expected\n");
1048 PUSH(XSLT_OP_ID, lit, NULL);
1049 } else if ((aid) && (xmlStrEqual(name, (const xmlChar *)"key"))) {
1052 lit = xsltScanLiteral(ctxt);
1057 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1058 xsltGenericError(xsltGenericErrorContext,
1059 "xsltCompileIdKeyPattern : , expected\n");
1065 lit2 = xsltScanLiteral(ctxt);
1070 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1071 xsltGenericError(xsltGenericErrorContext,
1072 "xsltCompileIdKeyPattern : ) expected\n");
1077 /* TODO: support namespace in keys */
1078 PUSH(XSLT_OP_KEY, lit, lit2);
1079 } else if (xmlStrEqual(name, (const xmlChar *)"processing-instruction")) {
1083 lit = xsltScanLiteral(ctxt);
1088 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1089 xsltGenericError(xsltGenericErrorContext,
1090 "xsltCompileIdKeyPattern : ) expected\n");
1096 PUSH(XSLT_OP_PI, lit, NULL);
1097 } else if (xmlStrEqual(name, (const xmlChar *)"text")) {
1101 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1102 xsltGenericError(xsltGenericErrorContext,
1103 "xsltCompileIdKeyPattern : ) expected\n");
1108 PUSH(XSLT_OP_TEXT, NULL, NULL);
1109 } else if (xmlStrEqual(name, (const xmlChar *)"comment")) {
1113 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1114 xsltGenericError(xsltGenericErrorContext,
1115 "xsltCompileIdKeyPattern : ) expected\n");
1120 PUSH(XSLT_OP_COMMENT, NULL, NULL);
1121 } else if (xmlStrEqual(name, (const xmlChar *)"node")) {
1125 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1126 xsltGenericError(xsltGenericErrorContext,
1127 "xsltCompileIdKeyPattern : ) expected\n");
1132 PUSH(XSLT_OP_NODE, NULL, NULL);
1134 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1135 xsltGenericError(xsltGenericErrorContext,
1136 "xsltCompileIdKeyPattern : expecting 'key' or 'id' or node type\n");
1140 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1141 xsltGenericError(xsltGenericErrorContext,
1142 "xsltCompileIdKeyPattern : node type\n");
1152 * xsltCompileStepPattern:
1153 * @ctxt: the compilation context
1154 * @token: a posible precompiled name
1156 * Compile the XSLT StepPattern and generates a precompiled
1157 * form suitable for fast matching.
1159 * [5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate*
1160 * [6] ChildOrAttributeAxisSpecifier ::= AbbreviatedAxisSpecifier
1161 * | ('child' | 'attribute') '::'
1163 * [7] NodeTest ::= NameTest
1164 * | NodeType '(' ')'
1165 * | 'processing-instruction' '(' Literal ')'
1166 * [8] Predicate ::= '[' PredicateExpr ']'
1167 * [9] PredicateExpr ::= Expr
1168 * [13] AbbreviatedAxisSpecifier ::= '@'?
1169 * [37] NameTest ::= '*' | NCName ':' '*' | QName
1173 xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) {
1174 xmlChar *name = NULL;
1175 const xmlChar *URI = NULL;
1176 xmlChar *URL = NULL;
1180 if ((token == NULL) && (CUR == '@')) {
1181 xmlChar *prefix = NULL;
1186 PUSH(XSLT_OP_ATTR, NULL, NULL);
1189 token = xsltScanQName(ctxt, &prefix);
1190 if (prefix != NULL) {
1193 ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
1195 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1196 xsltGenericError(xsltGenericErrorContext,
1197 "xsltCompileStepPattern : no namespace bound to prefix %s\n",
1200 URL = xmlStrdup(ns->href);
1204 if (token == NULL) {
1207 PUSH(XSLT_OP_ATTR, NULL, URL);
1210 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1211 xsltGenericError(xsltGenericErrorContext,
1212 "xsltCompileStepPattern : Name expected\n");
1216 PUSH(XSLT_OP_ATTR, token, URL);
1220 token = xsltScanName(ctxt);
1221 if (token == NULL) {
1224 PUSH(XSLT_OP_ALL, token, NULL);
1225 goto parse_predicate;
1227 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1228 xsltGenericError(xsltGenericErrorContext,
1229 "xsltCompileStepPattern : Name expected\n");
1238 xsltCompileIdKeyPattern(ctxt, token, 0);
1241 } else if (CUR == ':') {
1244 xmlChar *prefix = token;
1248 * This is a namespace match
1250 token = xsltScanName(ctxt);
1251 ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
1253 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1254 xsltGenericError(xsltGenericErrorContext,
1255 "xsltCompileStepPattern : no namespace bound to prefix %s\n",
1260 URL = xmlStrdup(ns->href);
1263 if (token == NULL) {
1266 PUSH(XSLT_OP_NS, URL, NULL);
1268 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1269 xsltGenericError(xsltGenericErrorContext,
1270 "xsltCompileStepPattern : Name expected\n");
1275 PUSH(XSLT_OP_ELEM, token, URL);
1279 if (xmlStrEqual(token, (const xmlChar *) "child")) {
1281 token = xsltScanName(ctxt);
1282 if (token == NULL) {
1283 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1284 xsltGenericError(xsltGenericErrorContext,
1285 "xsltCompileStepPattern : QName expected\n");
1289 URI = xsltGetQNameURI(ctxt->elem, &token);
1290 if (token == NULL) {
1294 name = xmlStrdup(token);
1296 URL = xmlStrdup(URI);
1298 PUSH(XSLT_OP_CHILD, name, URL);
1299 } else if (xmlStrEqual(token, (const xmlChar *) "attribute")) {
1301 token = xsltScanName(ctxt);
1302 if (token == NULL) {
1303 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1304 xsltGenericError(xsltGenericErrorContext,
1305 "xsltCompileStepPattern : QName expected\n");
1309 URI = xsltGetQNameURI(ctxt->elem, &token);
1310 if (token == NULL) {
1314 name = xmlStrdup(token);
1316 URL = xmlStrdup(URI);
1318 PUSH(XSLT_OP_ATTR, name, URL);
1320 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1321 xsltGenericError(xsltGenericErrorContext,
1322 "xsltCompileStepPattern : 'child' or 'attribute' expected\n");
1328 } else if (CUR == '*') {
1330 PUSH(XSLT_OP_ALL, token, NULL);
1332 URI = xsltGetQNameURI(ctxt->elem, &token);
1333 if (token == NULL) {
1338 URL = xmlStrdup(URI);
1339 PUSH(XSLT_OP_ELEM, token, URL);
1344 while (CUR == '[') {
1346 xmlChar *ret = NULL;
1351 /* TODO: avoid breaking in strings ... */
1352 while (IS_CHAR(CUR)) {
1353 /* Skip over nested predicates */
1363 if (!IS_CHAR(CUR)) {
1364 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1365 xsltGenericError(xsltGenericErrorContext,
1366 "xsltCompileStepPattern : ']' expected\n");
1370 ret = xmlStrndup(q, CUR_PTR - q);
1371 PUSH(XSLT_OP_PREDICATE, ret, NULL);
1372 /* push the predicate lower than local test */
1385 * xsltCompileRelativePathPattern:
1386 * @comp: the compilation context
1387 * @token: a posible precompiled name
1389 * Compile the XSLT RelativePathPattern and generates a precompiled
1390 * form suitable for fast matching.
1392 * [4] RelativePathPattern ::= StepPattern
1393 * | RelativePathPattern '/' StepPattern
1394 * | RelativePathPattern '//' StepPattern
1397 xsltCompileRelativePathPattern(xsltParserContextPtr ctxt, xmlChar *token) {
1398 xsltCompileStepPattern(ctxt, token);
1402 while ((CUR != 0) && (CUR != '|')) {
1403 if ((CUR == '/') && (NXT(1) == '/')) {
1404 PUSH(XSLT_OP_ANCESTOR, NULL, NULL);
1408 xsltCompileStepPattern(ctxt, NULL);
1409 } else if (CUR == '/') {
1410 PUSH(XSLT_OP_PARENT, NULL, NULL);
1413 if ((CUR != 0) || (CUR == '|')) {
1414 xsltCompileRelativePathPattern(ctxt, NULL);
1428 * xsltCompileLocationPathPattern:
1429 * @ctxt: the compilation context
1431 * Compile the XSLT LocationPathPattern and generates a precompiled
1432 * form suitable for fast matching.
1434 * [2] LocationPathPattern ::= '/' RelativePathPattern?
1435 * | IdKeyPattern (('/' | '//') RelativePathPattern)?
1436 * | '//'? RelativePathPattern
1439 xsltCompileLocationPathPattern(xsltParserContextPtr ctxt) {
1441 if ((CUR == '/') && (NXT(1) == '/')) {
1443 * since we reverse the query
1444 * a leading // can be safely ignored
1448 xsltCompileRelativePathPattern(ctxt, NULL);
1449 } else if (CUR == '/') {
1451 * We need to find root as the parent
1455 PUSH(XSLT_OP_ROOT, NULL, NULL);
1456 if ((CUR != 0) || (CUR == '|')) {
1457 PUSH(XSLT_OP_PARENT, NULL, NULL);
1458 xsltCompileRelativePathPattern(ctxt, NULL);
1460 } else if (CUR == '*') {
1461 xsltCompileRelativePathPattern(ctxt, NULL);
1462 } else if (CUR == '@') {
1463 xsltCompileRelativePathPattern(ctxt, NULL);
1466 name = xsltScanName(ctxt);
1468 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1469 xsltGenericError(xsltGenericErrorContext,
1470 "xsltCompileLocationPathPattern : Name expected\n");
1475 if ((CUR == '(') && !xmlXPathIsNodeType(name)) {
1476 xsltCompileIdKeyPattern(ctxt, name, 1);
1477 if ((CUR == '/') && (NXT(1) == '/')) {
1478 PUSH(XSLT_OP_ANCESTOR, NULL, NULL);
1482 xsltCompileRelativePathPattern(ctxt, NULL);
1483 } else if (CUR == '/') {
1484 PUSH(XSLT_OP_PARENT, NULL, NULL);
1487 xsltCompileRelativePathPattern(ctxt, NULL);
1491 xsltCompileRelativePathPattern(ctxt, name);
1498 * xsltCompilePattern:
1499 * @pattern: an XSLT pattern
1500 * @doc: the containing document
1501 * @node: the containing element
1503 * Compile the XSLT pattern and generates a list of precompiled form suitable
1504 * for fast matching.
1506 * [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern
1508 * Returns the generated pattern list or NULL in case of failure
1512 xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
1513 xsltParserContextPtr ctxt = NULL;
1514 xsltCompMatchPtr element, first = NULL, previous = NULL;
1515 int current, start, end;
1517 if (pattern == NULL) {
1518 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1519 xsltGenericError(xsltGenericErrorContext,
1520 "xsltCompilePattern : NULL pattern\n");
1524 ctxt = xsltNewParserContext();
1530 while (pattern[current] != 0) {
1532 while (IS_BLANK(pattern[current]))
1535 while ((pattern[end] != 0) && (pattern[end] != '|'))
1537 if (current == end) {
1538 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1539 xsltGenericError(xsltGenericErrorContext,
1540 "xsltCompilePattern : NULL pattern\n");
1543 element = xsltNewCompMatch();
1544 if (element == NULL) {
1549 else if (previous != NULL)
1550 previous->next = element;
1553 ctxt->comp = element;
1554 ctxt->base = xmlStrndup(&pattern[start], end - start);
1555 if (ctxt->base == NULL)
1557 ctxt->cur = &(ctxt->base)[current - start];
1558 element->pattern = ctxt->base;
1560 #ifdef WITH_XSLT_DEBUG_PATTERN
1561 xsltGenericDebug(xsltGenericDebugContext,
1562 "xsltCompilePattern : parsing '%s'\n",
1565 xsltCompileLocationPathPattern(ctxt);
1570 * Reverse for faster interpretation.
1572 xsltReverseCompMatch(element);
1575 * Set-up the priority
1577 if (((element->steps[0].op == XSLT_OP_ELEM) ||
1578 (element->steps[0].op == XSLT_OP_ATTR)) &&
1579 (element->steps[0].value != NULL) &&
1580 (element->steps[1].op == XSLT_OP_END)) {
1581 element->priority = 0;
1583 } else if ((element->steps[0].op == XSLT_OP_ROOT) &&
1584 (element->steps[1].op == XSLT_OP_END)) {
1585 element->priority = 0;
1587 } else if ((element->steps[0].op == XSLT_OP_PI) &&
1588 (element->steps[0].value != NULL) &&
1589 (element->steps[1].op == XSLT_OP_END)) {
1590 element->priority = 0;
1591 } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
1592 (element->steps[0].value2 != NULL) &&
1593 (element->steps[1].op == XSLT_OP_END)) {
1594 element->priority = -0.25;
1595 } else if ((element->steps[0].op == XSLT_OP_NS) &&
1596 (element->steps[0].value != NULL) &&
1597 (element->steps[1].op == XSLT_OP_END)) {
1598 element->priority = -0.25;
1599 } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
1600 (element->steps[0].value == NULL) &&
1601 (element->steps[0].value2 == NULL) &&
1602 (element->steps[1].op == XSLT_OP_END)) {
1603 element->priority = -0.5;
1604 } else if (((element->steps[0].op == XSLT_OP_PI) ||
1605 (element->steps[0].op == XSLT_OP_TEXT) ||
1606 (element->steps[0].op == XSLT_OP_ALL) ||
1607 (element->steps[0].op == XSLT_OP_NODE) ||
1608 (element->steps[0].op == XSLT_OP_COMMENT)) &&
1609 (element->steps[1].op == XSLT_OP_END)) {
1610 element->priority = -0.5;
1612 element->priority = 0.5;
1614 #ifdef WITH_XSLT_DEBUG_PATTERN
1615 xsltGenericDebug(xsltGenericDebugContext,
1616 "xsltCompilePattern : parsed %s, default priority %f\n",
1617 element->pattern, element->priority);
1619 if (pattern[end] == '|')
1624 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1625 xsltGenericError(xsltGenericErrorContext,
1626 "xsltCompilePattern : NULL pattern\n");
1630 xsltFreeParserContext(ctxt);
1635 xsltFreeParserContext(ctxt);
1637 xsltFreeCompMatchList(first);
1641 /************************************************************************
1643 * Module interfaces *
1645 ************************************************************************/
1649 * @style: an XSLT stylesheet
1650 * @cur: an XSLT template
1651 * @mode: the mode name or NULL
1652 * @modeURI: the mode URI or NULL
1654 * Register the XSLT pattern associated to @cur
1656 * Returns -1 in case of error, 0 otherwise
1659 xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
1660 const xmlChar *mode, const xmlChar *modeURI) {
1661 xsltCompMatchPtr pat, list, *top = NULL, next;
1662 const xmlChar *name = NULL;
1663 float priority; /* the priority */
1665 if ((style == NULL) || (cur == NULL) || (cur->match == NULL))
1668 priority = cur->priority;
1669 pat = xsltCompilePattern(cur->match, style->doc, cur->elem);
1675 pat->template = cur;
1677 pat->mode = xmlStrdup(mode);
1678 if (modeURI != NULL)
1679 pat->modeURI = xmlStrdup(modeURI);
1680 if (priority != XSLT_PAT_NO_PRIORITY)
1681 pat->priority = priority;
1684 * insert it in the hash table list corresponding to its lookup name
1686 switch (pat->steps[0].op) {
1688 if (pat->steps[0].value != NULL)
1689 name = pat->steps[0].value;
1691 top = (xsltCompMatchPtr *) &(style->attrMatch);
1695 case XSLT_OP_PARENT:
1696 case XSLT_OP_ANCESTOR:
1697 top = (xsltCompMatchPtr *) &(style->elemMatch);
1700 top = (xsltCompMatchPtr *) &(style->rootMatch);
1703 top = (xsltCompMatchPtr *) &(style->keyMatch);
1706 /* TODO optimize ID !!! */
1709 top = (xsltCompMatchPtr *) &(style->elemMatch);
1712 case XSLT_OP_PREDICATE:
1713 xsltPrintErrorContext(NULL, style, NULL);
1714 xsltGenericError(xsltGenericErrorContext,
1715 "xsltAddTemplate: invalid compiled pattern\n");
1716 xsltFreeCompMatch(pat);
1719 * TODO: some flags at the top level about type based patterns
1720 * would be faster than inclusion in the hash table.
1723 if (pat->steps[0].value != NULL)
1724 name = pat->steps[0].value;
1726 top = (xsltCompMatchPtr *) &(style->piMatch);
1728 case XSLT_OP_COMMENT:
1729 top = (xsltCompMatchPtr *) &(style->commentMatch);
1732 top = (xsltCompMatchPtr *) &(style->textMatch);
1735 if (pat->steps[0].value != NULL)
1736 name = pat->steps[0].value;
1738 top = (xsltCompMatchPtr *) &(style->elemMatch);
1743 if (style->templatesHash == NULL) {
1744 style->templatesHash = xmlHashCreate(1024);
1745 if (style->templatesHash == NULL) {
1746 xsltFreeCompMatch(pat);
1749 xmlHashAddEntry3(style->templatesHash, name, mode, modeURI, pat);
1751 list = (xsltCompMatchPtr) xmlHashLookup3(style->templatesHash,
1752 name, mode, modeURI);
1754 xmlHashAddEntry3(style->templatesHash, name,
1755 mode, modeURI, pat);
1758 * Note '<=' since one must choose among the matching
1759 * template rules that are left, the one that occurs
1760 * last in the stylesheet
1762 if (list->priority <= pat->priority) {
1764 xmlHashUpdateEntry3(style->templatesHash, name,
1765 mode, modeURI, pat, NULL);
1767 while (list->next != NULL) {
1768 if (list->next->priority <= pat->priority)
1772 pat->next = list->next;
1777 } else if (top != NULL) {
1782 } else if (list->priority <= pat->priority) {
1786 while (list->next != NULL) {
1787 if (list->next->priority <= pat->priority)
1791 pat->next = list->next;
1795 xsltPrintErrorContext(NULL, style, NULL);
1796 xsltGenericError(xsltGenericErrorContext,
1797 "xsltAddTemplate: invalid compiled pattern\n");
1798 xsltFreeCompMatch(pat);
1801 #ifdef WITH_XSLT_DEBUG_PATTERN
1803 xsltGenericDebug(xsltGenericDebugContext,
1804 "added pattern : '%s' mode '%s' priority %f\n",
1805 pat->pattern, pat->mode, pat->priority);
1807 xsltGenericDebug(xsltGenericDebugContext,
1808 "added pattern : '%s' priority %f\n",
1809 pat->pattern, pat->priority);
1819 * @ctxt: a XSLT process context
1820 * @node: the node being processed
1821 * @style: the current style
1823 * Finds the template applying to this node, if @style is non-NULL
1824 * it means one needs to look for the next imported template in scope.
1826 * Returns the xsltTemplatePtr or NULL if not found
1829 xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
1830 xsltStylesheetPtr style) {
1831 xsltStylesheetPtr curstyle;
1832 xsltTemplatePtr ret = NULL;
1833 const xmlChar *name = NULL;
1834 xsltCompMatchPtr list = NULL;
1837 if ((ctxt == NULL) || (node == NULL))
1840 if (style == NULL) {
1841 curstyle = ctxt->style;
1843 curstyle = xsltNextImport(style);
1846 while ((curstyle != NULL) && (curstyle != style)) {
1847 priority = XSLT_PAT_NO_PRIORITY;
1848 /* TODO : handle IDs/keys here ! */
1849 if (curstyle->templatesHash != NULL) {
1851 * Use the top name as selector
1853 switch (node->type) {
1854 case XML_ELEMENT_NODE:
1855 case XML_ATTRIBUTE_NODE:
1859 case XML_DOCUMENT_NODE:
1860 case XML_HTML_DOCUMENT_NODE:
1862 case XML_CDATA_SECTION_NODE:
1863 case XML_COMMENT_NODE:
1864 case XML_ENTITY_REF_NODE:
1865 case XML_ENTITY_NODE:
1866 case XML_DOCUMENT_TYPE_NODE:
1867 case XML_DOCUMENT_FRAG_NODE:
1868 case XML_NOTATION_NODE:
1870 case XML_ELEMENT_DECL:
1871 case XML_ATTRIBUTE_DECL:
1872 case XML_ENTITY_DECL:
1873 case XML_NAMESPACE_DECL:
1874 case XML_XINCLUDE_START:
1875 case XML_XINCLUDE_END:
1884 * find the list of appliable expressions based on the name
1886 list = (xsltCompMatchPtr) xmlHashLookup3(curstyle->templatesHash,
1887 name, ctxt->mode, ctxt->modeURI);
1890 while (list != NULL) {
1891 if (xsltTestCompMatch(ctxt, list, node,
1892 ctxt->mode, ctxt->modeURI)) {
1893 ret = list->template;
1894 priority = list->priority;
1902 * find alternate generic matches
1904 switch (node->type) {
1905 case XML_ELEMENT_NODE:
1906 list = curstyle->elemMatch;
1908 case XML_ATTRIBUTE_NODE:
1909 list = curstyle->attrMatch;
1912 list = curstyle->piMatch;
1914 case XML_DOCUMENT_NODE:
1915 case XML_HTML_DOCUMENT_NODE:
1916 list = curstyle->rootMatch;
1919 case XML_CDATA_SECTION_NODE:
1920 list = curstyle->textMatch;
1922 case XML_COMMENT_NODE:
1923 list = curstyle->commentMatch;
1925 case XML_ENTITY_REF_NODE:
1926 case XML_ENTITY_NODE:
1927 case XML_DOCUMENT_TYPE_NODE:
1928 case XML_DOCUMENT_FRAG_NODE:
1929 case XML_NOTATION_NODE:
1931 case XML_ELEMENT_DECL:
1932 case XML_ATTRIBUTE_DECL:
1933 case XML_ENTITY_DECL:
1934 case XML_NAMESPACE_DECL:
1935 case XML_XINCLUDE_START:
1936 case XML_XINCLUDE_END:
1942 while ((list != NULL) &&
1943 ((ret == NULL) || (list->priority > priority))) {
1944 if (xsltTestCompMatch(ctxt, list, node,
1945 ctxt->mode, ctxt->modeURI)) {
1946 ret = list->template;
1947 priority = list->priority;
1953 * Some of the tests for elements can also apply to documents
1955 if ((node->type == XML_DOCUMENT_NODE) ||
1956 (node->type == XML_HTML_DOCUMENT_NODE)) {
1957 list = curstyle->elemMatch;
1958 while ((list != NULL) &&
1959 ((ret == NULL) || (list->priority > priority))) {
1960 if (xsltTestCompMatch(ctxt, list, node,
1961 ctxt->mode, ctxt->modeURI)) {
1962 ret = list->template;
1963 priority = list->priority;
1970 if (node->_private != NULL) {
1971 list = curstyle->keyMatch;
1972 while ((list != NULL) &&
1973 ((ret == NULL) || (list->priority > priority))) {
1974 if (xsltTestCompMatch(ctxt, list, node,
1975 ctxt->mode, ctxt->modeURI)) {
1976 ret = list->template;
1977 priority = list->priority;
1987 * Cycle on next curstylesheet import.
1989 curstyle = xsltNextImport(curstyle);
1995 * xsltCleanupTemplates:
1996 * @style: an XSLT stylesheet
1998 * Cleanup the state of the templates used by the stylesheet and
1999 * the ones it imports.
2002 xsltCleanupTemplates(xsltStylesheetPtr style) {
2003 while (style != NULL) {
2004 xmlHashScan((xmlHashTablePtr) style->templatesHash,
2005 (xmlHashScanner) xsltCleanupCompMatch, NULL);
2007 style = xsltNextImport(style);
2012 * xsltFreeTemplateHashes:
2013 * @style: an XSLT stylesheet
2015 * Free up the memory used by xsltAddTemplate/xsltGetTemplate mechanism
2018 xsltFreeTemplateHashes(xsltStylesheetPtr style) {
2019 if (style->templatesHash != NULL)
2020 xmlHashFree((xmlHashTablePtr) style->templatesHash,
2021 (xmlHashDeallocator) xsltFreeCompMatchList);
2022 if (style->rootMatch != NULL)
2023 xsltFreeCompMatchList(style->rootMatch);
2024 if (style->keyMatch != NULL)
2025 xsltFreeCompMatchList(style->keyMatch);
2026 if (style->elemMatch != NULL)
2027 xsltFreeCompMatchList(style->elemMatch);
2028 if (style->attrMatch != NULL)
2029 xsltFreeCompMatchList(style->attrMatch);
2030 if (style->parentMatch != NULL)
2031 xsltFreeCompMatchList(style->parentMatch);
2032 if (style->textMatch != NULL)
2033 xsltFreeCompMatchList(style->textMatch);
2034 if (style->piMatch != NULL)
2035 xsltFreeCompMatchList(style->piMatch);
2036 if (style->commentMatch != NULL)
2037 xsltFreeCompMatchList(style->commentMatch);
2043 * @node: a node in the source tree
2044 * @pattern: an XSLT pattern
2046 * Determine if a node matches a pattern.
2049 xsltMatchPattern(xsltTransformContextPtr context,
2051 const xmlChar *pattern)
2054 xsltCompMatchPtr first, comp;
2056 if ((context != NULL) && (pattern != NULL)) {
2057 first = xsltCompilePattern(pattern);
2058 for (comp = first; comp != NULL; comp = comp->next) {
2059 match = xsltTestCompMatch(context, comp, node, NULL, NULL);
2064 xsltFreeCompMatchList(first);