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 oldCS = ctxt->xpathCtxt->contextSize;
561 oldCP = ctxt->xpathCtxt->proximityPosition;
562 if ((select != NULL) &&
563 (select->op == XSLT_OP_ELEM) &&
564 (select->value != NULL) &&
565 (node->type == XML_ELEMENT_NODE) &&
566 (node->parent != NULL)) {
568 if ((select->previous != NULL) &&
569 (select->previous->parent == node->parent)) {
571 * just walk back to adjust the index
574 xmlNodePtr sibling = node;
576 while (sibling != NULL) {
577 if (sibling == select->previous)
579 if (xmlStrEqual(node->name, sibling->name)) {
580 if ((select->value2 == NULL) ||
581 ((sibling->ns != NULL) &&
582 (xmlStrEqual(select->value2,
583 sibling->ns->href))))
586 sibling = sibling->prev;
588 if (sibling == NULL) {
589 /* hum going backward in document order ... */
592 while (sibling != NULL) {
593 if (sibling == select->previous)
595 if ((select->value2 == NULL) ||
596 ((sibling->ns != NULL) &&
597 (xmlStrEqual(select->value2,
598 sibling->ns->href))))
600 sibling = sibling->next;
603 if (sibling != NULL) {
604 pos = select->index + indx;
606 select->previous = node;
612 * recompute the index
614 xmlNodePtr siblings = node->parent->children;
616 while (siblings != NULL) {
617 if (siblings->type == XML_ELEMENT_NODE) {
618 if (siblings == node) {
621 } else if (xmlStrEqual(node->name,
623 if ((select->value2 == NULL) ||
624 ((siblings->ns != NULL) &&
625 (xmlStrEqual(select->value2,
626 siblings->ns->href))))
630 siblings = siblings->next;
634 ctxt->xpathCtxt->contextSize = len;
635 ctxt->xpathCtxt->proximityPosition = pos;
636 select->previous = node;
640 } else if ((select != NULL) && (select->op == XSLT_OP_ALL) &&
641 (node->type == XML_ELEMENT_NODE)) {
642 if ((select->previous != NULL) &&
643 (select->previous->parent == node->parent)) {
645 * just walk back to adjust the index
648 xmlNodePtr sibling = node;
650 while (sibling != NULL) {
651 if (sibling == select->previous)
653 if (sibling->type == XML_ELEMENT_NODE)
655 sibling = sibling->prev;
657 if (sibling == NULL) {
658 /* hum going backward in document order ... */
661 while (sibling != NULL) {
662 if (sibling == select->previous)
664 if (sibling->type == XML_ELEMENT_NODE)
666 sibling = sibling->next;
669 if (sibling != NULL) {
670 pos = select->index + indx;
672 select->previous = node;
678 * recompute the index
680 xmlNodePtr siblings = node->parent->children;
682 while (siblings != NULL) {
683 if (siblings->type == XML_ELEMENT_NODE) {
685 if (siblings == node) {
689 siblings = siblings->next;
693 ctxt->xpathCtxt->contextSize = len;
694 ctxt->xpathCtxt->proximityPosition = pos;
695 select->previous = node;
700 oldNode = ctxt->node;
703 if (step->value == NULL)
706 if (step->comp == NULL) {
707 step->comp = xmlXPathCompile(step->value);
708 if (step->comp == NULL)
711 if (comp->nsList == NULL) {
714 comp->nsList = xmlGetNsList(node->doc, node);
715 if (comp->nsList != NULL) {
716 while (comp->nsList[j] != NULL)
721 if (!xsltEvalXPathPredicate(ctxt, step->comp, comp->nsList,
726 ctxt->xpathCtxt->contextSize = oldCS;
727 ctxt->xpathCtxt->proximityPosition = oldCP;
729 ctxt->node = oldNode;
733 ctxt->xpathCtxt->contextSize = oldCS;
734 ctxt->xpathCtxt->proximityPosition = oldCP;
736 ctxt->node = oldNode;
740 if (node->type != XML_PI_NODE)
742 if (step->value != NULL) {
743 if (!xmlStrEqual(step->value, node->name))
747 case XSLT_OP_COMMENT:
748 if (node->type != XML_COMMENT_NODE)
752 if ((node->type != XML_TEXT_NODE) &&
753 (node->type != XML_CDATA_SECTION_NODE))
757 switch (node->type) {
758 case XML_DOCUMENT_NODE:
759 case XML_HTML_DOCUMENT_NODE:
760 case XML_ELEMENT_NODE:
761 case XML_CDATA_SECTION_NODE:
763 case XML_COMMENT_NODE:
765 case XML_ATTRIBUTE_NODE:
777 * xsltTestCompMatchList:
778 * @ctxt: a XSLT process context
780 * @comp: the precompiled pattern list
782 * Test wether the node matches one of the patterns in the list
784 * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure
787 xsltTestCompMatchList(xsltTransformContextPtr ctxt, xmlNodePtr node,
788 xsltCompMatchPtr comp) {
791 if ((ctxt == NULL) || (node == NULL))
793 while (comp != NULL) {
794 ret = xsltTestCompMatch(ctxt, comp, node, NULL, NULL);
802 /************************************************************************
804 * Dedicated parser for templates *
806 ************************************************************************/
808 #define CUR (*ctxt->cur)
809 #define SKIP(val) ctxt->cur += (val)
810 #define NXT(val) ctxt->cur[(val)]
811 #define CUR_PTR ctxt->cur
813 #define SKIP_BLANKS \
814 while (IS_BLANK(CUR)) NEXT
816 #define CURRENT (*ctxt->cur)
817 #define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
820 #define PUSH(op, val, val2) \
821 if (xsltCompMatchAdd(ctxt->comp, (op), (val), (val2))) goto error;
824 xsltSwapTopCompMatch(ctxt->comp);
826 #define XSLT_ERROR(X) \
827 { xsltError(ctxt, __FILE__, __LINE__, X); \
828 ctxt->error = (X); return; }
830 #define XSLT_ERROR0(X) \
831 { xsltError(ctxt, __FILE__, __LINE__, X); \
832 ctxt->error = (X); return(0); }
836 * @ctxt: the XPath Parser context
838 * Parse an XPath Litteral:
840 * [29] Literal ::= '"' [^"]* '"'
843 * Returns the Literal parsed or NULL
847 xsltScanLiteral(xsltParserContextPtr ctxt) {
855 while ((IS_CHAR(CUR)) && (CUR != '"'))
858 /* XP_ERROR(XPATH_UNFINISHED_LITERAL_ERROR); */
862 ret = xmlStrndup(q, CUR_PTR - q);
865 } else if (CUR == '\'') {
868 while ((IS_CHAR(CUR)) && (CUR != '\''))
871 /* XP_ERROR(XPATH_UNFINISHED_LITERAL_ERROR); */
875 ret = xmlStrndup(q, CUR_PTR - q);
879 /* XP_ERROR(XPATH_START_LITERAL_ERROR); */
888 * @ctxt: the XPath Parser context
890 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' |
891 * CombiningChar | Extender
893 * [5] Name ::= (Letter | '_' | ':') (NameChar)*
895 * [6] Names ::= Name (S Name)*
897 * Returns the Name parsed or NULL
901 xsltScanName(xsltParserContextPtr ctxt) {
902 xmlChar buf[XML_MAX_NAMELEN];
906 if (!IS_LETTER(CUR) && (CUR != '_') &&
911 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
912 (NXT(len) == '.') || (NXT(len) == '-') ||
914 (IS_COMBINING(NXT(len))) ||
915 (IS_EXTENDER(NXT(len)))) {
918 if (len >= XML_MAX_NAMELEN) {
919 xmlGenericError(xmlGenericErrorContext,
920 "xsltScanName: reached XML_MAX_NAMELEN limit\n");
921 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
922 (NXT(len) == '.') || (NXT(len) == '-') ||
923 (NXT(len) == '_') || (NXT(len) == ':') ||
924 (IS_COMBINING(NXT(len))) ||
925 (IS_EXTENDER(NXT(len))))
931 return(xmlStrndup(buf, len));
936 * @ctxt: the XPath Parser context
938 * Parses a non qualified name
940 * Returns the Name parsed or NULL
944 xsltScanNCName(xsltParserContextPtr ctxt) {
945 xmlChar buf[XML_MAX_NAMELEN];
949 if (!IS_LETTER(CUR) && (CUR != '_')) {
953 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
954 (NXT(len) == '.') || (NXT(len) == '-') ||
956 (IS_COMBINING(NXT(len))) ||
957 (IS_EXTENDER(NXT(len)))) {
960 if (len >= XML_MAX_NAMELEN) {
961 xmlGenericError(xmlGenericErrorContext,
962 "xsltScanNCName: reached XML_MAX_NAMELEN limit\n");
963 while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
964 (NXT(len) == '.') || (NXT(len) == '-') ||
966 (IS_COMBINING(NXT(len))) ||
967 (IS_EXTENDER(NXT(len))))
973 return(xmlStrndup(buf, len));
978 * @ctxt: the XPath Parser context
979 * @prefix: the place to store the prefix
981 * Parse a qualified name
983 * Returns the Name parsed or NULL
987 xsltScanQName(xsltParserContextPtr ctxt, xmlChar **prefix) {
991 ret = xsltScanNCName(ctxt);
995 ret = xsltScanNCName(ctxt);
1001 * xsltCompileIdKeyPattern:
1002 * @ctxt: the compilation context
1003 * @name: a preparsed name
1004 * @aid: whether id/key are allowed there
1006 * Compile the XSLT LocationIdKeyPattern
1007 * [3] IdKeyPattern ::= 'id' '(' Literal ')'
1008 * | 'key' '(' Literal ',' Literal ')'
1010 * also handle NodeType and PI from:
1012 * [7] NodeTest ::= NameTest
1013 * | NodeType '(' ')'
1014 * | 'processing-instruction' '(' Literal ')'
1017 xsltCompileIdKeyPattern(xsltParserContextPtr ctxt, xmlChar *name, int aid) {
1018 xmlChar *lit = NULL;
1019 xmlChar *lit2 = NULL;
1022 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1023 xsltGenericError(xsltGenericErrorContext,
1024 "xsltCompileIdKeyPattern : ( expected\n");
1028 if ((aid) && (xmlStrEqual(name, (const xmlChar *)"id"))) {
1031 lit = xsltScanLiteral(ctxt);
1036 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1037 xsltGenericError(xsltGenericErrorContext,
1038 "xsltCompileIdKeyPattern : ) expected\n");
1043 PUSH(XSLT_OP_ID, lit, NULL);
1044 } else if ((aid) && (xmlStrEqual(name, (const xmlChar *)"key"))) {
1047 lit = xsltScanLiteral(ctxt);
1052 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1053 xsltGenericError(xsltGenericErrorContext,
1054 "xsltCompileIdKeyPattern : , expected\n");
1060 lit2 = xsltScanLiteral(ctxt);
1065 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1066 xsltGenericError(xsltGenericErrorContext,
1067 "xsltCompileIdKeyPattern : ) expected\n");
1072 /* TODO: support namespace in keys */
1073 PUSH(XSLT_OP_KEY, lit, lit2);
1074 } else if (xmlStrEqual(name, (const xmlChar *)"processing-instruction")) {
1078 lit = xsltScanLiteral(ctxt);
1083 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1084 xsltGenericError(xsltGenericErrorContext,
1085 "xsltCompileIdKeyPattern : ) expected\n");
1091 PUSH(XSLT_OP_PI, lit, NULL);
1092 } else if (xmlStrEqual(name, (const xmlChar *)"text")) {
1096 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1097 xsltGenericError(xsltGenericErrorContext,
1098 "xsltCompileIdKeyPattern : ) expected\n");
1103 PUSH(XSLT_OP_TEXT, NULL, NULL);
1104 } else if (xmlStrEqual(name, (const xmlChar *)"comment")) {
1108 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1109 xsltGenericError(xsltGenericErrorContext,
1110 "xsltCompileIdKeyPattern : ) expected\n");
1115 PUSH(XSLT_OP_COMMENT, NULL, NULL);
1116 } else if (xmlStrEqual(name, (const xmlChar *)"node")) {
1120 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1121 xsltGenericError(xsltGenericErrorContext,
1122 "xsltCompileIdKeyPattern : ) expected\n");
1127 PUSH(XSLT_OP_NODE, NULL, NULL);
1129 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1130 xsltGenericError(xsltGenericErrorContext,
1131 "xsltCompileIdKeyPattern : expecting 'key' or 'id' or node type\n");
1135 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1136 xsltGenericError(xsltGenericErrorContext,
1137 "xsltCompileIdKeyPattern : node type\n");
1147 * xsltCompileStepPattern:
1148 * @ctxt: the compilation context
1149 * @token: a posible precompiled name
1151 * Compile the XSLT StepPattern and generates a precompiled
1152 * form suitable for fast matching.
1154 * [5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate*
1155 * [6] ChildOrAttributeAxisSpecifier ::= AbbreviatedAxisSpecifier
1156 * | ('child' | 'attribute') '::'
1158 * [7] NodeTest ::= NameTest
1159 * | NodeType '(' ')'
1160 * | 'processing-instruction' '(' Literal ')'
1161 * [8] Predicate ::= '[' PredicateExpr ']'
1162 * [9] PredicateExpr ::= Expr
1163 * [13] AbbreviatedAxisSpecifier ::= '@'?
1164 * [37] NameTest ::= '*' | NCName ':' '*' | QName
1168 xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) {
1169 xmlChar *name = NULL;
1170 const xmlChar *URI = NULL;
1171 xmlChar *URL = NULL;
1175 if ((token == NULL) && (CUR == '@')) {
1176 xmlChar *prefix = NULL;
1181 PUSH(XSLT_OP_ATTR, NULL, NULL);
1184 token = xsltScanQName(ctxt, &prefix);
1185 if (prefix != NULL) {
1188 ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
1190 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1191 xsltGenericError(xsltGenericErrorContext,
1192 "xsltCompileStepPattern : no namespace bound to prefix %s\n",
1195 URL = xmlStrdup(ns->href);
1199 if (token == NULL) {
1202 PUSH(XSLT_OP_ATTR, NULL, URL);
1205 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1206 xsltGenericError(xsltGenericErrorContext,
1207 "xsltCompileStepPattern : Name expected\n");
1211 PUSH(XSLT_OP_ATTR, token, URL);
1215 token = xsltScanName(ctxt);
1216 if (token == NULL) {
1219 PUSH(XSLT_OP_ALL, token, NULL);
1220 goto parse_predicate;
1222 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1223 xsltGenericError(xsltGenericErrorContext,
1224 "xsltCompileStepPattern : Name expected\n");
1233 xsltCompileIdKeyPattern(ctxt, token, 0);
1236 } else if (CUR == ':') {
1239 xmlChar *prefix = token;
1243 * This is a namespace match
1245 token = xsltScanName(ctxt);
1246 ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
1248 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1249 xsltGenericError(xsltGenericErrorContext,
1250 "xsltCompileStepPattern : no namespace bound to prefix %s\n",
1255 URL = xmlStrdup(ns->href);
1258 if (token == NULL) {
1261 PUSH(XSLT_OP_NS, URL, NULL);
1263 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1264 xsltGenericError(xsltGenericErrorContext,
1265 "xsltCompileStepPattern : Name expected\n");
1270 PUSH(XSLT_OP_ELEM, token, URL);
1274 if (xmlStrEqual(token, (const xmlChar *) "child")) {
1276 token = xsltScanName(ctxt);
1277 if (token == NULL) {
1278 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1279 xsltGenericError(xsltGenericErrorContext,
1280 "xsltCompileStepPattern : QName expected\n");
1284 URI = xsltGetQNameURI(ctxt->elem, &token);
1285 if (token == NULL) {
1289 name = xmlStrdup(token);
1291 URL = xmlStrdup(URI);
1293 PUSH(XSLT_OP_CHILD, name, URL);
1294 } else if (xmlStrEqual(token, (const xmlChar *) "attribute")) {
1296 token = xsltScanName(ctxt);
1297 if (token == NULL) {
1298 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1299 xsltGenericError(xsltGenericErrorContext,
1300 "xsltCompileStepPattern : QName expected\n");
1304 URI = xsltGetQNameURI(ctxt->elem, &token);
1305 if (token == NULL) {
1309 name = xmlStrdup(token);
1311 URL = xmlStrdup(URI);
1313 PUSH(XSLT_OP_ATTR, name, URL);
1315 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1316 xsltGenericError(xsltGenericErrorContext,
1317 "xsltCompileStepPattern : 'child' or 'attribute' expected\n");
1323 } else if (CUR == '*') {
1325 PUSH(XSLT_OP_ALL, token, NULL);
1327 URI = xsltGetQNameURI(ctxt->elem, &token);
1328 if (token == NULL) {
1333 URL = xmlStrdup(URI);
1334 PUSH(XSLT_OP_ELEM, token, URL);
1339 while (CUR == '[') {
1341 xmlChar *ret = NULL;
1346 /* TODO: avoid breaking in strings ... */
1347 while (IS_CHAR(CUR)) {
1348 /* Skip over nested predicates */
1358 if (!IS_CHAR(CUR)) {
1359 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1360 xsltGenericError(xsltGenericErrorContext,
1361 "xsltCompileStepPattern : ']' expected\n");
1365 ret = xmlStrndup(q, CUR_PTR - q);
1366 PUSH(XSLT_OP_PREDICATE, ret, NULL);
1367 /* push the predicate lower than local test */
1380 * xsltCompileRelativePathPattern:
1381 * @comp: the compilation context
1382 * @token: a posible precompiled name
1384 * Compile the XSLT RelativePathPattern and generates a precompiled
1385 * form suitable for fast matching.
1387 * [4] RelativePathPattern ::= StepPattern
1388 * | RelativePathPattern '/' StepPattern
1389 * | RelativePathPattern '//' StepPattern
1392 xsltCompileRelativePathPattern(xsltParserContextPtr ctxt, xmlChar *token) {
1393 xsltCompileStepPattern(ctxt, token);
1397 while ((CUR != 0) && (CUR != '|')) {
1398 if ((CUR == '/') && (NXT(1) == '/')) {
1399 PUSH(XSLT_OP_ANCESTOR, NULL, NULL);
1403 xsltCompileStepPattern(ctxt, NULL);
1404 } else if (CUR == '/') {
1405 PUSH(XSLT_OP_PARENT, NULL, NULL);
1408 if ((CUR != 0) || (CUR == '|')) {
1409 xsltCompileRelativePathPattern(ctxt, NULL);
1423 * xsltCompileLocationPathPattern:
1424 * @ctxt: the compilation context
1426 * Compile the XSLT LocationPathPattern and generates a precompiled
1427 * form suitable for fast matching.
1429 * [2] LocationPathPattern ::= '/' RelativePathPattern?
1430 * | IdKeyPattern (('/' | '//') RelativePathPattern)?
1431 * | '//'? RelativePathPattern
1434 xsltCompileLocationPathPattern(xsltParserContextPtr ctxt) {
1436 if ((CUR == '/') && (NXT(1) == '/')) {
1438 * since we reverse the query
1439 * a leading // can be safely ignored
1443 xsltCompileRelativePathPattern(ctxt, NULL);
1444 } else if (CUR == '/') {
1446 * We need to find root as the parent
1450 PUSH(XSLT_OP_ROOT, NULL, NULL);
1451 if ((CUR != 0) || (CUR == '|')) {
1452 PUSH(XSLT_OP_PARENT, NULL, NULL);
1453 xsltCompileRelativePathPattern(ctxt, NULL);
1455 } else if (CUR == '*') {
1456 xsltCompileRelativePathPattern(ctxt, NULL);
1457 } else if (CUR == '@') {
1458 xsltCompileRelativePathPattern(ctxt, NULL);
1461 name = xsltScanName(ctxt);
1463 xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
1464 xsltGenericError(xsltGenericErrorContext,
1465 "xsltCompileLocationPathPattern : Name expected\n");
1470 if ((CUR == '(') && !xmlXPathIsNodeType(name)) {
1471 xsltCompileIdKeyPattern(ctxt, name, 1);
1472 if ((CUR == '/') && (NXT(1) == '/')) {
1473 PUSH(XSLT_OP_ANCESTOR, NULL, NULL);
1477 xsltCompileRelativePathPattern(ctxt, NULL);
1478 } else if (CUR == '/') {
1479 PUSH(XSLT_OP_PARENT, NULL, NULL);
1482 xsltCompileRelativePathPattern(ctxt, NULL);
1486 xsltCompileRelativePathPattern(ctxt, name);
1493 * xsltCompilePattern:
1494 * @pattern: an XSLT pattern
1495 * @doc: the containing document
1496 * @node: the containing element
1498 * Compile the XSLT pattern and generates a list of precompiled form suitable
1499 * for fast matching.
1501 * [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern
1503 * Returns the generated pattern list or NULL in case of failure
1507 xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
1508 xsltParserContextPtr ctxt = NULL;
1509 xsltCompMatchPtr element, first = NULL, previous = NULL;
1510 int current, start, end;
1512 if (pattern == NULL) {
1513 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1514 xsltGenericError(xsltGenericErrorContext,
1515 "xsltCompilePattern : NULL pattern\n");
1519 ctxt = xsltNewParserContext();
1525 while (pattern[current] != 0) {
1527 while (IS_BLANK(pattern[current]))
1530 while ((pattern[end] != 0) && (pattern[end] != '|'))
1532 if (current == end) {
1533 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1534 xsltGenericError(xsltGenericErrorContext,
1535 "xsltCompilePattern : NULL pattern\n");
1538 element = xsltNewCompMatch();
1539 if (element == NULL) {
1544 else if (previous != NULL)
1545 previous->next = element;
1548 ctxt->comp = element;
1549 ctxt->base = xmlStrndup(&pattern[start], end - start);
1550 if (ctxt->base == NULL)
1552 ctxt->cur = &(ctxt->base)[current - start];
1553 element->pattern = ctxt->base;
1555 #ifdef WITH_XSLT_DEBUG_PATTERN
1556 xsltGenericDebug(xsltGenericDebugContext,
1557 "xsltCompilePattern : parsing '%s'\n",
1560 xsltCompileLocationPathPattern(ctxt);
1565 * Reverse for faster interpretation.
1567 xsltReverseCompMatch(element);
1570 * Set-up the priority
1572 if (((element->steps[0].op == XSLT_OP_ELEM) ||
1573 (element->steps[0].op == XSLT_OP_ATTR)) &&
1574 (element->steps[0].value != NULL) &&
1575 (element->steps[1].op == XSLT_OP_END)) {
1576 element->priority = 0;
1578 } else if ((element->steps[0].op == XSLT_OP_ROOT) &&
1579 (element->steps[1].op == XSLT_OP_END)) {
1580 element->priority = 0;
1582 } else if ((element->steps[0].op == XSLT_OP_PI) &&
1583 (element->steps[0].value != NULL) &&
1584 (element->steps[1].op == XSLT_OP_END)) {
1585 element->priority = 0;
1586 } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
1587 (element->steps[0].value2 != NULL) &&
1588 (element->steps[1].op == XSLT_OP_END)) {
1589 element->priority = -0.25;
1590 } else if ((element->steps[0].op == XSLT_OP_NS) &&
1591 (element->steps[0].value != NULL) &&
1592 (element->steps[1].op == XSLT_OP_END)) {
1593 element->priority = -0.25;
1594 } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
1595 (element->steps[0].value == NULL) &&
1596 (element->steps[0].value2 == NULL) &&
1597 (element->steps[1].op == XSLT_OP_END)) {
1598 element->priority = -0.5;
1599 } else if (((element->steps[0].op == XSLT_OP_PI) ||
1600 (element->steps[0].op == XSLT_OP_TEXT) ||
1601 (element->steps[0].op == XSLT_OP_ALL) ||
1602 (element->steps[0].op == XSLT_OP_NODE) ||
1603 (element->steps[0].op == XSLT_OP_COMMENT)) &&
1604 (element->steps[1].op == XSLT_OP_END)) {
1605 element->priority = -0.5;
1607 element->priority = 0.5;
1609 #ifdef WITH_XSLT_DEBUG_PATTERN
1610 xsltGenericDebug(xsltGenericDebugContext,
1611 "xsltCompilePattern : parsed %s, default priority %f\n",
1612 element->pattern, element->priority);
1614 if (pattern[end] == '|')
1619 xsltPrintErrorContext(NULL, NULL, node); /* TODO */
1620 xsltGenericError(xsltGenericErrorContext,
1621 "xsltCompilePattern : NULL pattern\n");
1625 xsltFreeParserContext(ctxt);
1630 xsltFreeParserContext(ctxt);
1632 xsltFreeCompMatchList(first);
1636 /************************************************************************
1638 * Module interfaces *
1640 ************************************************************************/
1644 * @style: an XSLT stylesheet
1645 * @cur: an XSLT template
1646 * @mode: the mode name or NULL
1647 * @modeURI: the mode URI or NULL
1649 * Register the XSLT pattern associated to @cur
1651 * Returns -1 in case of error, 0 otherwise
1654 xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
1655 const xmlChar *mode, const xmlChar *modeURI) {
1656 xsltCompMatchPtr pat, list, *top = NULL, next;
1657 const xmlChar *name = NULL;
1658 float priority; /* the priority */
1660 if ((style == NULL) || (cur == NULL) || (cur->match == NULL))
1663 priority = cur->priority;
1664 pat = xsltCompilePattern(cur->match, style->doc, cur->elem);
1670 pat->template = cur;
1672 pat->mode = xmlStrdup(mode);
1673 if (modeURI != NULL)
1674 pat->modeURI = xmlStrdup(modeURI);
1675 if (priority != XSLT_PAT_NO_PRIORITY)
1676 pat->priority = priority;
1679 * insert it in the hash table list corresponding to its lookup name
1681 switch (pat->steps[0].op) {
1683 if (pat->steps[0].value != NULL)
1684 name = pat->steps[0].value;
1686 top = (xsltCompMatchPtr *) &(style->attrMatch);
1690 case XSLT_OP_PARENT:
1691 case XSLT_OP_ANCESTOR:
1692 top = (xsltCompMatchPtr *) &(style->elemMatch);
1695 top = (xsltCompMatchPtr *) &(style->rootMatch);
1698 top = (xsltCompMatchPtr *) &(style->keyMatch);
1701 /* TODO optimize ID !!! */
1704 top = (xsltCompMatchPtr *) &(style->elemMatch);
1707 case XSLT_OP_PREDICATE:
1708 xsltPrintErrorContext(NULL, style, NULL);
1709 xsltGenericError(xsltGenericErrorContext,
1710 "xsltAddTemplate: invalid compiled pattern\n");
1711 xsltFreeCompMatch(pat);
1714 * TODO: some flags at the top level about type based patterns
1715 * would be faster than inclusion in the hash table.
1718 if (pat->steps[0].value != NULL)
1719 name = pat->steps[0].value;
1721 top = (xsltCompMatchPtr *) &(style->piMatch);
1723 case XSLT_OP_COMMENT:
1724 top = (xsltCompMatchPtr *) &(style->commentMatch);
1727 top = (xsltCompMatchPtr *) &(style->textMatch);
1730 if (pat->steps[0].value != NULL)
1731 name = pat->steps[0].value;
1733 top = (xsltCompMatchPtr *) &(style->elemMatch);
1738 if (style->templatesHash == NULL) {
1739 style->templatesHash = xmlHashCreate(1024);
1740 if (style->templatesHash == NULL) {
1741 xsltFreeCompMatch(pat);
1744 xmlHashAddEntry3(style->templatesHash, name, mode, modeURI, pat);
1746 list = (xsltCompMatchPtr) xmlHashLookup3(style->templatesHash,
1747 name, mode, modeURI);
1749 xmlHashAddEntry3(style->templatesHash, name,
1750 mode, modeURI, pat);
1753 * Note '<=' since one must choose among the matching
1754 * template rules that are left, the one that occurs
1755 * last in the stylesheet
1757 if (list->priority <= pat->priority) {
1759 xmlHashUpdateEntry3(style->templatesHash, name,
1760 mode, modeURI, pat, NULL);
1762 while (list->next != NULL) {
1763 if (list->next->priority <= pat->priority)
1767 pat->next = list->next;
1772 } else if (top != NULL) {
1777 } else if (list->priority <= pat->priority) {
1781 while (list->next != NULL) {
1782 if (list->next->priority <= pat->priority)
1786 pat->next = list->next;
1790 xsltPrintErrorContext(NULL, style, NULL);
1791 xsltGenericError(xsltGenericErrorContext,
1792 "xsltAddTemplate: invalid compiled pattern\n");
1793 xsltFreeCompMatch(pat);
1796 #ifdef WITH_XSLT_DEBUG_PATTERN
1798 xsltGenericDebug(xsltGenericDebugContext,
1799 "added pattern : '%s' mode '%s' priority %f\n",
1800 pat->pattern, pat->mode, pat->priority);
1802 xsltGenericDebug(xsltGenericDebugContext,
1803 "added pattern : '%s' priority %f\n",
1804 pat->pattern, pat->priority);
1814 * @ctxt: a XSLT process context
1815 * @node: the node being processed
1816 * @style: the current style
1818 * Finds the template applying to this node, if @style is non-NULL
1819 * it means one needs to look for the next imported template in scope.
1821 * Returns the xsltTemplatePtr or NULL if not found
1824 xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
1825 xsltStylesheetPtr style) {
1826 xsltStylesheetPtr curstyle;
1827 xsltTemplatePtr ret = NULL;
1828 const xmlChar *name = NULL;
1829 xsltCompMatchPtr list = NULL;
1832 if ((ctxt == NULL) || (node == NULL))
1835 if (style == NULL) {
1836 curstyle = ctxt->style;
1838 curstyle = xsltNextImport(style);
1841 while ((curstyle != NULL) && (curstyle != style)) {
1842 priority = XSLT_PAT_NO_PRIORITY;
1843 /* TODO : handle IDs/keys here ! */
1844 if (curstyle->templatesHash != NULL) {
1846 * Use the top name as selector
1848 switch (node->type) {
1849 case XML_ELEMENT_NODE:
1850 case XML_ATTRIBUTE_NODE:
1854 case XML_DOCUMENT_NODE:
1855 case XML_HTML_DOCUMENT_NODE:
1857 case XML_CDATA_SECTION_NODE:
1858 case XML_COMMENT_NODE:
1859 case XML_ENTITY_REF_NODE:
1860 case XML_ENTITY_NODE:
1861 case XML_DOCUMENT_TYPE_NODE:
1862 case XML_DOCUMENT_FRAG_NODE:
1863 case XML_NOTATION_NODE:
1865 case XML_ELEMENT_DECL:
1866 case XML_ATTRIBUTE_DECL:
1867 case XML_ENTITY_DECL:
1868 case XML_NAMESPACE_DECL:
1869 case XML_XINCLUDE_START:
1870 case XML_XINCLUDE_END:
1879 * find the list of appliable expressions based on the name
1881 list = (xsltCompMatchPtr) xmlHashLookup3(curstyle->templatesHash,
1882 name, ctxt->mode, ctxt->modeURI);
1885 while (list != NULL) {
1886 if (xsltTestCompMatch(ctxt, list, node,
1887 ctxt->mode, ctxt->modeURI)) {
1888 ret = list->template;
1889 priority = list->priority;
1897 * find alternate generic matches
1899 switch (node->type) {
1900 case XML_ELEMENT_NODE:
1901 list = curstyle->elemMatch;
1903 case XML_ATTRIBUTE_NODE:
1904 list = curstyle->attrMatch;
1907 list = curstyle->piMatch;
1909 case XML_DOCUMENT_NODE:
1910 case XML_HTML_DOCUMENT_NODE:
1911 list = curstyle->rootMatch;
1914 case XML_CDATA_SECTION_NODE:
1915 list = curstyle->textMatch;
1917 case XML_COMMENT_NODE:
1918 list = curstyle->commentMatch;
1920 case XML_ENTITY_REF_NODE:
1921 case XML_ENTITY_NODE:
1922 case XML_DOCUMENT_TYPE_NODE:
1923 case XML_DOCUMENT_FRAG_NODE:
1924 case XML_NOTATION_NODE:
1926 case XML_ELEMENT_DECL:
1927 case XML_ATTRIBUTE_DECL:
1928 case XML_ENTITY_DECL:
1929 case XML_NAMESPACE_DECL:
1930 case XML_XINCLUDE_START:
1931 case XML_XINCLUDE_END:
1937 while ((list != NULL) &&
1938 ((ret == NULL) || (list->priority > priority))) {
1939 if (xsltTestCompMatch(ctxt, list, node,
1940 ctxt->mode, ctxt->modeURI)) {
1941 ret = list->template;
1947 * Some of the tests for elements can also apply to documents
1949 if ((node->type == XML_DOCUMENT_NODE) ||
1950 (node->type == XML_HTML_DOCUMENT_NODE)) {
1951 list = curstyle->elemMatch;
1952 while ((list != NULL) &&
1953 ((ret == NULL) || (list->priority > priority))) {
1954 if (xsltTestCompMatch(ctxt, list, node,
1955 ctxt->mode, ctxt->modeURI)) {
1956 ret = list->template;
1963 if (node->_private != NULL) {
1964 list = curstyle->keyMatch;
1965 while ((list != NULL) &&
1966 ((ret == NULL) || (list->priority > priority))) {
1967 if (xsltTestCompMatch(ctxt, list, node,
1968 ctxt->mode, ctxt->modeURI)) {
1969 ret = list->template;
1979 * Cycle on next curstylesheet import.
1981 curstyle = xsltNextImport(curstyle);
1987 * xsltCleanupTemplates:
1988 * @style: an XSLT stylesheet
1990 * Cleanup the state of the templates used by the stylesheet and
1991 * the ones it imports.
1994 xsltCleanupTemplates(xsltStylesheetPtr style) {
1995 while (style != NULL) {
1996 xmlHashScan((xmlHashTablePtr) style->templatesHash,
1997 (xmlHashScanner) xsltCleanupCompMatch, NULL);
1999 style = xsltNextImport(style);
2004 * xsltFreeTemplateHashes:
2005 * @style: an XSLT stylesheet
2007 * Free up the memory used by xsltAddTemplate/xsltGetTemplate mechanism
2010 xsltFreeTemplateHashes(xsltStylesheetPtr style) {
2011 if (style->templatesHash != NULL)
2012 xmlHashFree((xmlHashTablePtr) style->templatesHash,
2013 (xmlHashDeallocator) xsltFreeCompMatchList);
2014 if (style->rootMatch != NULL)
2015 xsltFreeCompMatchList(style->rootMatch);
2016 if (style->keyMatch != NULL)
2017 xsltFreeCompMatchList(style->keyMatch);
2018 if (style->elemMatch != NULL)
2019 xsltFreeCompMatchList(style->elemMatch);
2020 if (style->attrMatch != NULL)
2021 xsltFreeCompMatchList(style->attrMatch);
2022 if (style->parentMatch != NULL)
2023 xsltFreeCompMatchList(style->parentMatch);
2024 if (style->textMatch != NULL)
2025 xsltFreeCompMatchList(style->textMatch);
2026 if (style->piMatch != NULL)
2027 xsltFreeCompMatchList(style->piMatch);
2028 if (style->commentMatch != NULL)
2029 xsltFreeCompMatchList(style->commentMatch);
2035 * @node: a node in the source tree
2036 * @pattern: an XSLT pattern
2038 * Determine if a node matches a pattern.
2041 xsltMatchPattern(xsltTransformContextPtr context,
2043 const xmlChar *pattern)
2046 xsltCompMatchPtr first, comp;
2048 if ((context != NULL) && (pattern != NULL)) {
2049 first = xsltCompilePattern(pattern);
2050 for (comp = first; comp != NULL; comp = comp->next) {
2051 match = xsltTestCompMatch(context, comp, node, NULL, NULL);
2056 xsltFreeCompMatchList(first);