summaryrefslogtreecommitdiff
path: root/libexslt/saxon.c
diff options
context:
space:
mode:
Diffstat (limited to 'libexslt/saxon.c')
-rw-r--r--libexslt/saxon.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/libexslt/saxon.c b/libexslt/saxon.c
index e92ba8d0..7a2f63be 100644
--- a/libexslt/saxon.c
+++ b/libexslt/saxon.c
@@ -101,9 +101,7 @@ exsltSaxonExpressionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
ret = xmlXPathCompile(arg);
if (ret == NULL) {
xmlFree(arg);
- xsltGenericError(xsltGenericErrorContext,
- "{%s}:%s: argument is not an XPath expression\n",
- ctxt->context->functionURI, ctxt->context->function);
+ xmlXPathSetError(ctxt, XPATH_EXPR_ERROR);
return;
}
xmlHashAddEntry(hash, arg, (void *) ret);
@@ -147,6 +145,10 @@ exsltSaxonEvalFunction (xmlXPathParserContextPtr ctxt, int nargs) {
expr = (xmlXPathCompExprPtr) xmlXPathPopExternal(ctxt);
ret = xmlXPathCompiledEval(expr, ctxt->context);
+ if (ret == NULL) {
+ xmlXPathSetError(ctxt, XPATH_EXPR_ERROR);
+ return;
+ }
valuePush(ctxt, ret);
}
@@ -227,11 +229,12 @@ exsltSaxonSystemIdFunction(xmlXPathParserContextPtr ctxt, int nargs)
static void
exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlNodePtr cur = NULL;
+ xmlXPathObjectPtr obj = NULL;
+ long lineNo = -1;
if (nargs == 0) {
cur = ctxt->context->node;
} else if (nargs == 1) {
- xmlXPathObjectPtr obj;
xmlNodeSetPtr nodelist;
int i;
@@ -244,18 +247,14 @@ exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
obj = valuePop(ctxt);
nodelist = obj->nodesetval;
- if ((nodelist == NULL) || (nodelist->nodeNr <= 0)) {
- xmlXPathFreeObject(obj);
- valuePush(ctxt, xmlXPathNewFloat(-1));
- return;
- }
- cur = nodelist->nodeTab[0];
- for (i = 1;i < nodelist->nodeNr;i++) {
- int ret = xmlXPathCmpNodes(cur, nodelist->nodeTab[i]);
- if (ret == -1)
- cur = nodelist->nodeTab[i];
- }
- xmlXPathFreeObject(obj);
+ if ((nodelist != NULL) && (nodelist->nodeNr > 0)) {
+ cur = nodelist->nodeTab[0];
+ for (i = 1;i < nodelist->nodeNr;i++) {
+ int ret = xmlXPathCmpNodes(cur, nodelist->nodeTab[i]);
+ if (ret == -1)
+ cur = nodelist->nodeTab[i];
+ }
+ }
} else {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"saxon:line-number() : invalid number of args %d\n",
@@ -264,8 +263,26 @@ exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
return;
}
- valuePush(ctxt, xmlXPathNewFloat(xmlGetLineNo(cur)));
- return;
+ if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) {
+ /*
+ * The XPath module sets the owner element of a ns-node on
+ * the ns->next field.
+ */
+ cur = (xmlNodePtr) ((xmlNsPtr) cur)->next;
+ if (cur == NULL || cur->type != XML_ELEMENT_NODE) {
+ xsltGenericError(xsltGenericErrorContext,
+ "Internal error in exsltSaxonLineNumberFunction: "
+ "Cannot retrieve the doc of a namespace node.\n");
+ cur = NULL;
+ }
+ }
+
+ if (cur != NULL)
+ lineNo = xmlGetLineNo(cur);
+
+ valuePush(ctxt, xmlXPathNewFloat(lineNo));
+
+ xmlXPathFreeObject(obj);
}
/**