diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2003-09-27 15:31:09 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2003-09-27 15:31:09 +0000 |
commit | c5f8d4199abba6af8d47d6c17f2eb5d03f894aae (patch) | |
tree | a22301f3171206b44fac0eba77a863c6fc87ec96 /libexslt/saxon.c | |
parent | 25e0bf85bd67fbd3c589f64062d247a7370ff78a (diff) | |
download | libxslt-c5f8d4199abba6af8d47d6c17f2eb5d03f894aae.tar.gz libxslt-c5f8d4199abba6af8d47d6c17f2eb5d03f894aae.tar.bz2 libxslt-c5f8d4199abba6af8d47d6c17f2eb5d03f894aae.zip |
applied patch from Brett Kail to implement saxon:line-number() Daniel
* libexslt/saxon.c: applied patch from Brett Kail to implement
saxon:line-number()
Daniel
Diffstat (limited to 'libexslt/saxon.c')
-rw-r--r-- | libexslt/saxon.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libexslt/saxon.c b/libexslt/saxon.c index 02e6a57e..f59bfb40 100644 --- a/libexslt/saxon.c +++ b/libexslt/saxon.c @@ -180,6 +180,68 @@ exsltSaxonEvaluateFunction (xmlXPathParserContextPtr ctxt, int nargs) { } /** + * exsltSaxonLineNumberFunction: + * @ctxt: an XPath parser context + * @nargs: number of arguments + * + * Implements the SAXON line-number() function + * integer saxon:line-number() + * + * This returns the line number of the context node in the source document + * within the entity that contains it. There are no arguments. If line numbers + * are not maintained for the current document, the function returns -1. (To + * ensure that line numbers are maintained, use the -l option on the command + * line) + * + * The extension has been extended to have the following form: + * integer saxon:line-number([node-set-1]) + * If a node-set is given, this extension will return the line number of the + * node in the argument node-set that is first in document order. + */ +static void +exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) { + xmlNodePtr cur = NULL; + + if (nargs == 0) { + cur = ctxt->context->node; + } else if (nargs == 1) { + xmlXPathObjectPtr obj; + xmlNodeSetPtr nodelist; + int i; + + if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_NODESET)) { + xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, + "saxon:line-number() : invalid arg expecting a node-set\n"); + ctxt->error = XPATH_INVALID_TYPE; + return; + } + + obj = valuePop(ctxt); + nodelist = obj->nodesetval; + if ((nodelist == NULL) || (nodelist->nodeNr <= 0)) { + xmlXPathFreeObject(obj); + valuePush(ctxt, xmlXPathNewFloat(-1)); + } + 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); + } else { + xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, + "saxon:line-number() : invalid number of args %d\n", + nargs); + ctxt->error = XPATH_INVALID_ARITY; + return; + } + + valuePush(ctxt, xmlXPathNewFloat(xmlGetLineNo(cur))); + return; +} + +/** * exsltSaxonRegister: * * Registers the SAXON extension module @@ -198,4 +260,7 @@ exsltSaxonRegister (void) { xsltRegisterExtModuleFunction((const xmlChar *) "evaluate", SAXON_NAMESPACE, exsltSaxonEvaluateFunction); + xsltRegisterExtModuleFunction ((const xmlChar *) "line-number", + SAXON_NAMESPACE, + exsltSaxonLineNumberFunction); } |