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 case XML_ELEMENT_NODE:
763 case XML_CDATA_SECTION_NODE:
765 case XML_COMMENT_NODE:
767 case XML_ATTRIBUTE_NODE:
779 * xsltTestCompMatchList:
780 * @ctxt: a XSLT process context
782 * @comp: the precompiled pattern list
784 * Test wether the node matches one of the patterns in the list
786 * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure
789 xsltTestCompMatchList(xsltTransformContextPtr ctxt, xmlNodePtr node,
790 xsltCompMatchPtr comp) {
793 if ((ctxt == NULL) || (node == NULL))
795 while (comp != NULL) {
796 ret = xsltTestCompMatch(ctxt, comp, node, NULL, NULL);
804 /************************************************************************
806 * Dedicated parser for templates *
808 ************************************************************************/
810 #define CUR (*ctxt->cur)
811 #define SKIP(val) ctxt->cur += (val)
812 #define NXT(val) ctxt->cur[(val)]
813 #define CUR_PTR ctxt->cur
815 #define SKIP_BLANKS \
816 while (IS_BLANK(CUR)) NEXT
818 #define CURRENT (*ctxt->cur)
819 #define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
822 #define PUSH(op, val, val2) \
823 if (xsltCompMatchAdd(ctxt->comp, (op), (val), (val2))) goto error;
826 xsltSwapTopCompMatch(ctxt->comp);
828 #define XSLT_ERROR(X) \
829 { xsltError(ctxt, __FILE__, __LINE__, X); \
830 ctxt->error = (X); return; }
832 #define XSLT_ERROR0(X) \
833 { xsltError(ctxt, __FILE__, __LINE__, X); \
834 ctxt->error = (X); return(0); }
838 * @ctxt: the XPath Parser context
840 * Parse an XPath Litteral:
842 * [29] Literal ::= '"' [^"]* '"'
845 * Returns the Literal parsed or NULL
849 xsltScanLiteral(xsltParserContextPtr ctxt) {
857 while ((IS_CHAR(CUR)) && (CUR != '"'))
860 /* XP_ERROR(XPATH_UNFINISHED_LITERAL_ERROR); */
864 ret = xmlStrndup(q, CUR_PTR - q);
867 } else if (CUR == '\'') {
870 while ((IS_CHAR(CUR)) && (CUR != '\''))
873 /* XP_ERROR(XPATH_UNFINISHED_LITERAL_ERROR); */
877 ret = xmlStrndup(q, CUR_PTR - q);
881 /* XP_ERROR(XPATH_START_LITERAL_ERROR); */
890 * @ctxt: the XPath Parser context
892 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' |
893 * CombiningChar | Extender
895 * [5] Name ::= (Letter | '_' | ':') (NameChar)*
897 * [6] Names ::= Name (S Name)*
899 * Returns the Name parsed or NULL
903 xsltScanName(xsltParserContextPtr ctxt) {
904 xmlChar buf[XML_MAX_NAMELEN];
908 if (!IS_LETTER(CUR) && (CUR != '_') &&
913 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
914 (NXT(len) == '.') || (NXT(len) == '-') ||
916 (IS_COMBINING(NXT(len))) ||
917 (IS_EXTENDER(NXT(len)))) {
920 if (len >= XML_MAX_NAMELEN) {
921 xmlGenericError(xmlGenericErrorContext,
922 "xsltScanName: reached XML_MAX_NAMELEN limit\n");
923 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
924 (NXT(len) == '.') || (NXT(len) == '-') ||
925 (NXT(len) == '_') || (NXT(len) == ':') ||
926 (IS_COMBINING(NXT(len))) ||
927 (IS_EXTENDER(NXT(len))))
933 return(xmlStrndup(buf, len));
938 * @ctxt: the XPath Parser context
940 * Parses a non qualified name
942 * Returns the Name parsed or NULL
946 xsltScanNCName(xsltParserContextPtr ctxt) {
947 xmlChar buf[XML_MAX_NAMELEN];
951 if (!IS_LETTER(CUR) && (CUR != '_')) {
955 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
956 (NXT(len) == '.') || (NXT(len) == '-') ||
958 (IS_COMBINING(NXT(len))) ||
959 (IS_EXTENDER(NXT(len)))) {
962 if (len >= XML_MAX_NAMELEN) {
963 xmlGenericError(xmlGenericErrorContext,
964 "xsltScanNCName: reached XML_MAX_NAMELEN limit\n");
965 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
966 (NXT(len) == '.') || (NXT(len) == '-') ||
968 (IS_COMBINING(NXT(len))) ||
969 (IS_EXTENDER(NXT(len))))
975 return(xmlStrndup(buf, len));
980 * @ctxt: the XPath Parser context
981 * @prefix: the place to store the prefix
983 * Parse a qualified name
985 * Returns the Name parsed or NULL
989 xsltScanQName(xsltParserContextPtr ctxt, xmlChar **prefix) {
993 ret = xsltScanNCName(ctxt);
997 ret = xsltScanNCName(ctxt);
1003 * xsltCompileIdKeyPattern:
1004 * @ctxt: the compilation context
1005 * @name: a preparsed name
1006 * @aid: whether id/key are allowed there
1008 * Compile the XSLT LocationIdKeyPattern
1009 * [3] IdKeyPattern ::= 'id' '(' Literal ')'
1010 * | 'key' '(' Literal ',' Literal ')'
1012 * also handle NodeType and PI from:
1014 * [7] NodeTest ::= NameTest
1015 * | NodeType '(' ')'
1016 * | 'processing-instruction' '(' Literal ')'
1019 xsltCompileIdKeyPattern(xsltParserContextPtr ctxt, xmlChar *name, int aid) {
1020 xmlChar *lit = NULL;
1021 xmlChar *lit2 = NULL;
1024 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1025 xsltGenericError(xsltGenericErrorContext,
1026 "xsltCompileIdKeyPattern : ( expected\n");
1030 if ((aid) && (xmlStrEqual(name, (const xmlChar *)"id"))) {
1033 lit = xsltScanLiteral(ctxt);
1038 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1039 xsltGenericError(xsltGenericErrorContext,
1040 "xsltCompileIdKeyPattern : ) expected\n");
1045 PUSH(XSLT_OP_ID, lit, NULL);
1046 } else if ((aid) && (xmlStrEqual(name, (const xmlChar *)"key"))) {
1049 lit = xsltScanLiteral(ctxt);
1054 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1055 xsltGenericError(xsltGenericErrorContext,
1056 "xsltCompileIdKeyPattern : , expected\n");
1062 lit2 = xsltScanLiteral(ctxt);
1067 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1068 xsltGenericError(xsltGenericErrorContext,
1069 "xsltCompileIdKeyPattern : ) expected\n");
1074 /* TODO: support namespace in keys */
1075 PUSH(XSLT_OP_KEY, lit, lit2);
1076 } else if (xmlStrEqual(name, (const xmlChar *)"processing-instruction")) {
1080 lit = xsltScanLiteral(ctxt);
1085 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1086 xsltGenericError(xsltGenericErrorContext,
1087 "xsltCompileIdKeyPattern : ) expected\n");
1093 PUSH(XSLT_OP_PI, lit, NULL);
1094 } else if (xmlStrEqual(name, (const xmlChar *)"text")) {
1098 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1099 xsltGenericError(xsltGenericErrorContext,
1100 "xsltCompileIdKeyPattern : ) expected\n");
1105 PUSH(XSLT_OP_TEXT, NULL, NULL);
1106 } else if (xmlStrEqual(name, (const xmlChar *)"comment")) {
1110 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1111 xsltGenericError(xsltGenericErrorContext,
1112 "xsltCompileIdKeyPattern : ) expected\n");
1117 PUSH(XSLT_OP_COMMENT, NULL, NULL);
1118 } else if (xmlStrEqual(name, (const xmlChar *)"node")) {
1122 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1123 xsltGenericError(xsltGenericErrorContext,
1124 "xsltCompileIdKeyPattern : ) expected\n");
1129 PUSH(XSLT_OP_NODE, NULL, NULL);
1131 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1132 xsltGenericError(xsltGenericErrorContext,
1133 "xsltCompileIdKeyPattern : expecting 'key' or 'id' or node type\n");
1137 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1138 xsltGenericError(xsltGenericErrorContext,
1139 "xsltCompileIdKeyPattern : node type\n");
1149 * xsltCompileStepPattern:
1150 * @ctxt: the compilation context
1151 * @token: a posible precompiled name
1153 * Compile the XSLT StepPattern and generates a precompiled
1154 * form suitable for fast matching.
1156 * [5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate*
1157 * [6] ChildOrAttributeAxisSpecifier ::= AbbreviatedAxisSpecifier
1158 * | ('child' | 'attribute') '::'
1160 * [7] NodeTest ::= NameTest
1161 * | NodeType '(' ')'
1162 * | 'processing-instruction' '(' Literal ')'
1163 * [8] Predicate ::= '[' PredicateExpr ']'
1164 * [9] PredicateExpr ::= Expr
1165 * [13] AbbreviatedAxisSpecifier ::= '@'?
1166 * [37] NameTest ::= '*' | NCName ':' '*' | QName
1170 xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) {
1171 xmlChar *name = NULL;
1172 const xmlChar *URI = NULL;
1173 xmlChar *URL = NULL;
1177 if ((token == NULL) && (CUR == '@')) {
1178 xmlChar *prefix = NULL;
1183 PUSH(XSLT_OP_ATTR, NULL, NULL);
1186 token = xsltScanQName(ctxt, &prefix);
1187 if (prefix != NULL) {
1190 ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
1192 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1193 xsltGenericError(xsltGenericErrorContext,
1194 "xsltCompileStepPattern : no namespace bound to prefix %s\n",
1197 URL = xmlStrdup(ns->href);
1201 if (token == NULL) {
1204 PUSH(XSLT_OP_ATTR, NULL, URL);
1207 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1208 xsltGenericError(xsltGenericErrorContext,
1209 "xsltCompileStepPattern : Name expected\n");
1213 PUSH(XSLT_OP_ATTR, token, URL);
1217 token = xsltScanName(ctxt);
1218 if (token == NULL) {
1221 PUSH(XSLT_OP_ALL, token, NULL);
1222 goto parse_predicate;
1224 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1225 xsltGenericError(xsltGenericErrorContext,
1226 "xsltCompileStepPattern : Name expected\n");
1235 xsltCompileIdKeyPattern(ctxt, token, 0);
1238 } else if (CUR == ':') {
1241 xmlChar *prefix = token;
1245 * This is a namespace match
1247 token = xsltScanName(ctxt);
1248 ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
1250 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1251 xsltGenericError(xsltGenericErrorContext,
1252 "xsltCompileStepPattern : no namespace bound to prefix %s\n",
1257 URL = xmlStrdup(ns->href);
1260 if (token == NULL) {
1263 PUSH(XSLT_OP_NS, URL, NULL);
1265 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1266 xsltGenericError(xsltGenericErrorContext,
1267 "xsltCompileStepPattern : Name expected\n");
1272 PUSH(XSLT_OP_ELEM, token, URL);
1276 if (xmlStrEqual(token, (const xmlChar *) "child")) {
1278 token = xsltScanName(ctxt);
1279 if (token == NULL) {
1280 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1281 xsltGenericError(xsltGenericErrorContext,
1282 "xsltCompileStepPattern : QName expected\n");
1286 URI = xsltGetQNameURI(ctxt->elem, &token);
1287 if (token == NULL) {
1291 name = xmlStrdup(token);
1293 URL = xmlStrdup(URI);
1295 PUSH(XSLT_OP_CHILD, name, URL);
1296 } else if (xmlStrEqual(token, (const xmlChar *) "attribute")) {
1298 token = xsltScanName(ctxt);
1299 if (token == NULL) {
1300 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1301 xsltGenericError(xsltGenericErrorContext,
1302 "xsltCompileStepPattern : QName expected\n");
1306 URI = xsltGetQNameURI(ctxt->elem, &token);
1307 if (token == NULL) {
1311 name = xmlStrdup(token);
1313 URL = xmlStrdup(URI);
1315 PUSH(XSLT_OP_ATTR, name, URL);
1317 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1318 xsltGenericError(xsltGenericErrorContext,
1319 "xsltCompileStepPattern : 'child' or 'attribute' expected\n");
1325 } else if (CUR == '*') {
1327 PUSH(XSLT_OP_ALL, token, NULL);
1329 URI = xsltGetQNameURI(ctxt->elem, &token);
1330 if (token == NULL) {
1335 URL = xmlStrdup(URI);
1336 PUSH(XSLT_OP_ELEM, token, URL);
1341 while (CUR == '[') {
1343 xmlChar *ret = NULL;
1348 /* TODO: avoid breaking in strings ... */
1349 while (IS_CHAR(CUR)) {
1350 /* Skip over nested predicates */
1360 if (!IS_CHAR(CUR)) {
1361 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1362 xsltGenericError(xsltGenericErrorContext,
1363 "xsltCompileStepPattern : ']' expected\n");
1367 ret = xmlStrndup(q, CUR_PTR - q);
1368 PUSH(XSLT_OP_PREDICATE, ret, NULL);
1369 /* push the predicate lower than local test */
1382 * xsltCompileRelativePathPattern:
1383 * @comp: the compilation context
1384 * @token: a posible precompiled name
1386 * Compile the XSLT RelativePathPattern and generates a precompiled
1387 * form suitable for fast matching.
1389 * [4] RelativePathPattern ::= StepPattern
1390 * | RelativePathPattern '/' StepPattern
1391 * | RelativePathPattern '//' StepPattern
1394 xsltCompileRelativePathPattern(xsltParserContextPtr ctxt, xmlChar *token) {
1395 xsltCompileStepPattern(ctxt, token);
1399 while ((CUR != 0) && (CUR != '|')) {
1400 if ((CUR == '/') && (NXT(1) == '/')) {
1401 PUSH(XSLT_OP_ANCESTOR, NULL, NULL);
1405 xsltCompileStepPattern(ctxt, NULL);
1406 } else if (CUR == '/') {
1407 PUSH(XSLT_OP_PARENT, NULL, NULL);
1410 if ((CUR != 0) || (CUR == '|')) {
1411 xsltCompileRelativePathPattern(ctxt, NULL);
1425 * xsltCompileLocationPathPattern:
1426 * @ctxt: the compilation context
1428 * Compile the XSLT LocationPathPattern and generates a precompiled
1429 * form suitable for fast matching.
1431 * [2] LocationPathPattern ::= '/' RelativePathPattern?
1432 * | IdKeyPattern (('/' | '//') RelativePathPattern)?
1433 * | '//'? RelativePathPattern
1436 xsltCompileLocationPathPattern(xsltParserContextPtr ctxt) {
1438 if ((CUR == '/') && (NXT(1) == '/')) {
1440 * since we reverse the query
1441 * a leading // can be safely ignored
1445 xsltCompileRelativePathPattern(ctxt, NULL);
1446 } else if (CUR == '/') {
1448 * We need to find root as the parent
1452 PUSH(XSLT_OP_ROOT, NULL, NULL);
1453 if ((CUR != 0) || (CUR == '|')) {
1454 PUSH(XSLT_OP_PARENT, NULL, NULL);
1455 xsltCompileRelativePathPattern(ctxt, NULL);
1457 } else if (CUR == '*') {
1458 xsltCompileRelativePathPattern(ctxt, NULL);
1459 } else if (CUR == '@') {
1460 xsltCompileRelativePathPattern(ctxt, NULL);
1463 name = xsltScanName(ctxt);
1465 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1466 xsltGenericError(xsltGenericErrorContext,
1467 "xsltCompileLocationPathPattern : Name expected\n");
1472 if ((CUR == '(') && !xmlXPathIsNodeType(name)) {
1473 xsltCompileIdKeyPattern(ctxt, name, 1);
1474 if ((CUR == '/') && (NXT(1) == '/')) {
1475 PUSH(XSLT_OP_ANCESTOR, NULL, NULL);
1479 xsltCompileRelativePathPattern(ctxt, NULL);
1480 } else if (CUR == '/') {
1481 PUSH(XSLT_OP_PARENT, NULL, NULL);
1484 xsltCompileRelativePathPattern(ctxt, NULL);
1488 xsltCompileRelativePathPattern(ctxt, name);
1495 * xsltCompilePattern:
1496 * @pattern: an XSLT pattern
1497 * @doc: the containing document
1498 * @node: the containing element
1500 * Compile the XSLT pattern and generates a list of precompiled form suitable
1501 * for fast matching.
1503 * [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern
1505 * Returns the generated pattern list or NULL in case of failure
1509 xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
1510 xsltParserContextPtr ctxt = NULL;
1511 xsltCompMatchPtr element, first = NULL, previous = NULL;
1512 int current, start, end;
1514 if (pattern == NULL) {
1515 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1516 xsltGenericError(xsltGenericErrorContext,
1517 "xsltCompilePattern : NULL pattern\n");
1521 ctxt = xsltNewParserContext();
1527 while (pattern[current] != 0) {
1529 while (IS_BLANK(pattern[current]))
1532 while ((pattern[end] != 0) && (pattern[end] != '|'))
1534 if (current == end) {
1535 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1536 xsltGenericError(xsltGenericErrorContext,
1537 "xsltCompilePattern : NULL pattern\n");
1540 element = xsltNewCompMatch();
1541 if (element == NULL) {
1546 else if (previous != NULL)
1547 previous->next = element;
1550 ctxt->comp = element;
1551 ctxt->base = xmlStrndup(&pattern[start], end - start);
1552 if (ctxt->base == NULL)
1554 ctxt->cur = &(ctxt->base)[current - start];
1555 element->pattern = ctxt->base;
1557 #ifdef WITH_XSLT_DEBUG_PATTERN
1558 xsltGenericDebug(xsltGenericDebugContext,
1559 "xsltCompilePattern : parsing '%s'\n",
1562 xsltCompileLocationPathPattern(ctxt);
1567 * Reverse for faster interpretation.
1569 xsltReverseCompMatch(element);
1572 * Set-up the priority
1574 if (((element->steps[0].op == XSLT_OP_ELEM) ||
1575 (element->steps[0].op == XSLT_OP_ATTR)) &&
1576 (element->steps[0].value != NULL) &&
1577 (element->steps[1].op == XSLT_OP_END)) {
1578 element->priority = 0;
1580 } else if ((element->steps[0].op == XSLT_OP_ROOT) &&
1581 (element->steps[1].op == XSLT_OP_END)) {
1582 element->priority = 0;
1584 } else if ((element->steps[0].op == XSLT_OP_PI) &&
1585 (element->steps[0].value != NULL) &&
1586 (element->steps[1].op == XSLT_OP_END)) {
1587 element->priority = 0;
1588 } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
1589 (element->steps[0].value2 != NULL) &&
1590 (element->steps[1].op == XSLT_OP_END)) {
1591 element->priority = -0.25;
1592 } else if ((element->steps[0].op == XSLT_OP_NS) &&
1593 (element->steps[0].value != NULL) &&
1594 (element->steps[1].op == XSLT_OP_END)) {
1595 element->priority = -0.25;
1596 } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
1597 (element->steps[0].value == NULL) &&
1598 (element->steps[0].value2 == NULL) &&
1599 (element->steps[1].op == XSLT_OP_END)) {
1600 element->priority = -0.5;
1601 } else if (((element->steps[0].op == XSLT_OP_PI) ||
1602 (element->steps[0].op == XSLT_OP_TEXT) ||
1603 (element->steps[0].op == XSLT_OP_ALL) ||
1604 (element->steps[0].op == XSLT_OP_NODE) ||
1605 (element->steps[0].op == XSLT_OP_COMMENT)) &&
1606 (element->steps[1].op == XSLT_OP_END)) {
1607 element->priority = -0.5;
1609 element->priority = 0.5;
1611 #ifdef WITH_XSLT_DEBUG_PATTERN
1612 xsltGenericDebug(xsltGenericDebugContext,
1613 "xsltCompilePattern : parsed %s, default priority %f\n",
1614 element->pattern, element->priority);
1616 if (pattern[end] == '|')
1621 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1622 xsltGenericError(xsltGenericErrorContext,
1623 "xsltCompilePattern : NULL pattern\n");
1627 xsltFreeParserContext(ctxt);
1632 xsltFreeParserContext(ctxt);
1634 xsltFreeCompMatchList(first);
1638 /************************************************************************
1640 * Module interfaces *
1642 ************************************************************************/
1646 * @style: an XSLT stylesheet
1647 * @cur: an XSLT template
1648 * @mode: the mode name or NULL
1649 * @modeURI: the mode URI or NULL
1651 * Register the XSLT pattern associated to @cur
1653 * Returns -1 in case of error, 0 otherwise
1656 xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
1657 const xmlChar *mode, const xmlChar *modeURI) {
1658 xsltCompMatchPtr pat, list, *top = NULL, next;
1659 const xmlChar *name = NULL;
1660 float priority; /* the priority */
1662 if ((style == NULL) || (cur == NULL) || (cur->match == NULL))
1665 priority = cur->priority;
1666 pat = xsltCompilePattern(cur->match, style->doc, cur->elem);
1672 pat->template = cur;
1674 pat->mode = xmlStrdup(mode);
1675 if (modeURI != NULL)
1676 pat->modeURI = xmlStrdup(modeURI);
1677 if (priority != XSLT_PAT_NO_PRIORITY)
1678 pat->priority = priority;
1681 * insert it in the hash table list corresponding to its lookup name
1683 switch (pat->steps[0].op) {
1685 if (pat->steps[0].value != NULL)
1686 name = pat->steps[0].value;
1688 top = (xsltCompMatchPtr *) &(style->attrMatch);
1692 case XSLT_OP_PARENT:
1693 case XSLT_OP_ANCESTOR:
1694 top = (xsltCompMatchPtr *) &(style->elemMatch);
1697 top = (xsltCompMatchPtr *) &(style->rootMatch);
1700 top = (xsltCompMatchPtr *) &(style->keyMatch);
1703 /* TODO optimize ID !!! */
1706 top = (xsltCompMatchPtr *) &(style->elemMatch);
1709 case XSLT_OP_PREDICATE:
1710 xsltPrintErrorContext(NULL, style, NULL);
1711 xsltGenericError(xsltGenericErrorContext,
1712 "xsltAddTemplate: invalid compiled pattern\n");
1713 xsltFreeCompMatch(pat);
1716 * TODO: some flags at the top level about type based patterns
1717 * would be faster than inclusion in the hash table.
1720 if (pat->steps[0].value != NULL)
1721 name = pat->steps[0].value;
1723 top = (xsltCompMatchPtr *) &(style->piMatch);
1725 case XSLT_OP_COMMENT:
1726 top = (xsltCompMatchPtr *) &(style->commentMatch);
1729 top = (xsltCompMatchPtr *) &(style->textMatch);
1732 if (pat->steps[0].value != NULL)
1733 name = pat->steps[0].value;
1735 top = (xsltCompMatchPtr *) &(style->elemMatch);
1740 if (style->templatesHash == NULL) {
1741 style->templatesHash = xmlHashCreate(1024);
1742 if (style->templatesHash == NULL) {
1743 xsltFreeCompMatch(pat);
1746 xmlHashAddEntry3(style->templatesHash, name, mode, modeURI, pat);
1748 list = (xsltCompMatchPtr) xmlHashLookup3(style->templatesHash,
1749 name, mode, modeURI);
1751 xmlHashAddEntry3(style->templatesHash, name,
1752 mode, modeURI, pat);
1755 * Note '<=' since one must choose among the matching
1756 * template rules that are left, the one that occurs
1757 * last in the stylesheet
1759 if (list->priority <= pat->priority) {
1761 xmlHashUpdateEntry3(style->templatesHash, name,
1762 mode, modeURI, pat, NULL);
1764 while (list->next != NULL) {
1765 if (list->next->priority <= pat->priority)
1769 pat->next = list->next;
1774 } else if (top != NULL) {
1779 } else if (list->priority <= pat->priority) {
1783 while (list->next != NULL) {
1784 if (list->next->priority <= pat->priority)
1788 pat->next = list->next;
1792 xsltPrintErrorContext(NULL, style, NULL);
1793 xsltGenericError(xsltGenericErrorContext,
1794 "xsltAddTemplate: invalid compiled pattern\n");
1795 xsltFreeCompMatch(pat);
1798 #ifdef WITH_XSLT_DEBUG_PATTERN
1800 xsltGenericDebug(xsltGenericDebugContext,
1801 "added pattern : '%s' mode '%s' priority %f\n",
1802 pat->pattern, pat->mode, pat->priority);
1804 xsltGenericDebug(xsltGenericDebugContext,
1805 "added pattern : '%s' priority %f\n",
1806 pat->pattern, pat->priority);
1816 * @ctxt: a XSLT process context
1817 * @node: the node being processed
1818 * @style: the current style
1820 * Finds the template applying to this node, if @style is non-NULL
1821 * it means one needs to look for the next imported template in scope.
1823 * Returns the xsltTemplatePtr or NULL if not found
1826 xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
1827 xsltStylesheetPtr style) {
1828 xsltStylesheetPtr curstyle;
1829 xsltTemplatePtr ret = NULL;
1830 const xmlChar *name = NULL;
1831 xsltCompMatchPtr list = NULL;
1834 if ((ctxt == NULL) || (node == NULL))
1837 if (style == NULL) {
1838 curstyle = ctxt->style;
1840 curstyle = xsltNextImport(style);
1843 while ((curstyle != NULL) && (curstyle != style)) {
1844 priority = XSLT_PAT_NO_PRIORITY;
1845 /* TODO : handle IDs/keys here ! */
1846 if (curstyle->templatesHash != NULL) {
1848 * Use the top name as selector
1850 switch (node->type) {
1851 case XML_ELEMENT_NODE:
1852 case XML_ATTRIBUTE_NODE:
1856 case XML_DOCUMENT_NODE:
1857 case XML_HTML_DOCUMENT_NODE:
1859 case XML_CDATA_SECTION_NODE:
1860 case XML_COMMENT_NODE:
1861 case XML_ENTITY_REF_NODE:
1862 case XML_ENTITY_NODE:
1863 case XML_DOCUMENT_TYPE_NODE:
1864 case XML_DOCUMENT_FRAG_NODE:
1865 case XML_NOTATION_NODE:
1867 case XML_ELEMENT_DECL:
1868 case XML_ATTRIBUTE_DECL:
1869 case XML_ENTITY_DECL:
1870 case XML_NAMESPACE_DECL:
1871 case XML_XINCLUDE_START:
1872 case XML_XINCLUDE_END:
1881 * find the list of appliable expressions based on the name
1883 list = (xsltCompMatchPtr) xmlHashLookup3(curstyle->templatesHash,
1884 name, ctxt->mode, ctxt->modeURI);
1887 while (list != NULL) {
1888 if (xsltTestCompMatch(ctxt, list, node,
1889 ctxt->mode, ctxt->modeURI)) {
1890 ret = list->template;
1891 priority = list->priority;
1899 * find alternate generic matches
1901 switch (node->type) {
1902 case XML_ELEMENT_NODE:
1903 list = curstyle->elemMatch;
1905 case XML_ATTRIBUTE_NODE:
1906 list = curstyle->attrMatch;
1909 list = curstyle->piMatch;
1911 case XML_DOCUMENT_NODE:
1912 case XML_HTML_DOCUMENT_NODE:
1913 list = curstyle->rootMatch;
1916 case XML_CDATA_SECTION_NODE:
1917 list = curstyle->textMatch;
1919 case XML_COMMENT_NODE:
1920 list = curstyle->commentMatch;
1922 case XML_ENTITY_REF_NODE:
1923 case XML_ENTITY_NODE:
1924 case XML_DOCUMENT_TYPE_NODE:
1925 case XML_DOCUMENT_FRAG_NODE:
1926 case XML_NOTATION_NODE:
1928 case XML_ELEMENT_DECL:
1929 case XML_ATTRIBUTE_DECL:
1930 case XML_ENTITY_DECL:
1931 case XML_NAMESPACE_DECL:
1932 case XML_XINCLUDE_START:
1933 case XML_XINCLUDE_END:
1939 while ((list != NULL) &&
1940 ((ret == NULL) || (list->priority > priority))) {
1941 if (xsltTestCompMatch(ctxt, list, node,
1942 ctxt->mode, ctxt->modeURI)) {
1943 ret = list->template;
1949 * Some of the tests for elements can also apply to documents
1951 if ((node->type == XML_DOCUMENT_NODE) ||
1952 (node->type == XML_HTML_DOCUMENT_NODE)) {
1953 list = curstyle->elemMatch;
1954 while ((list != NULL) &&
1955 ((ret == NULL) || (list->priority > priority))) {
1956 if (xsltTestCompMatch(ctxt, list, node,
1957 ctxt->mode, ctxt->modeURI)) {
1958 ret = list->template;
1965 if (node->_private != NULL) {
1966 list = curstyle->keyMatch;
1967 while ((list != NULL) &&
1968 ((ret == NULL) || (list->priority > priority))) {
1969 if (xsltTestCompMatch(ctxt, list, node,
1970 ctxt->mode, ctxt->modeURI)) {
1971 ret = list->template;
1981 * Cycle on next curstylesheet import.
1983 curstyle = xsltNextImport(curstyle);
1989 * xsltCleanupTemplates:
1990 * @style: an XSLT stylesheet
1992 * Cleanup the state of the templates used by the stylesheet and
1993 * the ones it imports.
1996 xsltCleanupTemplates(xsltStylesheetPtr style) {
1997 while (style != NULL) {
1998 xmlHashScan((xmlHashTablePtr) style->templatesHash,
1999 (xmlHashScanner) xsltCleanupCompMatch, NULL);
2001 style = xsltNextImport(style);
2006 * xsltFreeTemplateHashes:
2007 * @style: an XSLT stylesheet
2009 * Free up the memory used by xsltAddTemplate/xsltGetTemplate mechanism
2012 xsltFreeTemplateHashes(xsltStylesheetPtr style) {
2013 if (style->templatesHash != NULL)
2014 xmlHashFree((xmlHashTablePtr) style->templatesHash,
2015 (xmlHashDeallocator) xsltFreeCompMatchList);
2016 if (style->rootMatch != NULL)
2017 xsltFreeCompMatchList(style->rootMatch);
2018 if (style->keyMatch != NULL)
2019 xsltFreeCompMatchList(style->keyMatch);
2020 if (style->elemMatch != NULL)
2021 xsltFreeCompMatchList(style->elemMatch);
2022 if (style->attrMatch != NULL)
2023 xsltFreeCompMatchList(style->attrMatch);
2024 if (style->parentMatch != NULL)
2025 xsltFreeCompMatchList(style->parentMatch);
2026 if (style->textMatch != NULL)
2027 xsltFreeCompMatchList(style->textMatch);
2028 if (style->piMatch != NULL)
2029 xsltFreeCompMatchList(style->piMatch);
2030 if (style->commentMatch != NULL)
2031 xsltFreeCompMatchList(style->commentMatch);
2037 * @node: a node in the source tree
2038 * @pattern: an XSLT pattern
2040 * Determine if a node matches a pattern.
2043 xsltMatchPattern(xsltTransformContextPtr context,
2045 const xmlChar *pattern)
2048 xsltCompMatchPtr first, comp;
2050 if ((context != NULL) && (pattern != NULL)) {
2051 first = xsltCompilePattern(pattern);
2052 for (comp = first; comp != NULL; comp = comp->next) {
2053 match = xsltTestCompMatch(context, comp, node, NULL, NULL);
2058 xsltFreeCompMatchList(first);