static HRESULT xslt_next_match( struct xslt_info *info, xmlNodePtr *node, xmlNodePtr *top_level_node ) { if (!info->ctxt) return S_FALSE; /* make sure that the current element matches the pattern */ while ( *node ) { int r; r = xsltTestCompMatchList( info->ctxt, *node, info->pattern ); if ( 1 == r ) { TRACE("Matched %p (%s)\n", *node, (*node)->name ); return S_OK; } if (r != 0) { ERR("Pattern match failed\n"); return E_FAIL; } *node = get_next_node(info, *node, top_level_node); } return S_OK; }
static int xsltNumberFormatGetAnyLevel(xsltTransformContextPtr context, xmlNodePtr node, xsltCompMatchPtr countPat, xsltCompMatchPtr fromPat, double *array) { int amount = 0; int cnt = 0; xmlNodePtr cur = node; while (cur != NULL) { /* process current node */ if (xsltTestCompMatchCount(context, cur, countPat, node)) cnt++; if ((fromPat != NULL) && xsltTestCompMatchList(context, cur, fromPat)) { break; /* while */ } /* Skip to next preceding or ancestor */ if ((cur->type == XML_DOCUMENT_NODE) || #ifdef LIBXML_DOCB_ENABLED (cur->type == XML_DOCB_DOCUMENT_NODE) || #endif (cur->type == XML_HTML_DOCUMENT_NODE)) break; /* while */ if (cur->type == XML_NAMESPACE_DECL) { /* * The XPath module stores the parent of a namespace node in * the ns->next field. */ cur = (xmlNodePtr) ((xmlNsPtr) cur)->next; } else if (cur->type == XML_ATTRIBUTE_NODE) { cur = cur->parent; } else { while ((cur->prev != NULL) && ((cur->prev->type == XML_DTD_NODE) || (cur->prev->type == XML_XINCLUDE_START) || (cur->prev->type == XML_XINCLUDE_END))) cur = cur->prev; if (cur->prev != NULL) { for (cur = cur->prev; cur->last != NULL; cur = cur->last); } else { cur = cur->parent; } } } array[amount++] = (double) cnt; return(amount); }
static int xsltNumberFormatGetMultipleLevel(xsltTransformContextPtr context, xmlNodePtr node, xsltCompMatchPtr countPat, xsltCompMatchPtr fromPat, double *array, int max) { int amount = 0; int cnt; xmlNodePtr ancestor; xmlNodePtr preceding; xmlXPathParserContextPtr parser; context->xpathCtxt->node = node; parser = xmlXPathNewParserContext(NULL, context->xpathCtxt); if (parser) { /* ancestor-or-self::*[count] */ for (ancestor = node; (ancestor != NULL) && (ancestor->type != XML_DOCUMENT_NODE); ancestor = xmlXPathNextAncestor(parser, ancestor)) { if ((fromPat != NULL) && xsltTestCompMatchList(context, ancestor, fromPat)) break; /* for */ if (xsltTestCompMatchCount(context, ancestor, countPat, node)) { /* count(preceding-sibling::*) */ cnt = 1; for (preceding = xmlXPathNextPrecedingSibling(parser, ancestor); preceding != NULL; preceding = xmlXPathNextPrecedingSibling(parser, preceding)) { if (xsltTestCompMatchCount(context, preceding, countPat, node)) cnt++; } array[amount++] = (double)cnt; if (amount >= max) break; /* for */ } } xmlXPathFreeParserContext(parser); } return amount; }
static int xsltTestCompMatchCount(xsltTransformContextPtr context, xmlNodePtr node, xsltCompMatchPtr countPat, xmlNodePtr cur) { if (countPat != NULL) { return xsltTestCompMatchList(context, node, countPat); } else { /* * 7.7 Numbering * * If count attribute is not specified, then it defaults to the * pattern that matches any node with the same node type as the * current node and, if the current node has an expanded-name, with * the same expanded-name as the current node. */ if (node->type != cur->type) return 0; if (node->type == XML_NAMESPACE_DECL) /* * Namespace nodes have no preceding siblings and no parents * that are namespace nodes. This means that node == cur. */ return 1; /* TODO: Skip node types without expanded names like text nodes. */ if (!xmlStrEqual(node->name, cur->name)) return 0; if (node->ns == cur->ns) return 1; if ((node->ns == NULL) || (cur->ns == NULL)) return 0; return (xmlStrEqual(node->ns->href, cur->ns->href)); } }
static int xsltNumberFormatGetMultipleLevel(xsltTransformContextPtr context, xmlNodePtr node, xmlChar *count, xmlChar *from, double *array, int max, xmlDocPtr doc, xmlNodePtr elem) { int amount = 0; int cnt; xmlNodePtr ancestor; xmlNodePtr preceding; xmlXPathParserContextPtr parser; xsltCompMatchPtr countPat; xsltCompMatchPtr fromPat; if (count != NULL) countPat = xsltCompilePattern(count, doc, elem, NULL, context); else countPat = NULL; if (from != NULL) fromPat = xsltCompilePattern(from, doc, elem, NULL, context); else fromPat = NULL; context->xpathCtxt->node = node; parser = xmlXPathNewParserContext(NULL, context->xpathCtxt); if (parser) { /* ancestor-or-self::*[count] */ for (ancestor = node; (ancestor != NULL) && (ancestor->type != XML_DOCUMENT_NODE); ancestor = xmlXPathNextAncestor(parser, ancestor)) { if ((from != NULL) && xsltTestCompMatchList(context, ancestor, fromPat)) break; /* for */ if ((count == NULL) || xsltTestCompMatchList(context, ancestor, countPat)) { /* count(preceding-sibling::*) */ cnt = 0; for (preceding = ancestor; preceding != NULL; preceding = xmlXPathNextPrecedingSibling(parser, preceding)) { if (count == NULL) { if ((preceding->type == ancestor->type) && /* FIXME */ xmlStrEqual(preceding->name, ancestor->name)) cnt++; } else { if (xsltTestCompMatchList(context, preceding, countPat)) cnt++; } } array[amount++] = (double)cnt; if (amount >= max) break; /* for */ } } xmlXPathFreeParserContext(parser); } xsltFreeCompMatchList(countPat); xsltFreeCompMatchList(fromPat); return amount; }
static int xsltNumberFormatGetAnyLevel(xsltTransformContextPtr context, xmlNodePtr node, xmlChar *count, xmlChar *from, double *array, xmlDocPtr doc, xmlNodePtr elem) { int amount = 0; int cnt = 0; xmlNodePtr cur; xsltCompMatchPtr countPat = NULL; xsltCompMatchPtr fromPat = NULL; if (count != NULL) countPat = xsltCompilePattern(count, doc, elem, NULL, context); if (from != NULL) fromPat = xsltCompilePattern(from, doc, elem, NULL, context); /* select the starting node */ switch (node->type) { case XML_ELEMENT_NODE: cur = node; break; case XML_ATTRIBUTE_NODE: cur = ((xmlAttrPtr) node)->parent; break; case XML_TEXT_NODE: case XML_PI_NODE: case XML_COMMENT_NODE: cur = node->parent; break; default: cur = NULL; break; } while (cur != NULL) { /* process current node */ if (count == NULL) { if ((node->type == cur->type) && /* FIXME: must use expanded-name instead of local name */ xmlStrEqual(node->name, cur->name)) cnt++; } else { if (xsltTestCompMatchList(context, cur, countPat)) cnt++; } if ((from != NULL) && xsltTestCompMatchList(context, cur, fromPat)) { break; /* while */ } /* Skip to next preceding or ancestor */ if ((cur->type == XML_DOCUMENT_NODE) || #ifdef LIBXML_DOCB_ENABLED (cur->type == XML_DOCB_DOCUMENT_NODE) || #endif (cur->type == XML_HTML_DOCUMENT_NODE)) break; /* while */ while ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) cur = cur->prev; if (cur->prev != NULL) { for (cur = cur->prev; cur->last != NULL; cur = cur->last); } else { cur = cur->parent; } } array[amount++] = (double) cnt; if (countPat != NULL) xsltFreeCompMatchList(countPat); if (fromPat != NULL) xsltFreeCompMatchList(fromPat); return(amount); }