Lines Matching refs:ctxt

226     { xmlXPathErr(ctxt, X); return(NULL); }
262 * @ctxt: an XPath context
268 xmlXPathErrMemory(xmlXPathContextPtr ctxt, const char *extra)
270 if (ctxt != NULL) {
277 ctxt->lastError.message = (char *) xmlStrdup(buf);
279 ctxt->lastError.message = (char *)
282 ctxt->lastError.domain = XML_FROM_XPATH;
283 ctxt->lastError.code = XML_ERR_NO_MEMORY;
284 if (ctxt->error != NULL)
285 ctxt->error(ctxt->userData, &ctxt->lastError);
304 * @ctxt: an XPath parser context
310 xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra)
312 if (ctxt == NULL)
315 ctxt->error = XPATH_MEMORY_ERROR;
316 xmlXPathErrMemory(ctxt->context, extra);
322 * @ctxt: a XPath parser context
328 xmlXPathErr(xmlXPathParserContextPtr ctxt, int error)
332 if (ctxt == NULL) {
341 ctxt->error = error;
342 if (ctxt->context == NULL) {
347 (const char *) ctxt->base, NULL, NULL,
348 ctxt->cur - ctxt->base, 0,
354 xmlResetError(&ctxt->context->lastError);
356 ctxt->context->lastError.domain = XML_FROM_XPATH;
357 ctxt->context->lastError.code = error + XML_XPATH_EXPRESSION_OK -
359 ctxt->context->lastError.level = XML_ERR_ERROR;
360 ctxt->context->lastError.str1 = (char *) xmlStrdup(ctxt->base);
361 ctxt->context->lastError.int1 = ctxt->cur - ctxt->base;
362 ctxt->context->lastError.node = ctxt->context->debugNode;
363 if (ctxt->context->error != NULL) {
364 ctxt->context->error(ctxt->context->userData,
365 &ctxt->context->lastError);
368 NULL, ctxt->context->debugNode, XML_FROM_XPATH,
371 (const char *) ctxt->base, NULL, NULL,
372 ctxt->cur - ctxt->base, 0,
380 * @ctxt: the XPath Parser context
388 xmlXPatherror(xmlXPathParserContextPtr ctxt, const char *file ATTRIBUTE_UNUSED,
390 xmlXPathErr(ctxt, no);
598 xmlXPathReleaseObject(xmlXPathContextPtr ctxt, xmlXPathObjectPtr obj);
600 xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
603 xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt,
794 xmlXPathCompExprAdd(ctxt->comp, (op1), (op2), \
797 xmlXPathCompExprAdd(ctxt->comp, ctxt->comp->last, -1, \
801 xmlXPathCompExprAdd(ctxt->comp, -1, -1, (op), (val), (val2), 0 ,NULL ,NULL)
804 xmlXPathCompExprAdd(ctxt->comp, (ch), -1, (op), (val), (val2), 0 ,NULL ,NULL)
807 xmlXPathCompExprAdd(ctxt->comp, (ch1), (ch2), (op), \
1353 xmlXPathDebugObjUsageReset(xmlXPathContextPtr ctxt)
1355 if (ctxt != NULL) {
1356 if (ctxt->cache != NULL) {
1358 (xmlXPathContextCachePtr) ctxt->cache;
1425 xmlXPathDebugObjUsageRequested(xmlXPathContextPtr ctxt,
1430 if (ctxt != NULL) {
1431 if (ctxt->cache != NULL) {
1433 (xmlXPathContextCachePtr) ctxt->cache;
1579 xmlXPathDebugObjUsageReleased(xmlXPathContextPtr ctxt,
1584 if (ctxt != NULL) {
1585 if (ctxt->cache != NULL) {
1587 (xmlXPathContextCachePtr) ctxt->cache;
1668 xmlXPathDebugObjUsageDisplay(xmlXPathContextPtr ctxt)
1688 if (ctxt != NULL) {
1689 if (ctxt->cache != NULL) {
1691 (xmlXPathContextCachePtr) ctxt->cache;
1859 * @ctxt: the XPath context
1879 xmlXPathContextSetCache(xmlXPathContextPtr ctxt,
1884 if (ctxt == NULL)
1889 if (ctxt->cache == NULL) {
1890 ctxt->cache = xmlXPathNewCache();
1891 if (ctxt->cache == NULL)
1894 cache = (xmlXPathContextCachePtr) ctxt->cache;
1904 } else if (ctxt->cache != NULL) {
1905 xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache);
1906 ctxt->cache = NULL;
1913 * @ctxt: the XPath context
1922 xmlXPathCacheWrapNodeSet(xmlXPathContextPtr ctxt, xmlNodeSetPtr val)
1924 if ((ctxt != NULL) && (ctxt->cache != NULL)) {
1926 (xmlXPathContextCachePtr) ctxt->cache;
1938 xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);
1950 * @ctxt: the XPath context
1959 xmlXPathCacheWrapString(xmlXPathContextPtr ctxt, xmlChar *val)
1961 if ((ctxt != NULL) && (ctxt->cache != NULL)) {
1962 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
1975 xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);
1991 xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);
2001 * @ctxt: the XPath context
2011 xmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val)
2013 if ((ctxt != NULL) && (ctxt->cache)) {
2014 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
2038 xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);
2056 xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);
2066 * @ctxt: the XPath context
2075 xmlXPathCacheNewCString(xmlXPathContextPtr ctxt, const char *val)
2077 if ((ctxt != NULL) && (ctxt->cache)) {
2078 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
2091 xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);
2105 xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);
2115 * @ctxt: the XPath context
2124 xmlXPathCacheNewString(xmlXPathContextPtr ctxt, const xmlChar *val)
2126 if ((ctxt != NULL) && (ctxt->cache)) {
2127 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
2142 xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);
2159 xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);
2169 * @ctxt: the XPath context
2178 xmlXPathCacheNewBoolean(xmlXPathContextPtr ctxt, int val)
2180 if ((ctxt != NULL) && (ctxt->cache)) {
2181 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
2193 xmlXPathDebugObjUsageRequested(ctxt, XPATH_BOOLEAN);
2207 xmlXPathDebugObjUsageRequested(ctxt, XPATH_BOOLEAN);
2217 * @ctxt: the XPath context
2226 xmlXPathCacheNewFloat(xmlXPathContextPtr ctxt, double val)
2228 if ((ctxt != NULL) && (ctxt->cache)) {
2229 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
2241 xmlXPathDebugObjUsageRequested(ctxt, XPATH_NUMBER);
2255 xmlXPathDebugObjUsageRequested(ctxt, XPATH_NUMBER);
2265 * @ctxt: the XPath context
2276 xmlXPathCacheConvertString(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val) {
2280 return(xmlXPathCacheNewCString(ctxt, ""));
2307 xmlXPathReleaseObject(ctxt, val);
2309 return(xmlXPathCacheNewCString(ctxt, ""));
2310 return(xmlXPathCacheWrapString(ctxt, res));
2315 * @ctxt: the XPath context
2324 xmlXPathCacheObjectCopy(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val)
2329 if (XP_HAS_CACHE(ctxt)) {
2332 return(xmlXPathCacheWrapNodeSet(ctxt,
2335 return(xmlXPathCacheNewString(ctxt, val->stringval));
2337 return(xmlXPathCacheNewBoolean(ctxt, val->boolval));
2339 return(xmlXPathCacheNewFloat(ctxt, val->floatval));
2349 * @ctxt: the XPath context
2359 xmlXPathCacheConvertBoolean(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val) {
2363 return(xmlXPathCacheNewBoolean(ctxt, 0));
2366 ret = xmlXPathCacheNewBoolean(ctxt, xmlXPathCastToBoolean(val));
2367 xmlXPathReleaseObject(ctxt, val);
2373 * @ctxt: the XPath context
2383 xmlXPathCacheConvertNumber(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val) {
2387 return(xmlXPathCacheNewFloat(ctxt, 0.0));
2390 ret = xmlXPathCacheNewFloat(ctxt, xmlXPathCastToNumber(val));
2391 xmlXPathReleaseObject(ctxt, val);
2403 * @ctxt: an XPath parser context
2410 xmlXPathSetFrame(xmlXPathParserContextPtr ctxt) {
2413 if (ctxt == NULL)
2415 ret = ctxt->valueFrame;
2416 ctxt->valueFrame = ctxt->valueNr;
2422 * @ctxt: an XPath parser context
2428 xmlXPathPopFrame(xmlXPathParserContextPtr ctxt, int frame) {
2429 if (ctxt == NULL)
2431 if (ctxt->valueNr < ctxt->valueFrame) {
2432 xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_STACK_ERROR);
2434 ctxt->valueFrame = frame;
2439 * @ctxt: an XPath evaluation context
2446 valuePop(xmlXPathParserContextPtr ctxt)
2450 if ((ctxt == NULL) || (ctxt->valueNr <= 0))
2453 if (ctxt->valueNr <= ctxt->valueFrame) {
2454 xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_STACK_ERROR);
2458 ctxt->valueNr--;
2459 if (ctxt->valueNr > 0)
2460 ctxt->value = ctxt->valueTab[ctxt->valueNr - 1];
2462 ctxt->value = NULL;
2463 ret = ctxt->valueTab[ctxt->valueNr];
2464 ctxt->valueTab[ctxt->valueNr] = NULL;
2469 * @ctxt: an XPath evaluation context
2477 valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value)
2479 if ((ctxt == NULL) || (value == NULL)) return(-1);
2480 if (ctxt->valueNr >= ctxt->valueMax) {
2483 tmp = (xmlXPathObjectPtr *) xmlRealloc(ctxt->valueTab,
2484 2 * ctxt->valueMax *
2485 sizeof(ctxt->valueTab[0]));
2488 ctxt->error = XPATH_MEMORY_ERROR;
2491 ctxt->valueMax *= 2;
2492 ctxt->valueTab = tmp;
2494 ctxt->valueTab[ctxt->valueNr] = value;
2495 ctxt->value = value;
2496 return (ctxt->valueNr++);
2501 * @ctxt: an XPath parser context
2509 xmlXPathPopBoolean (xmlXPathParserContextPtr ctxt) {
2513 obj = valuePop(ctxt);
2515 xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND);
2522 xmlXPathReleaseObject(ctxt->context, obj);
2528 * @ctxt: an XPath parser context
2536 xmlXPathPopNumber (xmlXPathParserContextPtr ctxt) {
2540 obj = valuePop(ctxt);
2542 xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND);
2549 xmlXPathReleaseObject(ctxt->context, obj);
2555 * @ctxt: an XPath parser context
2563 xmlXPathPopString (xmlXPathParserContextPtr ctxt) {
2567 obj = valuePop(ctxt);
2569 xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND);
2576 xmlXPathReleaseObject(ctxt->context, obj);
2582 * @ctxt: an XPath parser context
2590 xmlXPathPopNodeSet (xmlXPathParserContextPtr ctxt) {
2594 if (ctxt == NULL) return(NULL);
2595 if (ctxt->value == NULL) {
2596 xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND);
2599 if (!xmlXPathStackIsNodeSet(ctxt)) {
2600 xmlXPathSetTypeError(ctxt);
2603 obj = valuePop(ctxt);
2611 xmlXPathReleaseObject(ctxt->context, obj);
2617 * @ctxt: an XPath parser context
2625 xmlXPathPopExternal (xmlXPathParserContextPtr ctxt) {
2629 if ((ctxt == NULL) || (ctxt->value == NULL)) {
2630 xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND);
2633 if (ctxt->value->type != XPATH_USERS) {
2634 xmlXPathSetTypeError(ctxt);
2637 obj = valuePop(ctxt);
2640 xmlXPathReleaseObject(ctxt->context, obj);
2667 #define CUR (*ctxt->cur)
2668 #define SKIP(val) ctxt->cur += (val)
2669 #define NXT(val) ctxt->cur[(val)]
2670 #define CUR_PTR ctxt->cur
2671 #define CUR_CHAR(l) xmlXPathCurrentChar(ctxt, &l)
2677 #define NEXTL(l) ctxt->cur += l
2680 while (IS_BLANK_CH(*(ctxt->cur))) NEXT
2682 #define CURRENT (*ctxt->cur)
2683 #define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
4744 * @ctxt: the XPath context
4753 xmlXPathRegisterFunc(xmlXPathContextPtr ctxt, const xmlChar *name,
4755 return(xmlXPathRegisterFuncNS(ctxt, name, NULL, f));
4760 * @ctxt: the XPath context
4770 xmlXPathRegisterFuncNS(xmlXPathContextPtr ctxt, const xmlChar *name,
4772 if (ctxt == NULL)
4777 if (ctxt->funcHash == NULL)
4778 ctxt->funcHash = xmlHashCreate(0);
4779 if (ctxt->funcHash == NULL)
4782 return(xmlHashRemoveEntry2(ctxt->funcHash, name, ns_uri, NULL));
4783 return(xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, XML_CAST_FPTR(f)));
4788 * @ctxt: the XPath context
4795 xmlXPathRegisterFuncLookup (xmlXPathContextPtr ctxt,
4798 if (ctxt == NULL)
4800 ctxt->funcLookupFunc = f;
4801 ctxt->funcLookupData = funcCtxt;
4806 * @ctxt: the XPath context
4815 xmlXPathFunctionLookup(xmlXPathContextPtr ctxt, const xmlChar *name) {
4816 if (ctxt == NULL)
4819 if (ctxt->funcLookupFunc != NULL) {
4823 f = ctxt->funcLookupFunc;
4824 ret = f(ctxt->funcLookupData, name, NULL);
4828 return(xmlXPathFunctionLookupNS(ctxt, name, NULL));
4833 * @ctxt: the XPath context
4843 xmlXPathFunctionLookupNS(xmlXPathContextPtr ctxt, const xmlChar *name,
4847 if (ctxt == NULL)
4852 if (ctxt->funcLookupFunc != NULL) {
4855 f = ctxt->funcLookupFunc;
4856 ret = f(ctxt->funcLookupData, name, ns_uri);
4861 if (ctxt->funcHash == NULL)
4864 XML_CAST_FPTR(ret) = xmlHashLookup2(ctxt->funcHash, name, ns_uri);
4870 * @ctxt: the XPath context
4875 xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt) {
4876 if (ctxt == NULL)
4879 xmlHashFree(ctxt->funcHash, NULL);
4880 ctxt->funcHash = NULL;
4891 * @ctxt: the XPath context
4901 xmlXPathRegisterVariable(xmlXPathContextPtr ctxt, const xmlChar *name,
4903 return(xmlXPathRegisterVariableNS(ctxt, name, NULL, value));
4908 * @ctxt: the XPath context
4919 xmlXPathRegisterVariableNS(xmlXPathContextPtr ctxt, const xmlChar *name,
4922 if (ctxt == NULL)
4927 if (ctxt->varHash == NULL)
4928 ctxt->varHash = xmlHashCreate(0);
4929 if (ctxt->varHash == NULL)
4932 return(xmlHashRemoveEntry2(ctxt->varHash, name, ns_uri,
4934 return(xmlHashUpdateEntry2(ctxt->varHash, name, ns_uri,
4941 * @ctxt: the XPath context
4948 xmlXPathRegisterVariableLookup(xmlXPathContextPtr ctxt,
4950 if (ctxt == NULL)
4952 ctxt->varLookupFunc = f;
4953 ctxt->varLookupData = data;
4958 * @ctxt: the XPath context
4967 xmlXPathVariableLookup(xmlXPathContextPtr ctxt, const xmlChar *name) {
4968 if (ctxt == NULL)
4971 if (ctxt->varLookupFunc != NULL) {
4974 ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc)
4975 (ctxt->varLookupData, name, NULL);
4978 return(xmlXPathVariableLookupNS(ctxt, name, NULL));
4983 * @ctxt: the XPath context
4993 xmlXPathVariableLookupNS(xmlXPathContextPtr ctxt, const xmlChar *name,
4995 if (ctxt == NULL)
4998 if (ctxt->varLookupFunc != NULL) {
5001 ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc)
5002 (ctxt->varLookupData, name, ns_uri);
5006 if (ctxt->varHash == NULL)
5011 return(xmlXPathCacheObjectCopy(ctxt, (xmlXPathObjectPtr)
5012 xmlHashLookup2(ctxt->varHash, name, ns_uri)));
5017 * @ctxt: the XPath context
5022 xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt) {
5023 if (ctxt == NULL)
5026 xmlHashFree(ctxt->varHash, (xmlHashDeallocator)xmlXPathFreeObject);
5027 ctxt->varHash = NULL;
5032 * @ctxt: the XPath context
5042 xmlXPathRegisterNs(xmlXPathContextPtr ctxt, const xmlChar *prefix,
5044 if (ctxt == NULL)
5049 if (ctxt->nsHash == NULL)
5050 ctxt->nsHash = xmlHashCreate(10);
5051 if (ctxt->nsHash == NULL)
5054 return(xmlHashRemoveEntry(ctxt->nsHash, prefix,
5056 return(xmlHashUpdateEntry(ctxt->nsHash, prefix, (void *) xmlStrdup(ns_uri),
5062 * @ctxt: the XPath context
5071 xmlXPathNsLookup(xmlXPathContextPtr ctxt, const xmlChar *prefix) {
5072 if (ctxt == NULL)
5082 if (ctxt->namespaces != NULL) {
5085 for (i = 0;i < ctxt->nsNr;i++) {
5086 if ((ctxt->namespaces[i] != NULL) &&
5087 (xmlStrEqual(ctxt->namespaces[i]->prefix, prefix)))
5088 return(ctxt->namespaces[i]->href);
5092 return((const xmlChar *) xmlHashLookup(ctxt->nsHash, prefix));
5097 * @ctxt: the XPath context
5102 xmlXPathRegisteredNsCleanup(xmlXPathContextPtr ctxt) {
5103 if (ctxt == NULL)
5106 xmlHashFree(ctxt->nsHash, (xmlHashDeallocator)xmlFree);
5107 ctxt->nsHash = NULL;
5428 xmlXPathReleaseObject(xmlXPathContextPtr ctxt, xmlXPathObjectPtr obj)
5438 if ((ctxt == NULL) || (ctxt->cache == NULL)) {
5442 (xmlXPathContextCachePtr) ctxt->cache;
5512 xmlXPathDebugObjUsageReleased(ctxt, obj->type);
6061 * @ctxt: the context to free
6066 xmlXPathFreeContext(xmlXPathContextPtr ctxt) {
6067 if (ctxt == NULL) return;
6069 if (ctxt->cache != NULL)
6070 xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache);
6071 xmlXPathRegisteredNsCleanup(ctxt);
6072 xmlXPathRegisteredFuncsCleanup(ctxt);
6073 xmlXPathRegisteredVariablesCleanup(ctxt);
6074 xmlResetError(&ctxt->lastError);
6075 xmlFree(ctxt);
6084 #define CHECK_CTXT(ctxt) \
6085 if (ctxt == NULL) { \
6095 #define CHECK_CTXT_NEG(ctxt) \
6096 if (ctxt == NULL) { \
6107 #define CHECK_CONTEXT(ctxt) \
6108 if ((ctxt == NULL) || (ctxt->doc == NULL) || \
6109 (ctxt->doc->children == NULL)) { \
6110 xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_INVALID_CTXT); \
6118 * @ctxt: the XPath context
6125 xmlXPathNewParserContext(const xmlChar *str, xmlXPathContextPtr ctxt) {
6130 xmlXPathErrMemory(ctxt, "creating parser context\n");
6135 ret->context = ctxt;
6143 if ((ctxt != NULL) && (ctxt->dict != NULL)) {
6144 ret->comp->dict = ctxt->dict;
6154 * @ctxt: the XPath context
6161 xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctxt) {
6166 xmlXPathErrMemory(ctxt, "creating evaluation context\n");
6176 xmlXPathErrMemory(ctxt, "creating evaluation context\n");
6184 ret->context = ctxt;
6192 * @ctxt: the context to free
6197 xmlXPathFreeParserContext(xmlXPathParserContextPtr ctxt) {
6198 if (ctxt->valueTab != NULL) {
6199 xmlFree(ctxt->valueTab);
6201 if (ctxt->comp != NULL) {
6203 if (ctxt->comp->stream != NULL) {
6204 xmlFreePatternList(ctxt->comp->stream);
6205 ctxt->comp->stream = NULL;
6208 xmlXPathFreeCompExpr(ctxt->comp);
6210 xmlFree(ctxt);
6359 * @ctxt: the XPath Parser context
6380 xmlXPathCompareNodeSetFloat(xmlXPathParserContextPtr ctxt, int inf, int strict,
6388 xmlXPathReleaseObject(ctxt->context, arg);
6389 xmlXPathReleaseObject(ctxt->context, f);
6397 valuePush(ctxt,
6398 xmlXPathCacheNewString(ctxt->context, str2));
6400 xmlXPathNumberFunction(ctxt, 1);
6401 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt->context, f));
6402 ret = xmlXPathCompareValues(ctxt, inf, strict);
6408 xmlXPathReleaseObject(ctxt->context, arg);
6409 xmlXPathReleaseObject(ctxt->context, f);
6415 * @ctxt: the XPath Parser context
6435 xmlXPathCompareNodeSetString(xmlXPathParserContextPtr ctxt, int inf, int strict,
6443 xmlXPathReleaseObject(ctxt->context, arg);
6444 xmlXPathReleaseObject(ctxt->context, s);
6452 valuePush(ctxt,
6453 xmlXPathCacheNewString(ctxt->context, str2));
6455 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt->context, s));
6456 ret = xmlXPathCompareValues(ctxt, inf, strict);
6462 xmlXPathReleaseObject(ctxt->context, arg);
6463 xmlXPathReleaseObject(ctxt->context, s);
6571 * @ctxt: the XPath Parser context
6591 xmlXPathCompareNodeSetValue(xmlXPathParserContextPtr ctxt, int inf, int strict,
6599 return(xmlXPathCompareNodeSetFloat(ctxt, inf, strict, arg, val));
6604 return(xmlXPathCompareNodeSetString(ctxt, inf, strict, arg, val));
6606 valuePush(ctxt, arg);
6607 xmlXPathBooleanFunction(ctxt, 1);
6608 valuePush(ctxt, val);
6609 return(xmlXPathCompareValues(ctxt, inf, strict));
6690 xmlXPathEqualNodeSetFloat(xmlXPathParserContextPtr ctxt,
6707 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, str2));
6709 xmlXPathNumberFunction(ctxt, 1);
6710 val = valuePop(ctxt);
6712 xmlXPathReleaseObject(ctxt->context, val);
6851 xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt,
6916 valuePush(ctxt, arg2);
6917 xmlXPathNumberFunction(ctxt, 1);
6918 arg2 = valuePop(ctxt);
6979 valuePush(ctxt, arg1);
6980 xmlXPathNumberFunction(ctxt, 1);
6981 arg1 = valuePop(ctxt);
7031 xmlXPathReleaseObject(ctxt->context, arg1);
7032 xmlXPathReleaseObject(ctxt->context, arg2);
7038 * @ctxt: the XPath Parser context
7045 xmlXPathEqualValues(xmlXPathParserContextPtr ctxt) {
7049 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0);
7050 arg2 = valuePop(ctxt);
7051 arg1 = valuePop(ctxt);
7054 xmlXPathReleaseObject(ctxt->context, arg1);
7056 xmlXPathReleaseObject(ctxt->context, arg2);
7101 ret = xmlXPathEqualNodeSetFloat(ctxt, arg1, arg2->floatval, 0);
7113 xmlXPathReleaseObject(ctxt->context, arg1);
7114 xmlXPathReleaseObject(ctxt->context, arg2);
7118 return (xmlXPathEqualValuesCommon(ctxt, arg1, arg2));
7123 * @ctxt: the XPath Parser context
7130 xmlXPathNotEqualValues(xmlXPathParserContextPtr ctxt) {
7134 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0);
7135 arg2 = valuePop(ctxt);
7136 arg1 = valuePop(ctxt);
7139 xmlXPathReleaseObject(ctxt->context, arg1);
7141 xmlXPathReleaseObject(ctxt->context, arg2);
7150 xmlXPathReleaseObject(ctxt->context, arg1);
7186 ret = xmlXPathEqualNodeSetFloat(ctxt, arg1, arg2->floatval, 1);
7198 xmlXPathReleaseObject(ctxt->context, arg1);
7199 xmlXPathReleaseObject(ctxt->context, arg2);
7203 return (!xmlXPathEqualValuesCommon(ctxt, arg1, arg2));
7208 * @ctxt: the XPath Parser context
7231 xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict) {
7235 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0);
7236 arg2 = valuePop(ctxt);
7237 arg1 = valuePop(ctxt);
7240 xmlXPathReleaseObject(ctxt->context, arg1);
7242 xmlXPathReleaseObject(ctxt->context, arg2);
7258 ret = xmlXPathCompareNodeSetValue(ctxt, inf, strict,
7261 ret = xmlXPathCompareNodeSetValue(ctxt, !inf, strict,
7269 valuePush(ctxt, arg1);
7270 xmlXPathNumberFunction(ctxt, 1);
7271 arg1 = valuePop(ctxt);
7279 valuePush(ctxt, arg2);
7280 xmlXPathNumberFunction(ctxt, 1);
7281 arg2 = valuePop(ctxt);
7284 xmlXPathReleaseObject(ctxt->context, arg1);
7285 xmlXPathReleaseObject(ctxt->context, arg2);
7337 xmlXPathReleaseObject(ctxt->context, arg1);
7338 xmlXPathReleaseObject(ctxt->context, arg2);
7344 * @ctxt: the XPath Parser context
7351 xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt) {
7352 if ((ctxt == NULL) || (ctxt->context == NULL)) return;
7355 if (xmlXPathIsNaN(ctxt->value->floatval))
7356 ctxt->value->floatval=xmlXPathNAN;
7357 else if (xmlXPathIsInf(ctxt->value->floatval) == 1)
7358 ctxt->value->floatval=xmlXPathNINF;
7359 else if (xmlXPathIsInf(ctxt->value->floatval) == -1)
7360 ctxt->value->floatval=xmlXPathPINF;
7361 else if (ctxt->value->floatval == 0) {
7362 if (xmlXPathGetSign(ctxt->value->floatval) == 0)
7363 ctxt->value->floatval = xmlXPathNZERO;
7365 ctxt->value->floatval = 0;
7368 ctxt->value->floatval = - ctxt->value->floatval;
7373 * @ctxt: the XPath Parser context
7380 xmlXPathAddValues(xmlXPathParserContextPtr ctxt) {
7384 arg = valuePop(ctxt);
7388 xmlXPathReleaseObject(ctxt->context, arg);
7391 ctxt->value->floatval += val;
7396 * @ctxt: the XPath Parser context
7403 xmlXPathSubValues(xmlXPathParserContextPtr ctxt) {
7407 arg = valuePop(ctxt);
7411 xmlXPathReleaseObject(ctxt->context, arg);
7414 ctxt->value->floatval -= val;
7419 * @ctxt: the XPath Parser context
7426 xmlXPathMultValues(xmlXPathParserContextPtr ctxt) {
7430 arg = valuePop(ctxt);
7434 xmlXPathReleaseObject(ctxt->context, arg);
7437 ctxt->value->floatval *= val;
7442 * @ctxt: the XPath Parser context
7449 xmlXPathDivValues(xmlXPathParserContextPtr ctxt) {
7453 arg = valuePop(ctxt);
7457 xmlXPathReleaseObject(ctxt->context, arg);
7460 if (xmlXPathIsNaN(val) || xmlXPathIsNaN(ctxt->value->floatval))
7461 ctxt->value->floatval = xmlXPathNAN;
7463 if (ctxt->value->floatval == 0)
7464 ctxt->value->floatval = xmlXPathNAN;
7465 else if (ctxt->value->floatval > 0)
7466 ctxt->value->floatval = xmlXPathNINF;
7467 else if (ctxt->value->floatval < 0)
7468 ctxt->value->floatval = xmlXPathPINF;
7471 if (ctxt->value->floatval == 0)
7472 ctxt->value->floatval = xmlXPathNAN;
7473 else if (ctxt->value->floatval > 0)
7474 ctxt->value->floatval = xmlXPathPINF;
7475 else if (ctxt->value->floatval < 0)
7476 ctxt->value->floatval = xmlXPathNINF;
7478 ctxt->value->floatval /= val;
7483 * @ctxt: the XPath Parser context
7490 xmlXPathModValues(xmlXPathParserContextPtr ctxt) {
7494 arg = valuePop(ctxt);
7498 xmlXPathReleaseObject(ctxt->context, arg);
7501 arg1 = ctxt->value->floatval;
7503 ctxt->value->floatval = xmlXPathNAN;
7505 ctxt->value->floatval = fmod(arg1, arg2);
7521 (xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
7543 * @ctxt: the XPath Parser context
7552 xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7553 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7555 return(ctxt->context->node);
7561 * @ctxt: the XPath Parser context
7570 xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7571 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7573 if (ctxt->context->node == NULL) return(NULL);
7574 switch (ctxt->context->node->type) {
7584 return(ctxt->context->node->children);
7592 return(((xmlDocPtr) ctxt->context->node)->children);
7612 * @ctxt: the XPath Parser context
7621 xmlXPathNextChildElement(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7622 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7624 cur = ctxt->context->node;
7687 * @ctxt: the XPath Parser context
7763 * @ctxt: the XPath Parser context
7773 xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7774 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7776 if (ctxt->context->node == NULL)
7778 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
7779 (ctxt->context->node->type == XML_NAMESPACE_DECL))
7782 if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc)
7783 return(ctxt->context->doc->children);
7784 return(ctxt->context->node->children);
7801 if (cur == ctxt->context->node) return(NULL);
7813 if (cur == ctxt->context->node) return(NULL);
7824 * @ctxt: the XPath Parser context
7836 xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7837 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7839 if (ctxt->context->node == NULL)
7841 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
7842 (ctxt->context->node->type == XML_NAMESPACE_DECL))
7844 return(ctxt->context->node);
7847 return(xmlXPathNextDescendant(ctxt, cur));
7852 * @ctxt: the XPath Parser context
7861 xmlXPathNextParent(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7862 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7869 if (ctxt->context->node == NULL) return(NULL);
7870 switch (ctxt->context->node->type) {
7885 if (ctxt->context->node->parent == NULL)
7886 return((xmlNodePtr) ctxt->context->doc);
7887 if ((ctxt->context->node->parent->type == XML_ELEMENT_NODE) &&
7888 ((ctxt->context->node->parent->name[0] == ' ') ||
7889 (xmlStrEqual(ctxt->context->node->parent->name,
7892 return(ctxt->context->node->parent);
7894 xmlAttrPtr att = (xmlAttrPtr) ctxt->context->node;
7907 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node;
7921 * @ctxt: the XPath Parser context
7934 xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
7935 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
7942 if (ctxt->context->node == NULL) return(NULL);
7943 switch (ctxt->context->node->type) {
7958 if (ctxt->context->node->parent == NULL)
7959 return((xmlNodePtr) ctxt->context->doc);
7960 if ((ctxt->context->node->parent->type == XML_ELEMENT_NODE) &&
7961 ((ctxt->context->node->parent->name[0] == ' ') ||
7962 (xmlStrEqual(ctxt->context->node->parent->name,
7965 return(ctxt->context->node->parent);
7967 xmlAttrPtr tmp = (xmlAttrPtr) ctxt->context->node;
7980 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node;
7991 if (cur == ctxt->context->doc->children)
7992 return((xmlNodePtr) ctxt->context->doc);
7993 if (cur == (xmlNodePtr) ctxt->context->doc)
8019 xmlAttrPtr att = (xmlAttrPtr) ctxt->context->node;
8024 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node;
8046 * @ctxt: the XPath Parser context
8058 xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
8059 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8061 return(ctxt->context->node);
8062 return(xmlXPathNextAncestor(ctxt, cur));
8067 * @ctxt: the XPath Parser context
8077 xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
8078 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8079 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
8080 (ctxt->context->node->type == XML_NAMESPACE_DECL))
8082 if (cur == (xmlNodePtr) ctxt->context->doc)
8085 return(ctxt->context->node->next);
8091 * @ctxt: the XPath Parser context
8102 xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
8103 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8104 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
8105 (ctxt->context->node->type == XML_NAMESPACE_DECL))
8107 if (cur == (xmlNodePtr) ctxt->context->doc)
8110 return(ctxt->context->node->prev);
8114 return(ctxt->context->node->prev);
8121 * @ctxt: the XPath Parser context
8133 xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
8134 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8140 cur = ctxt->context->node;
8151 if (cur == (xmlNodePtr) ctxt->context->doc) return(NULL);
8184 * @ctxt: the XPath Parser context
8196 xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur)
8198 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8200 cur = ctxt->context->node;
8219 if (cur == ctxt->context->doc->children)
8221 } while (xmlXPathIsAncestor(cur, ctxt->context->node));
8227 * @ctxt: the XPath Parser context
8236 * state kept in the parser context: ctxt->ancestor.
8241 xmlXPathNextPrecedingInternal(xmlXPathParserContextPtr ctxt,
8244 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8246 cur = ctxt->context->node;
8251 ctxt->ancestor = cur->parent;
8259 if (cur == ctxt->context->doc->children)
8261 if (cur != ctxt->ancestor)
8263 ctxt->ancestor = cur->parent;
8273 * @ctxt: the XPath Parser context
8286 xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
8287 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8288 if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL);
8289 if (ctxt->context->tmpNsList == NULL && cur != (xmlNodePtr) xmlXPathXMLNamespace) {
8290 if (ctxt->context->tmpNsList != NULL)
8291 xmlFree(ctxt->context->tmpNsList);
8292 ctxt->context->tmpNsList =
8293 xmlGetNsList(ctxt->context->doc, ctxt->context->node);
8294 ctxt->context->tmpNsNr = 0;
8295 if (ctxt->context->tmpNsList != NULL) {
8296 while (ctxt->context->tmpNsList[ctxt->context->tmpNsNr] != NULL) {
8297 ctxt->context->tmpNsNr++;
8302 if (ctxt->context->tmpNsNr > 0) {
8303 return (xmlNodePtr)ctxt->context->tmpNsList[--ctxt->context->tmpNsNr];
8305 if (ctxt->context->tmpNsList != NULL)
8306 xmlFree(ctxt->context->tmpNsList);
8307 ctxt->context->tmpNsList = NULL;
8314 * @ctxt: the XPath Parser context
8323 xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
8324 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
8325 if (ctxt->context->node == NULL)
8327 if (ctxt->context->node->type != XML_ELEMENT_NODE)
8330 if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc)
8332 return((xmlNodePtr)ctxt->context->node->properties);
8354 * @ctxt: the XPath Parser context
8359 xmlXPathRoot(xmlXPathParserContextPtr ctxt) {
8360 if ((ctxt == NULL) || (ctxt->context == NULL))
8362 ctxt->context->node = (xmlNodePtr) ctxt->context->doc;
8363 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
8364 ctxt->context->node));
8377 * @ctxt: the XPath Parser context
8385 xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8387 if (ctxt->context->contextSize >= 0) {
8388 valuePush(ctxt,
8389 xmlXPathCacheNewFloat(ctxt->context,
8390 (double) ctxt->context->contextSize));
8393 "last() : %d\n", ctxt->context->contextSize);
8402 * @ctxt: the XPath Parser context
8412 xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8414 if (ctxt->context->proximityPosition >= 0) {
8415 valuePush(ctxt,
8416 xmlXPathCacheNewFloat(ctxt->context,
8417 (double) ctxt->context->proximityPosition));
8420 ctxt->context->proximityPosition);
8429 * @ctxt: the XPath Parser context
8436 xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8440 if ((ctxt->value == NULL) ||
8441 ((ctxt->value->type != XPATH_NODESET) &&
8442 (ctxt->value->type != XPATH_XSLT_TREE)))
8444 cur = valuePop(ctxt);
8447 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, (double) 0));
8449 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context,
8454 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, (double) 0));
8467 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, (double) i));
8470 xmlXPathReleaseObject(ctxt->context, cur);
8530 * @ctxt: the XPath Parser context
8547 xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8553 obj = valuePop(ctxt);
8565 ns = xmlXPathGetElementsByIds(ctxt->context->doc, tokens);
8572 xmlXPathReleaseObject(ctxt->context, obj);
8573 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt->context, ret));
8576 obj = xmlXPathCacheConvertString(ctxt->context, obj);
8577 ret = xmlXPathGetElementsByIds(ctxt->context->doc, obj->stringval);
8578 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt->context, ret));
8579 xmlXPathReleaseObject(ctxt->context, obj);
8585 * @ctxt: the XPath Parser context
8597 xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8600 if (ctxt == NULL) return;
8603 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
8604 ctxt->context->node));
8609 if ((ctxt->value == NULL) ||
8610 ((ctxt->value->type != XPATH_NODESET) &&
8611 (ctxt->value->type != XPATH_XSLT_TREE)))
8613 cur = valuePop(ctxt);
8616 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8624 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8626 valuePush(ctxt,
8627 xmlXPathCacheNewString(ctxt->context,
8631 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
8635 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8638 xmlXPathReleaseObject(ctxt->context, cur);
8643 * @ctxt: the XPath Parser context
8656 xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8659 if (ctxt == NULL) return;
8662 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
8663 ctxt->context->node));
8667 if ((ctxt->value == NULL) ||
8668 ((ctxt->value->type != XPATH_NODESET) &&
8669 (ctxt->value->type != XPATH_XSLT_TREE)))
8671 cur = valuePop(ctxt);
8674 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8681 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8683 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
8687 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8690 xmlXPathReleaseObject(ctxt->context, cur);
8695 * @ctxt: the XPath Parser context
8716 xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs)
8721 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
8722 ctxt->context->node));
8727 if ((ctxt->value == NULL) ||
8728 ((ctxt->value->type != XPATH_NODESET) &&
8729 (ctxt->value->type != XPATH_XSLT_TREE)))
8731 cur = valuePop(ctxt);
8734 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
8742 valuePush(ctxt,
8743 xmlXPathCacheNewCString(ctxt->context, ""));
8746 valuePush(ctxt,
8747 xmlXPathCacheNewString(ctxt->context,
8760 valuePush(ctxt, xmlXPathCacheWrapString(
8761 ctxt->context, fullname));
8765 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
8767 xmlXPathLocalNameFunction(ctxt, 1);
8770 xmlXPathReleaseObject(ctxt->context, cur);
8776 * @ctxt: the XPath Parser context
8811 xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8814 if (ctxt == NULL) return;
8816 valuePush(ctxt,
8817 xmlXPathCacheWrapString(ctxt->context,
8818 xmlXPathCastNodeToString(ctxt->context->node)));
8823 cur = valuePop(ctxt);
8825 valuePush(ctxt, xmlXPathCacheConvertString(ctxt->context, cur));
8830 * @ctxt: the XPath Parser context
8841 xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8845 if ((ctxt == NULL) || (ctxt->context == NULL))
8847 if (ctxt->context->node == NULL) {
8848 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, 0));
8852 content = xmlXPathCastNodeToString(ctxt->context->node);
8853 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context,
8862 cur = valuePop(ctxt);
8863 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context,
8865 xmlXPathReleaseObject(ctxt->context, cur);
8870 * @ctxt: the XPath Parser context
8878 xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8882 if (ctxt == NULL) return;
8888 cur = valuePop(ctxt);
8890 xmlXPathReleaseObject(ctxt->context, cur);
8897 newobj = valuePop(ctxt);
8899 xmlXPathReleaseObject(ctxt->context, newobj);
8900 xmlXPathReleaseObject(ctxt->context, cur);
8906 xmlXPathReleaseObject(ctxt->context, newobj);
8909 valuePush(ctxt, cur);
8914 * @ctxt: the XPath Parser context
8923 xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8929 needle = valuePop(ctxt);
8931 hay = valuePop(ctxt);
8934 xmlXPathReleaseObject(ctxt->context, hay);
8935 xmlXPathReleaseObject(ctxt->context, needle);
8939 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 1));
8941 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0));
8942 xmlXPathReleaseObject(ctxt->context, hay);
8943 xmlXPathReleaseObject(ctxt->context, needle);
8948 * @ctxt: the XPath Parser context
8957 xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs) {
8964 needle = valuePop(ctxt);
8966 hay = valuePop(ctxt);
8969 xmlXPathReleaseObject(ctxt->context, hay);
8970 xmlXPathReleaseObject(ctxt->context, needle);
8975 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0));
8977 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 1));
8978 xmlXPathReleaseObject(ctxt->context, hay);
8979 xmlXPathReleaseObject(ctxt->context, needle);
8984 * @ctxt: the XPath Parser context
9011 xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9029 len = valuePop(ctxt);
9031 xmlXPathReleaseObject(ctxt->context, len);
9036 start = valuePop(ctxt);
9038 xmlXPathReleaseObject(ctxt->context, start);
9041 str = valuePop(ctxt);
9098 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, ""));
9100 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, ret));
9103 xmlXPathReleaseObject(ctxt->context, str);
9108 * @ctxt: the XPath Parser context
9120 xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9129 find = valuePop(ctxt);
9131 str = valuePop(ctxt);
9140 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
9144 xmlXPathReleaseObject(ctxt->context, str);
9145 xmlXPathReleaseObject(ctxt->context, find);
9150 * @ctxt: the XPath Parser context
9163 xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9172 find = valuePop(ctxt);
9174 str = valuePop(ctxt);
9184 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
9188 xmlXPathReleaseObject(ctxt->context, str);
9189 xmlXPathReleaseObject(ctxt->context, find);
9194 * @ctxt: the XPath Parser context
9207 xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9213 if (ctxt == NULL) return;
9216 valuePush(ctxt,
9217 xmlXPathCacheWrapString(ctxt->context,
9218 xmlXPathCastNodeToString(ctxt->context->node)));
9225 obj = valuePop(ctxt);
9249 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
9253 xmlXPathReleaseObject(ctxt->context, obj);
9258 * @ctxt: the XPath Parser context
9278 xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9291 to = valuePop(ctxt);
9293 from = valuePop(ctxt);
9295 str = valuePop(ctxt);
9334 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
9337 xmlXPathReleaseObject(ctxt->context, str);
9338 xmlXPathReleaseObject(ctxt->context, from);
9339 xmlXPathReleaseObject(ctxt->context, to);
9344 * @ctxt: the XPath Parser context
9356 xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9360 cur = valuePop(ctxt);
9362 cur = xmlXPathCacheConvertBoolean(ctxt->context, cur);
9363 valuePush(ctxt, cur);
9368 * @ctxt: the XPath Parser context
9377 xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9381 ctxt->value->boolval = ! ctxt->value->boolval;
9386 * @ctxt: the XPath Parser context
9393 xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9395 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 1));
9400 * @ctxt: the XPath Parser context
9407 xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9409 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0));
9414 * @ctxt: the XPath Parser context
9434 xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9444 val = valuePop(ctxt);
9446 theLang = xmlNodeGetLang(ctxt->context->node);
9458 xmlXPathReleaseObject(ctxt->context, val);
9459 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, ret));
9464 * @ctxt: the XPath Parser context
9471 xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9475 if (ctxt == NULL) return;
9477 if (ctxt->context->node == NULL) {
9478 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, 0.0));
9480 xmlChar* content = xmlNodeGetContent(ctxt->context->node);
9483 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, res));
9490 cur = valuePop(ctxt);
9491 valuePush(ctxt, xmlXPathCacheConvertNumber(ctxt->context, cur));
9496 * @ctxt: the XPath Parser context
9505 xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9511 if ((ctxt->value == NULL) ||
9512 ((ctxt->value->type != XPATH_NODESET) &&
9513 (ctxt->value->type != XPATH_XSLT_TREE)))
9515 cur = valuePop(ctxt);
9522 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, res));
9523 xmlXPathReleaseObject(ctxt->context, cur);
9540 * @ctxt: the XPath Parser context
9549 xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9556 XTRUNC(f, ctxt->value->floatval);
9557 if (f != ctxt->value->floatval) {
9558 if (ctxt->value->floatval > 0)
9559 ctxt->value->floatval = f;
9561 ctxt->value->floatval = f - 1;
9567 * @ctxt: the XPath Parser context
9576 xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9584 ctxt->value->floatval = ceil(ctxt->value->floatval);
9586 XTRUNC(f, ctxt->value->floatval);
9587 if (f != ctxt->value->floatval) {
9588 if (ctxt->value->floatval > 0)
9589 ctxt->value->floatval = f + 1;
9591 if (ctxt->value->floatval < 0 && f == 0)
9592 ctxt->value->floatval = xmlXPathNZERO;
9594 ctxt->value->floatval = f;
9603 * @ctxt: the XPath Parser context
9613 xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs) {
9620 if ((xmlXPathIsNaN(ctxt->value->floatval)) ||
9621 (xmlXPathIsInf(ctxt->value->floatval) == 1) ||
9622 (xmlXPathIsInf(ctxt->value->floatval) == -1) ||
9623 (ctxt->value->floatval == 0.0))
9626 XTRUNC(f, ctxt->value->floatval);
9627 if (ctxt->value->floatval < 0) {
9628 if (ctxt->value->floatval < f - 0.5)
9629 ctxt->value->floatval = f - 1;
9631 ctxt->value->floatval = f;
9632 if (ctxt->value->floatval == 0)
9633 ctxt->value->floatval = xmlXPathNZERO;
9635 if (ctxt->value->floatval < f + 0.5)
9636 ctxt->value->floatval = f;
9638 ctxt->value->floatval = f + 1;
9652 static void xmlXPathCompileExpr(xmlXPathParserContextPtr ctxt, int sort);
9653 static void xmlXPathCompPredicate(xmlXPathParserContextPtr ctxt, int filter);
9654 static void xmlXPathCompLocationPath(xmlXPathParserContextPtr ctxt);
9655 static void xmlXPathCompRelativeLocationPath(xmlXPathParserContextPtr ctxt);
9656 static xmlChar * xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt,
9661 * @ctxt: the XPath parser context
9672 xmlXPathCurrentChar(xmlXPathParserContextPtr ctxt, int *len) {
9677 if (ctxt == NULL)
9679 cur = ctxt->cur;
9746 * @ctxt: the XPath Parser context
9759 xmlXPathParseNCName(xmlXPathParserContextPtr ctxt) {
9764 if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL);
9768 in = ctxt->cur;
9782 count = in - ctxt->cur;
9785 ret = xmlStrndup(ctxt->cur, count);
9786 ctxt->cur = in;
9790 return(xmlXPathParseNameComplex(ctxt, 0));
9796 * @ctxt: the XPath Parser context
9812 xmlXPathParseQName(xmlXPathParserContextPtr ctxt, xmlChar **prefix) {
9816 ret = xmlXPathParseNCName(ctxt);
9820 ret = xmlXPathParseNCName(ctxt);
9827 * @ctxt: the XPath Parser context
9840 xmlXPathParseName(xmlXPathParserContextPtr ctxt) {
9845 if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL);
9849 in = ctxt->cur;
9861 count = in - ctxt->cur;
9862 ret = xmlStrndup(ctxt->cur, count);
9863 ctxt->cur = in;
9867 return(xmlXPathParseNameComplex(ctxt, 1));
9871 xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) {
10055 * @ctxt: the XPath Parser context
10065 xmlXPathCompNumber(xmlXPathParserContextPtr ctxt)
10131 xmlXPathCacheNewFloat(ctxt->context, ret), NULL);
10136 * @ctxt: the XPath Parser context
10146 xmlXPathParseLiteral(xmlXPathParserContextPtr ctxt) {
10180 * @ctxt: the XPath Parser context
10190 xmlXPathCompLiteral(xmlXPathParserContextPtr ctxt) {
10221 xmlXPathCacheNewString(ctxt->context, ret), NULL);
10227 * @ctxt: the XPath Parser context
10243 xmlXPathCompVariableReference(xmlXPathParserContextPtr ctxt) {
10252 name = xmlXPathParseQName(ctxt, &prefix);
10256 ctxt->comp->last = -1;
10260 if ((ctxt->context != NULL) && (ctxt->context->flags & XML_XPATH_NOVAR)) {
10296 * @ctxt: the XPath Parser context
10305 xmlXPathCompFunctionCall(xmlXPathParserContextPtr ctxt) {
10311 name = xmlXPathParseQName(ctxt, &prefix);
10339 ctxt->comp->last = -1;
10342 int op1 = ctxt->comp->last;
10343 ctxt->comp->last = -1;
10344 xmlXPathCompileExpr(ctxt, sort);
10346 PUSH_BINARY_EXPR(XPATH_OP_ARG, op1, ctxt->comp->last, 0, 0);
10364 * @ctxt: the XPath Parser context
10375 xmlXPathCompPrimaryExpr(xmlXPathParserContextPtr ctxt) {
10377 if (CUR == '$') xmlXPathCompVariableReference(ctxt);
10381 xmlXPathCompileExpr(ctxt, 1);
10389 xmlXPathCompNumber(ctxt);
10391 xmlXPathCompLiteral(ctxt);
10393 xmlXPathCompFunctionCall(ctxt);
10400 * @ctxt: the XPath Parser context
10414 xmlXPathCompFilterExpr(xmlXPathParserContextPtr ctxt) {
10415 xmlXPathCompPrimaryExpr(ctxt);
10420 xmlXPathCompPredicate(ctxt, 1);
10429 * @ctxt: the XPath Parser context
10445 xmlXPathScanName(xmlXPathParserContextPtr ctxt) {
10451 cur = ctxt->cur;
10470 ret = xmlStrndup(cur, ctxt->cur - cur);
10471 ctxt->cur = cur;
10477 * @ctxt: the XPath Parser context
10494 xmlXPathCompPathExpr(xmlXPathParserContextPtr ctxt) {
10529 name = xmlXPathScanName(ctxt);
10615 xmlXPathCompLocationPath(ctxt);
10617 xmlXPathCompFilterExpr(ctxt);
10625 PUSH_UNARY_EXPR(XPATH_OP_RESET, ctxt->comp->last, 1, 0);
10627 xmlXPathCompRelativeLocationPath(ctxt);
10629 xmlXPathCompRelativeLocationPath(ctxt);
10637 * @ctxt: the XPath Parser context
10646 xmlXPathCompUnionExpr(xmlXPathParserContextPtr ctxt) {
10647 xmlXPathCompPathExpr(ctxt);
10651 int op1 = ctxt->comp->last;
10656 xmlXPathCompPathExpr(ctxt);
10658 PUSH_BINARY_EXPR(XPATH_OP_UNION, op1, ctxt->comp->last, 0, 0);
10666 * @ctxt: the XPath Parser context
10675 xmlXPathCompUnaryExpr(xmlXPathParserContextPtr ctxt) {
10687 xmlXPathCompUnionExpr(ctxt);
10691 PUSH_UNARY_EXPR(XPATH_OP_PLUS, ctxt->comp->last, 2, 0);
10693 PUSH_UNARY_EXPR(XPATH_OP_PLUS, ctxt->comp->last, 3, 0);
10699 * @ctxt: the XPath Parser context
10711 xmlXPathCompMultiplicativeExpr(xmlXPathParserContextPtr ctxt) {
10712 xmlXPathCompUnaryExpr(ctxt);
10719 int op1 = ctxt->comp->last;
10732 xmlXPathCompUnaryExpr(ctxt);
10734 PUSH_BINARY_EXPR(XPATH_OP_MULT, op1, ctxt->comp->last, op, 0);
10741 * @ctxt: the XPath Parser context
10751 xmlXPathCompAdditiveExpr(xmlXPathParserContextPtr ctxt) {
10753 xmlXPathCompMultiplicativeExpr(ctxt);
10758 int op1 = ctxt->comp->last;
10764 xmlXPathCompMultiplicativeExpr(ctxt);
10766 PUSH_BINARY_EXPR(XPATH_OP_PLUS, op1, ctxt->comp->last, plus, 0);
10773 * @ctxt: the XPath Parser context
10790 xmlXPathCompRelationalExpr(xmlXPathParserContextPtr ctxt) {
10791 xmlXPathCompAdditiveExpr(ctxt);
10799 int op1 = ctxt->comp->last;
10808 xmlXPathCompAdditiveExpr(ctxt);
10810 PUSH_BINARY_EXPR(XPATH_OP_CMP, op1, ctxt->comp->last, inf, strict);
10817 * @ctxt: the XPath Parser context
10832 xmlXPathCompEqualityExpr(xmlXPathParserContextPtr ctxt) {
10833 xmlXPathCompRelationalExpr(ctxt);
10838 int op1 = ctxt->comp->last;
10845 xmlXPathCompRelationalExpr(ctxt);
10847 PUSH_BINARY_EXPR(XPATH_OP_EQUAL, op1, ctxt->comp->last, eq, 0);
10854 * @ctxt: the XPath Parser context
10863 xmlXPathCompAndExpr(xmlXPathParserContextPtr ctxt) {
10864 xmlXPathCompEqualityExpr(ctxt);
10868 int op1 = ctxt->comp->last;
10871 xmlXPathCompEqualityExpr(ctxt);
10873 PUSH_BINARY_EXPR(XPATH_OP_AND, op1, ctxt->comp->last, 0, 0);
10880 * @ctxt: the XPath Parser context
10889 xmlXPathCompileExpr(xmlXPathParserContextPtr ctxt, int sort) {
10890 xmlXPathCompAndExpr(ctxt);
10894 int op1 = ctxt->comp->last;
10897 xmlXPathCompAndExpr(ctxt);
10899 PUSH_BINARY_EXPR(XPATH_OP_OR, op1, ctxt->comp->last, 0, 0);
10900 op1 = ctxt->comp->nbStep;
10903 if ((sort) && (ctxt->comp->steps[ctxt->comp->last].op != XPATH_OP_VALUE)) {
10910 PUSH_UNARY_EXPR(XPATH_OP_SORT, ctxt->comp->last , 0, 0);
10916 * @ctxt: the XPath Parser context
10925 xmlXPathCompPredicate(xmlXPathParserContextPtr ctxt, int filter) {
10926 int op1 = ctxt->comp->last;
10935 ctxt->comp->last = -1;
10946 xmlXPathCompileExpr(ctxt, 0);
10948 xmlXPathCompileExpr(ctxt, 1);
10956 PUSH_BINARY_EXPR(XPATH_OP_FILTER, op1, ctxt->comp->last, 0, 0);
10958 PUSH_BINARY_EXPR(XPATH_OP_PREDICATE, op1, ctxt->comp->last, 0, 0);
10966 * @ctxt: the XPath Parser context
10986 xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test,
11010 name = xmlXPathParseNCName(ctxt);
11047 name = xmlXPathParseLiteral(ctxt);
11073 *prefix = xmlXPathNsLookup(ctxt->context, name);
11092 name = xmlXPathParseNCName(ctxt);
11170 * @ctxt: the XPath Parser context
11201 xmlXPathCompStep(xmlXPathParserContextPtr ctxt) {
11228 if (ctxt->xptr) {
11229 name = xmlXPathParseNCName(ctxt);
11231 op2 = ctxt->comp->last;
11240 xmlXPathCompileExpr(ctxt, 1);
11241 /* PUSH_BINARY_EXPR(XPATH_OP_RANGETO, op2, ctxt->comp->last, 0, 0); */
11258 name = xmlXPathParseNCName(ctxt);
11284 name = xmlXPathCompNodeTest(ctxt, &test, &type, &prefix, name);
11288 if ((prefix != NULL) && (ctxt->context != NULL) &&
11289 (ctxt->context->flags & XML_XPATH_CHECKNS)) {
11290 if (xmlXPathNsLookup(ctxt->context, prefix) == NULL) {
11291 xmlXPathErr(ctxt, XPATH_UNDEF_PREFIX_ERROR);
11301 if (ctxt->value == NULL)
11303 else if (ctxt->value->nodesetval == NULL)
11306 xmlGenericErrorContextNodeSet(stdout, ctxt->value->nodesetval);
11312 op1 = ctxt->comp->last;
11313 ctxt->comp->last = -1;
11317 xmlXPathCompPredicate(ctxt, 0);
11325 PUSH_FULL_EXPR(XPATH_OP_COLLECT, op1, ctxt->comp->last, axis,
11331 if (ctxt->value == NULL)
11333 else if (ctxt->value->nodesetval == NULL)
11337 ctxt->value->nodesetval);
11343 * @ctxt: the XPath Parser context
11354 (xmlXPathParserContextPtr ctxt) {
11365 xmlXPathCompStep(ctxt);
11373 xmlXPathCompStep(ctxt);
11377 xmlXPathCompStep(ctxt);
11385 * @ctxt: the XPath Parser context
11405 xmlXPathCompLocationPath(xmlXPathParserContextPtr ctxt) {
11408 xmlXPathCompRelativeLocationPath(ctxt);
11416 xmlXPathCompRelativeLocationPath(ctxt);
11423 xmlXPathCompRelativeLocationPath(ctxt);
11436 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op);
11527 xmlXPathCompOpEvalPredicate(xmlXPathParserContextPtr ctxt,
11534 xmlXPathCompExprPtr comp = ctxt->comp;
11543 contextSize = xmlXPathCompOpEvalPredicate(ctxt,
11550 xmlXPathContextPtr xpctxt = ctxt->context;
11592 exprOp = &ctxt->comp->steps[op->ch2];
11621 valuePush(ctxt, contextObj);
11623 res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp, 1);
11625 if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1)) {
11641 if (ctxt->value == contextObj) {
11647 valuePop(ctxt);
11659 if (ctxt->value == contextObj)
11660 valuePop(ctxt);
11665 xmlXPathReleaseObject(ctxt->context, exprRes);
11679 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserContextPtr ctxt,
11688 xmlXPathCompExprPtr comp = ctxt->comp;
11694 contextSize = xmlXPathCompOpEvalPredicate(ctxt,
11719 xmlXPathContextPtr xpctxt = ctxt->context;
11738 exprOp = &ctxt->comp->steps[op->ch2];
11769 frame = xmlXPathSetFrame(ctxt);
11770 valuePush(ctxt, contextObj);
11771 res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp, 1);
11772 tmp = valuePop(ctxt);
11773 xmlXPathPopFrame(ctxt, frame);
11775 if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1)) {
11782 tmp = valuePop(ctxt);
11787 valuePush(ctxt, tmp);
11829 xmlXPathReleaseObject(ctxt->context, exprRes);
11832 if (ctxt->value == contextObj) {
11838 valuePop(ctxt);
11856 if (ctxt->value == contextObj)
11857 valuePop(ctxt);
11861 xmlXPathReleaseObject(ctxt->context, exprRes);
11875 xmlXPathIsPositionalPredicate(xmlXPathParserContextPtr ctxt,
11899 exprOp = &ctxt->comp->steps[op->ch2];
11930 xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
11996 xmlXPathContextPtr xpctxt = ctxt->context;
12000 obj = valuePop(ctxt);
12115 valuePush(ctxt, xmlXPathCacheWrapNodeSet(xpctxt, NULL));
12144 predOp = &ctxt->comp->steps[op->ch2];
12145 if (xmlXPathIsPositionalPredicate(ctxt, predOp, &maxPos)) {
12150 predOp = &ctxt->comp->steps[predOp->ch1];
12220 cur = next(ctxt, cur);
12453 * (E.g. ctxt->value->type == XPATH_LOCATIONSET)
12477 newSize = xmlXPathCompOpEvalPositionalPredicate(ctxt,
12480 newSize = xmlXPathCompOpEvalPredicate(ctxt,
12483 if (ctxt->error != XPATH_EXPRESSION_OK) {
12539 ctxt->value->boolval = 1;
12540 ctxt->value->user = obj->user;
12562 valuePush(ctxt, xmlXPathCacheWrapNodeSet(xpctxt, outSeq));
12578 xmlXPathCompOpEvalFilterFirst(xmlXPathParserContextPtr ctxt,
12583 * @ctxt: the XPath parser context with the compiled expression
12593 xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
12601 comp = ctxt->comp;
12607 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
12610 if ((ctxt->value != NULL)
12611 && (ctxt->value->type == XPATH_NODESET)
12612 && (ctxt->value->nodesetval != NULL)
12613 && (ctxt->value->nodesetval->nodeNr >= 1)) {
12624 if (ctxt->value->nodesetval->nodeNr > 1)
12625 xmlXPathNodeSetSort(ctxt->value->nodesetval);
12626 *first = ctxt->value->nodesetval->nodeTab[0];
12629 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch2],
12633 arg2 = valuePop(ctxt);
12636 arg1 = valuePop(ctxt);
12640 valuePush(ctxt, arg1);
12641 xmlXPathReleaseObject(ctxt->context, arg2);
12647 xmlXPathRoot(ctxt);
12651 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12654 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
12656 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
12657 ctxt->context->node));
12661 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12664 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
12666 ctxt->context->node = NULL;
12672 total = xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12675 total += xmlXPathNodeCollectAndTest(ctxt, op, first, NULL, 0);
12679 valuePush(ctxt,
12680 xmlXPathCacheObjectCopy(ctxt->context,
12686 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
12689 if ((ctxt->value != NULL)
12690 && (ctxt->value->type == XPATH_NODESET)
12691 && (ctxt->value->nodesetval != NULL)
12692 && (ctxt->value->nodesetval->nodeNr > 1))
12693 xmlXPathNodeSetSort(ctxt->value->nodesetval);
12697 total =+ xmlXPathCompOpEvalFilterFirst(ctxt, op, first);
12701 return (xmlXPathCompOpEval(ctxt, op));
12707 * @ctxt: the XPath parser context with the compiled expression
12717 xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
12729 comp = ctxt->comp;
12734 bakd = ctxt->context->doc;
12735 bak = ctxt->context->node;
12736 pp = ctxt->context->proximityPosition;
12737 cs = ctxt->context->contextSize;
12739 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], last);
12741 if ((ctxt->value != NULL)
12742 && (ctxt->value->type == XPATH_NODESET)
12743 && (ctxt->value->nodesetval != NULL)
12744 && (ctxt->value->nodesetval->nodeNr >= 1)) {
12748 if (ctxt->value->nodesetval->nodeNr > 1)
12749 xmlXPathNodeSetSort(ctxt->value->nodesetval);
12751 ctxt->value->nodesetval->nodeTab[ctxt->value->
12755 ctxt->context->doc = bakd;
12756 ctxt->context->node = bak;
12757 ctxt->context->proximityPosition = pp;
12758 ctxt->context->contextSize = cs;
12760 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch2], last);
12762 if ((ctxt->value != NULL)
12763 && (ctxt->value->type == XPATH_NODESET)
12764 && (ctxt->value->nodesetval != NULL)
12765 && (ctxt->value->nodesetval->nodeNr >= 1)) { /* TODO: NOP ? */
12768 arg2 = valuePop(ctxt);
12771 arg1 = valuePop(ctxt);
12775 valuePush(ctxt, arg1);
12776 xmlXPathReleaseObject(ctxt->context, arg2);
12782 xmlXPathRoot(ctxt);
12786 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12789 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
12791 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
12792 ctxt->context->node));
12796 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12799 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
12801 ctxt->context->node = NULL;
12807 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12810 total += xmlXPathNodeCollectAndTest(ctxt, op, NULL, last, 0);
12814 valuePush(ctxt,
12815 xmlXPathCacheObjectCopy(ctxt->context,
12821 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1],
12824 if ((ctxt->value != NULL)
12825 && (ctxt->value->type == XPATH_NODESET)
12826 && (ctxt->value->nodesetval != NULL)
12827 && (ctxt->value->nodesetval->nodeNr > 1))
12828 xmlXPathNodeSetSort(ctxt->value->nodesetval);
12831 return (xmlXPathCompOpEval(ctxt, op));
12837 xmlXPathCompOpEvalFilterFirst(xmlXPathParserContextPtr ctxt,
12850 comp = ctxt->comp;
12869 xmlXPathCompOpEvalLast(ctxt,
12877 if ((ctxt->value != NULL) &&
12878 (ctxt->value->type == XPATH_NODESET) &&
12879 (ctxt->value->nodesetval != NULL) &&
12880 (ctxt->value->nodesetval->nodeTab != NULL) &&
12881 (ctxt->value->nodesetval->nodeNr > 1)) {
12882 ctxt->value->nodesetval->nodeTab[0] =
12883 ctxt->value->nodesetval->nodeTab[ctxt->
12888 ctxt->value->nodesetval->nodeNr = 1;
12889 *first = *(ctxt->value->nodesetval->nodeTab);
12896 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
12900 if (ctxt->value == NULL)
12904 oldnode = ctxt->context->node;
12908 if (ctxt->value->type == XPATH_LOCATIONSET) {
12919 obj = valuePop(ctxt);
12921 ctxt->context->node = NULL;
12924 ctxt->context->contextSize = 0;
12925 ctxt->context->proximityPosition = 0;
12927 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
12928 res = valuePop(ctxt);
12930 xmlXPathReleaseObject(ctxt->context, res);
12932 valuePush(ctxt, obj);
12943 ctxt->context->node = oldlocset->locTab[i]->user;
12944 ctxt->context->contextSize = oldlocset->locNr;
12945 ctxt->context->proximityPosition = i + 1;
12947 tmp = xmlXPathCacheNewNodeSet(ctxt->context,
12948 ctxt->context->node);
12951 ctxt->context->node);
12953 valuePush(ctxt, tmp);
12955 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
12956 if (ctxt->error != XPATH_EXPRESSION_OK) {
12964 res = valuePop(ctxt);
12965 if (xmlXPathEvaluatePredicateResult(ctxt, res)) {
12967 xmlXPathCacheObjectCopy(ctxt->context,
12974 xmlXPathReleaseObject(ctxt->context, res);
12976 if (ctxt->value == tmp) {
12977 valuePop(ctxt);
12986 ctxt->context->node = NULL;
12996 xmlXPathReleaseObject(ctxt->context, tmp);
13001 xmlXPathReleaseObject(ctxt->context, obj);
13002 ctxt->context->node = NULL;
13003 ctxt->context->contextSize = -1;
13004 ctxt->context->proximityPosition = -1;
13005 valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset));
13006 ctxt->context->node = oldnode;
13017 obj = valuePop(ctxt);
13020 oldnode = ctxt->context->node;
13021 oldDoc = ctxt->context->doc;
13022 ctxt->context->node = NULL;
13025 ctxt->context->contextSize = 0;
13026 ctxt->context->proximityPosition = 0;
13030 xmlXPathCompOpEval(ctxt,
13033 res = valuePop(ctxt);
13037 valuePush(ctxt, obj);
13038 ctxt->context->node = oldnode;
13055 ctxt->context->node = oldset->nodeTab[i];
13058 ctxt->context->doc = oldset->nodeTab[i]->doc;
13060 tmp = xmlXPathCacheNewNodeSet(ctxt->context,
13061 ctxt->context->node);
13064 ctxt->context->node);
13066 valuePush(ctxt, tmp);
13067 ctxt->context->contextSize = oldset->nodeNr;
13068 ctxt->context->proximityPosition = i + 1;
13070 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13071 if (ctxt->error != XPATH_EXPRESSION_OK) {
13080 res = valuePop(ctxt);
13081 if (xmlXPathEvaluatePredicateResult(ctxt, res)) {
13088 xmlXPathReleaseObject(ctxt->context, res);
13090 if (ctxt->value == tmp) {
13091 valuePop(ctxt);
13100 ctxt->context->node = NULL;
13110 xmlXPathReleaseObject(ctxt->context, tmp);
13115 xmlXPathReleaseObject(ctxt->context, obj);
13116 ctxt->context->node = NULL;
13117 ctxt->context->contextSize = -1;
13118 ctxt->context->proximityPosition = -1;
13120 ctxt->context->doc = oldDoc;
13121 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt->context, newset));
13123 ctxt->context->node = oldnode;
13130 * @ctxt: the XPath parser context with the compiled expression
13137 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
13149 comp = ctxt->comp;
13154 bakd = ctxt->context->doc;
13155 bak = ctxt->context->node;
13156 pp = ctxt->context->proximityPosition;
13157 cs = ctxt->context->contextSize;
13158 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13160 xmlXPathBooleanFunction(ctxt, 1);
13161 if ((ctxt->value == NULL) || (ctxt->value->boolval == 0))
13163 arg2 = valuePop(ctxt);
13164 ctxt->context->doc = bakd;
13165 ctxt->context->node = bak;
13166 ctxt->context->proximityPosition = pp;
13167 ctxt->context->contextSize = cs;
13168 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13169 if (ctxt->error) {
13173 xmlXPathBooleanFunction(ctxt, 1);
13174 arg1 = valuePop(ctxt);
13176 valuePush(ctxt, arg1);
13177 xmlXPathReleaseObject(ctxt->context, arg2);
13180 bakd = ctxt->context->doc;
13181 bak = ctxt->context->node;
13182 pp = ctxt->context->proximityPosition;
13183 cs = ctxt->context->contextSize;
13184 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13186 xmlXPathBooleanFunction(ctxt, 1);
13187 if ((ctxt->value == NULL) || (ctxt->value->boolval == 1))
13189 arg2 = valuePop(ctxt);
13190 ctxt->context->doc = bakd;
13191 ctxt->context->node = bak;
13192 ctxt->context->proximityPosition = pp;
13193 ctxt->context->contextSize = cs;
13194 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13195 if (ctxt->error) {
13199 xmlXPathBooleanFunction(ctxt, 1);
13200 arg1 = valuePop(ctxt);
13202 valuePush(ctxt, arg1);
13203 xmlXPathReleaseObject(ctxt->context, arg2);
13206 bakd = ctxt->context->doc;
13207 bak = ctxt->context->node;
13208 pp = ctxt->context->proximityPosition;
13209 cs = ctxt->context->contextSize;
13210 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13212 ctxt->context->doc = bakd;
13213 ctxt->context->node = bak;
13214 ctxt->context->proximityPosition = pp;
13215 ctxt->context->contextSize = cs;
13216 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13219 equal = xmlXPathEqualValues(ctxt);
13221 equal = xmlXPathNotEqualValues(ctxt);
13222 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, equal));
13225 bakd = ctxt->context->doc;
13226 bak = ctxt->context->node;
13227 pp = ctxt->context->proximityPosition;
13228 cs = ctxt->context->contextSize;
13229 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13231 ctxt->context->doc = bakd;
13232 ctxt->context->node = bak;
13233 ctxt->context->proximityPosition = pp;
13234 ctxt->context->contextSize = cs;
13235 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13237 ret = xmlXPathCompareValues(ctxt, op->value, op->value2);
13238 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, ret));
13241 bakd = ctxt->context->doc;
13242 bak = ctxt->context->node;
13243 pp = ctxt->context->proximityPosition;
13244 cs = ctxt->context->contextSize;
13245 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13248 ctxt->context->doc = bakd;
13249 ctxt->context->node = bak;
13250 ctxt->context->proximityPosition = pp;
13251 ctxt->context->contextSize = cs;
13252 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13256 xmlXPathSubValues(ctxt);
13258 xmlXPathAddValues(ctxt);
13260 xmlXPathValueFlipSign(ctxt);
13267 bakd = ctxt->context->doc;
13268 bak = ctxt->context->node;
13269 pp = ctxt->context->proximityPosition;
13270 cs = ctxt->context->contextSize;
13271 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13273 ctxt->context->doc = bakd;
13274 ctxt->context->node = bak;
13275 ctxt->context->proximityPosition = pp;
13276 ctxt->context->contextSize = cs;
13277 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13280 xmlXPathMultValues(ctxt);
13282 xmlXPathDivValues(ctxt);
13284 xmlXPathModValues(ctxt);
13287 bakd = ctxt->context->doc;
13288 bak = ctxt->context->node;
13289 pp = ctxt->context->proximityPosition;
13290 cs = ctxt->context->contextSize;
13291 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13293 ctxt->context->doc = bakd;
13294 ctxt->context->node = bak;
13295 ctxt->context->proximityPosition = pp;
13296 ctxt->context->contextSize = cs;
13297 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13300 arg2 = valuePop(ctxt);
13303 arg1 = valuePop(ctxt);
13313 valuePush(ctxt, arg1);
13314 xmlXPathReleaseObject(ctxt->context, arg2);
13317 xmlXPathRoot(ctxt);
13321 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13324 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13326 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
13327 ctxt->context->node));
13331 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13334 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13336 ctxt->context->node = NULL;
13342 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13345 total += xmlXPathNodeCollectAndTest(ctxt, op, NULL, NULL, 0);
13349 valuePush(ctxt,
13350 xmlXPathCacheObjectCopy(ctxt->context,
13358 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13360 val = xmlXPathVariableLookup(ctxt->context, op->value4);
13362 ctxt->error = XPATH_UNDEF_VARIABLE_ERROR;
13365 valuePush(ctxt, val);
13369 URI = xmlXPathNsLookup(ctxt->context, op->value5);
13374 ctxt->error = XPATH_UNDEF_PREFIX_ERROR;
13377 val = xmlXPathVariableLookupNS(ctxt->context,
13380 ctxt->error = XPATH_UNDEF_VARIABLE_ERROR;
13383 valuePush(ctxt, val);
13393 frame = xmlXPathSetFrame(ctxt);
13396 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13397 if (ctxt->valueNr < op->value) {
13400 ctxt->error = XPATH_INVALID_OPERAND;
13401 xmlXPathPopFrame(ctxt, frame);
13405 if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) {
13408 ctxt->error = XPATH_INVALID_OPERAND;
13409 xmlXPathPopFrame(ctxt, frame);
13420 xmlXPathFunctionLookup(ctxt->context,
13423 URI = xmlXPathNsLookup(ctxt->context, op->value5);
13428 ctxt->error = XPATH_UNDEF_PREFIX_ERROR;
13431 func = xmlXPathFunctionLookupNS(ctxt->context,
13443 oldFunc = ctxt->context->function;
13444 oldFuncURI = ctxt->context->functionURI;
13445 ctxt->context->function = op->value4;
13446 ctxt->context->functionURI = op->cacheURI;
13447 func(ctxt, op->value);
13448 ctxt->context->function = oldFunc;
13449 ctxt->context->functionURI = oldFuncURI;
13450 xmlXPathPopFrame(ctxt, frame);
13454 bakd = ctxt->context->doc;
13455 bak = ctxt->context->node;
13456 pp = ctxt->context->proximityPosition;
13457 cs = ctxt->context->contextSize;
13459 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13460 ctxt->context->contextSize = cs;
13461 ctxt->context->proximityPosition = pp;
13462 ctxt->context->node = bak;
13463 ctxt->context->doc = bakd;
13466 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
13467 ctxt->context->doc = bakd;
13468 ctxt->context->node = bak;
13510 xmlXPathCompOpEvalFirst(ctxt,
13518 if ((ctxt->value != NULL) &&
13519 (ctxt->value->type == XPATH_NODESET) &&
13520 (ctxt->value->nodesetval != NULL) &&
13521 (ctxt->value->nodesetval->nodeNr > 1))
13522 ctxt->value->nodesetval->nodeNr = 1;
13544 xmlXPathCompOpEvalLast(ctxt,
13552 if ((ctxt->value != NULL) &&
13553 (ctxt->value->type == XPATH_NODESET) &&
13554 (ctxt->value->nodesetval != NULL) &&
13555 (ctxt->value->nodesetval->nodeTab != NULL) &&
13556 (ctxt->value->nodesetval->nodeNr > 1)) {
13557 ctxt->value->nodesetval->nodeTab[0] =
13558 ctxt->value->nodesetval->nodeTab[ctxt->
13563 ctxt->value->nodesetval->nodeNr = 1;
13581 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13585 if (ctxt->value == NULL)
13588 oldnode = ctxt->context->node;
13594 if (ctxt->value->type == XPATH_LOCATIONSET) {
13604 obj = valuePop(ctxt);
13606 ctxt->context->node = NULL;
13609 ctxt->context->contextSize = 0;
13610 ctxt->context->proximityPosition = 0;
13613 xmlXPathCompOpEval(ctxt,
13615 res = valuePop(ctxt);
13617 xmlXPathReleaseObject(ctxt->context, res);
13619 valuePush(ctxt, obj);
13630 ctxt->context->node = oldlocset->locTab[i]->user;
13631 ctxt->context->contextSize = oldlocset->locNr;
13632 ctxt->context->proximityPosition = i + 1;
13633 tmp = xmlXPathCacheNewNodeSet(ctxt->context,
13634 ctxt->context->node);
13635 valuePush(ctxt, tmp);
13639 xmlXPathCompOpEval(ctxt,
13641 if (ctxt->error != XPATH_EXPRESSION_OK) {
13650 res = valuePop(ctxt);
13651 if (xmlXPathEvaluatePredicateResult(ctxt, res)) {
13661 xmlXPathReleaseObject(ctxt->context, res);
13663 if (ctxt->value == tmp) {
13664 res = valuePop(ctxt);
13665 xmlXPathReleaseObject(ctxt->context, res);
13668 ctxt->context->node = NULL;
13674 xmlXPathReleaseObject(ctxt->context, obj);
13675 ctxt->context->node = NULL;
13676 ctxt->context->contextSize = -1;
13677 ctxt->context->proximityPosition = -1;
13678 valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset));
13679 ctxt->context->node = oldnode;
13690 obj = valuePop(ctxt);
13693 oldnode = ctxt->context->node;
13694 oldDoc = ctxt->context->doc;
13695 ctxt->context->node = NULL;
13698 ctxt->context->contextSize = 0;
13699 ctxt->context->proximityPosition = 0;
13703 xmlXPathCompOpEval(ctxt,
13706 res = valuePop(ctxt);
13710 valuePush(ctxt, obj);
13711 ctxt->context->node = oldnode;
13752 ctxt->context->node = oldset->nodeTab[i];
13755 ctxt->context->doc = oldset->nodeTab[i]->doc;
13757 tmp = xmlXPathCacheNewNodeSet(ctxt->context,
13758 ctxt->context->node);
13761 ctxt->context->node);
13763 valuePush(ctxt, tmp);
13764 ctxt->context->contextSize = oldset->nodeNr;
13765 ctxt->context->proximityPosition = i + 1;
13773 xmlXPathCompOpEval(ctxt,
13775 if (ctxt->error != XPATH_EXPRESSION_OK) {
13789 res = valuePop(ctxt);
13790 if (xmlXPathEvaluatePredicateResult(ctxt, res)) {
13798 xmlXPathReleaseObject(ctxt->context, res);
13800 if (ctxt->value == tmp) {
13801 valuePop(ctxt);
13810 ctxt->context->node = NULL;
13813 xmlXPathReleaseObject(ctxt->context, tmp);
13817 xmlXPathReleaseObject(ctxt->context, obj);
13818 ctxt->context->node = NULL;
13819 ctxt->context->contextSize = -1;
13820 ctxt->context->proximityPosition = -1;
13822 ctxt->context->doc = oldDoc;
13823 valuePush(ctxt,
13824 xmlXPathCacheWrapNodeSet(ctxt->context, newset));
13826 ctxt->context->node = oldnode;
13831 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13833 if ((ctxt->value != NULL) &&
13834 (ctxt->value->type == XPATH_NODESET) &&
13835 (ctxt->value->nodesetval != NULL) &&
13836 (ctxt->value->nodesetval->nodeNr > 1))
13838 xmlXPathNodeSetSort(ctxt->value->nodesetval);
13853 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
13857 if (ctxt->value->type == XPATH_LOCATIONSET) {
13864 obj = valuePop(ctxt);
13868 ctxt->context->node = NULL;
13869 ctxt->context->contextSize = 0;
13870 ctxt->context->proximityPosition = 0;
13871 total += xmlXPathCompOpEval(ctxt,&comp->steps[op->ch2]);
13872 res = valuePop(ctxt);
13874 xmlXPathReleaseObject(ctxt->context, res);
13876 valuePush(ctxt, obj);
13887 ctxt->context->node = oldlocset->locTab[i]->user;
13888 ctxt->context->contextSize = oldlocset->locNr;
13889 ctxt->context->proximityPosition = i + 1;
13890 tmp = xmlXPathCacheNewNodeSet(ctxt->context,
13891 ctxt->context->node);
13892 valuePush(ctxt, tmp);
13896 xmlXPathCompOpEval(ctxt,
13898 if (ctxt->error != XPATH_EXPRESSION_OK) {
13903 res = valuePop(ctxt);
13929 xmlXPathReleaseObject(ctxt->context, res);
13931 if (ctxt->value == tmp) {
13932 res = valuePop(ctxt);
13933 xmlXPathReleaseObject(ctxt->context, res);
13936 ctxt->context->node = NULL;
13940 obj = valuePop(ctxt);
13942 ctxt->context->node = NULL;
13952 ctxt->context->node = oldset->nodeTab[i];
13956 tmp = xmlXPathCacheNewNodeSet(ctxt->context,
13957 ctxt->context->node);
13958 valuePush(ctxt, tmp);
13962 xmlXPathCompOpEval(ctxt,
13964 if (ctxt->error != XPATH_EXPRESSION_OK) {
13969 res = valuePop(ctxt);
13981 xmlXPathReleaseObject(ctxt->context, res);
13983 if (ctxt->value == tmp) {
13984 res = valuePop(ctxt);
13985 xmlXPathReleaseObject(ctxt->context, res);
13988 ctxt->context->node = NULL;
13996 xmlXPathReleaseObject(ctxt->context, obj);
13997 ctxt->context->node = NULL;
13998 ctxt->context->contextSize = -1;
13999 ctxt->context->proximityPosition = -1;
14000 valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset));
14007 ctxt->error = XPATH_INVALID_OPERAND;
14013 * @ctxt: the XPath parser context
14020 xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt,
14027 /* comp = ctxt->comp; */
14034 return(xmlXPathEvaluatePredicateResult(ctxt, resObj));
14041 op = &ctxt->comp->steps[op->ch1];
14049 xmlXPathCompOpEval(ctxt, &ctxt->comp->steps[op->ch1]);
14050 if (ctxt->error != XPATH_EXPRESSION_OK)
14053 xmlXPathNodeCollectAndTest(ctxt, op, NULL, NULL, 1);
14054 if (ctxt->error != XPATH_EXPRESSION_OK)
14057 resObj = valuePop(ctxt);
14065 xmlXPathCompOpEval(ctxt, op);
14066 if (ctxt->error != XPATH_EXPRESSION_OK)
14069 resObj = valuePop(ctxt);
14089 res = xmlXPathEvaluatePredicateResult(ctxt, resObj);
14093 xmlXPathReleaseObject(ctxt->context, resObj);
14103 * @ctxt: the XPath parser context with the compiled expression
14108 xmlXPathRunStreamEval(xmlXPathContextPtr ctxt, xmlPatternPtr comp,
14120 if ((ctxt == NULL) || (comp == NULL))
14140 *resultSeq = xmlXPathCacheNewNodeSet(ctxt, NULL);
14154 (xmlNodePtr) ctxt->doc);
14159 xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, ctxt->node);
14167 cur = (xmlNodePtr)ctxt->doc;
14168 } else if (ctxt->node != NULL) {
14169 switch (ctxt->node->type) {
14177 cur = ctxt->node;
14331 * @ctxt: the XPath parser context with the compiled expression
14337 xmlXPathRunEval(xmlXPathParserContextPtr ctxt, int toBool)
14341 if ((ctxt == NULL) || (ctxt->comp == NULL))
14344 if (ctxt->valueTab == NULL) {
14346 ctxt->valueTab = (xmlXPathObjectPtr *)
14348 if (ctxt->valueTab == NULL) {
14349 xmlXPathPErrMemory(ctxt, "creating evaluation context\n");
14350 xmlFree(ctxt);
14352 ctxt->valueNr = 0;
14353 ctxt->valueMax = 10;
14354 ctxt->value = NULL;
14355 ctxt->valueFrame = 0;
14358 if (ctxt->comp->stream) {
14365 res = xmlXPathRunStreamEval(ctxt->context,
14366 ctxt->comp->stream, NULL, 1);
14375 res = xmlXPathRunStreamEval(ctxt->context,
14376 ctxt->comp->stream, &resObj, 0);
14379 valuePush(ctxt, resObj);
14383 xmlXPathReleaseObject(ctxt->context, resObj);
14391 comp = ctxt->comp;
14398 return(xmlXPathCompOpEvalToBoolean(ctxt,
14401 xmlXPathCompOpEval(ctxt, &comp->steps[comp->last]);
14414 * @ctxt: the XPath context
14429 xmlXPathEvalPredicate(xmlXPathContextPtr ctxt, xmlXPathObjectPtr res) {
14430 if ((ctxt == NULL) || (res == NULL)) return(0);
14435 return(res->floatval == ctxt->proximityPosition);
14452 * @ctxt: the XPath Parser context
14467 xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt,
14469 if ((ctxt == NULL) || (res == NULL)) return(0);
14475 return((res->floatval == ctxt->context->proximityPosition) &&
14478 return(res->floatval == ctxt->context->proximityPosition);
14504 * @ctxt: an XPath context
14512 xmlXPathTryStreamCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
14539 ((ctxt == NULL) || (ctxt->nsNr == 0) || (tmp[1] == ':')))
14542 if (ctxt != NULL) {
14543 dict = ctxt->dict;
14544 if (ctxt->nsNr > 0) {
14545 namespaces = xmlMalloc(2 * (ctxt->nsNr + 1) * sizeof(xmlChar*));
14547 xmlXPathErrMemory(ctxt, "allocating namespaces array\n");
14550 for (i = 0, j = 0; (j < ctxt->nsNr); j++) {
14551 ns = ctxt->namespaces[j];
14568 xmlXPathErrMemory(ctxt, "allocating streamable expression\n");
14638 * @ctxt: an XPath context
14647 xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
14652 comp = xmlXPathTryStreamCompile(ctxt, str);
14659 pctxt = xmlXPathNewParserContext(str, ctxt);
14719 * @ctxt: the XPath context
14731 xmlXPathContextPtr ctxt,
14741 CHECK_CTXT_NEG(ctxt)
14760 pctxt = xmlXPathCompParserContext(comp, ctxt);
14784 xmlXPathReleaseObject(ctxt, tmp);
14831 * @ctxt: the XPath context
14841 xmlXPathContextPtr ctxt)
14843 return(xmlXPathCompiledEvalInternal(comp, ctxt, NULL, 1));
14848 * @ctxt: the XPath Parser context
14854 xmlXPathEvalExpr(xmlXPathParserContextPtr ctxt) {
14859 if (ctxt == NULL) return;
14862 comp = xmlXPathTryStreamCompile(ctxt->context, ctxt->base);
14864 if (ctxt->comp != NULL)
14865 xmlXPathFreeCompExpr(ctxt->comp);
14866 ctxt->comp = comp;
14867 if (ctxt->cur != NULL)
14868 while (*ctxt->cur != 0) ctxt->cur++;
14872 xmlXPathCompileExpr(ctxt, 1);
14874 * In this scenario the expression string will sit in ctxt->base.
14876 if ((ctxt->error == XPATH_EXPRESSION_OK) &&
14877 (ctxt->comp != NULL) &&
14878 (ctxt->base != NULL) &&
14879 (ctxt->comp->nbStep > 2) &&
14880 (ctxt->comp->last >= 0) &&
14881 (xmlXPathCanRewriteDosExpression((xmlChar *) ctxt->base) == 1))
14883 xmlXPathRewriteDOSExpression(ctxt->comp,
14884 &ctxt->comp->steps[ctxt->comp->last]);
14888 xmlXPathRunEval(ctxt, 0);
14903 xmlXPathParserContextPtr ctxt;
14911 ctxt = xmlXPathNewParserContext(str, ctx);
14912 if (ctxt == NULL)
14914 xmlXPathEvalExpr(ctxt);
14916 if (ctxt->value == NULL) {
14920 } else if ((*ctxt->cur != 0) && (ctxt->comp != NULL)
14922 && (ctxt->comp->stream == NULL)
14925 xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR);
14928 res = valuePop(ctxt);
14932 tmp = valuePop(ctxt);
14944 if (ctxt->error != XPATH_EXPRESSION_OK) {
14949 xmlXPathFreeParserContext(ctxt);
14956 * @ctxt: the XPath context
14964 xmlXPathEvalExpression(const xmlChar *str, xmlXPathContextPtr ctxt) {
14969 CHECK_CTXT(ctxt)
14973 pctxt = xmlXPathNewParserContext(str, ctxt);
14987 xmlXPathReleaseObject(ctxt, tmp);
15007 * @ctxt: the XPath Parser context
15054 xmlXPathEscapeUriFunction(xmlXPathParserContextPtr ctxt, int nargs) {
15063 escape_reserved = xmlXPathPopBoolean(ctxt);
15066 str = valuePop(ctxt);
15108 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
15111 xmlXPathReleaseObject(ctxt->context, str);
15116 * @ctxt: the XPath context
15121 xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt)
15123 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"boolean",
15125 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"ceiling",
15127 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"count",
15129 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"concat",
15131 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"contains",
15133 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"id",
15135 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"false",
15137 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"floor",
15139 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"last",
15141 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"lang",
15143 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"local-name",
15145 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"not",
15147 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"name",
15149 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"namespace-uri",
15151 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"normalize-space",
15153 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"number",
15155 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"position",
15157 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"round",
15159 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"string",
15161 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"string-length",
15163 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"starts-with",
15165 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring",
15167 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring-before",
15169 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring-after",
15171 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"sum",
15173 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"true",
15175 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"translate",
15178 xmlXPathRegisterFuncNS(ctxt, (const xmlChar *)"escape-uri",