Skip to content
Snippets Groups Projects
Commit a5c6871e895f authored by Daniel Veillard's avatar Daniel Veillard
Browse files

More work on Key support:

- libxslt/functions.c FEATURES: started adding support for key()
- tests/REC/test-12.2-1.*: first key test
Daniel
parent f1f79e0fefc3
Branches
No related tags found
No related merge requests found
Wed Feb 7 21:16:47 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* libxslt/functions.c FEATURES: started adding support for key()
* tests/REC/test-12.2-1.*: first key test
Wed Feb 7 19:46:07 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Wed Feb 7 19:46:07 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* FEATURES: updated * FEATURES: updated
......
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
========== ==========
PARTIAL node-set document(object, node-set?) PARTIAL node-set document(object, node-set?)
NO node-set key(string, object) PARTIAL node-set key(string, object)
YES string format-number(number, string, string?) YES string format-number(number, string, string?)
YES node-set current() YES node-set current()
YES string unparsed-entity-uri(string) YES string unparsed-entity-uri(string)
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "xsltutils.h" #include "xsltutils.h"
#include "functions.h" #include "functions.h"
#include "numbersInternals.h" #include "numbersInternals.h"
#include "keys.h"
#define DEBUG_FUNCTION #define DEBUG_FUNCTION
...@@ -142,7 +143,64 @@ ...@@ -142,7 +143,64 @@
*/ */
void void
xsltKeyFunction(xmlXPathParserContextPtr ctxt, int nargs){ xsltKeyFunction(xmlXPathParserContextPtr ctxt, int nargs){
TODO /* function */ xmlNodeSetPtr nodelist;
xmlXPathObjectPtr obj, tmp;
xmlChar *key, *value;
xsltTransformContextPtr tctxt;
tctxt = ((xsltTransformContextPtr)ctxt->context->extra);
if (nargs != 2) {
xsltGenericError(xsltGenericErrorContext,
"key() : expects one string arg\n");
ctxt->error = XPATH_INVALID_ARITY;
return;
}
obj = valuePop(ctxt);
if ((obj == NULL) ||
(ctxt->value == NULL) || (ctxt->value->type != XPATH_STRING)) {
xsltGenericError(xsltGenericErrorContext,
"generate-id() : invalid arg expecting a string\n");
ctxt->error = XPATH_INVALID_TYPE;
xmlXPathFreeObject(obj);
return;
}
tmp = valuePop(ctxt);
key = tmp->stringval;
/* TODO: find URI when qualified name */
if (obj->type == XPATH_NODESET) {
TODO /* handle NODE set as 2nd args of key() */
} else {
/*
* Force conversion of first arg to string
*/
valuePush(ctxt, obj);
xmlXPathStringFunction(ctxt, 1);
if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_STRING)) {
xsltGenericError(xsltGenericErrorContext,
"generate-id() : invalid arg expecting a string\n");
ctxt->error = XPATH_INVALID_TYPE;
xmlXPathFreeObject(obj);
return;
}
obj = valuePop(ctxt);
value = obj->stringval;
nodelist = xsltGetKey(tctxt, key, NULL, value);
valuePush(ctxt, xmlXPathWrapNodeSet(
xmlXPathNodeSetMerge(NULL, nodelist)));
}
if (obj != NULL)
xmlXPathFreeObject(obj);
if (tmp != NULL)
xmlXPathFreeObject(tmp);
} }
/** /**
......
<?xml version="1.0"?>
Success
<doc>
<div id="lookup">Success</div>
<div id="unwanted">Failed</div>
</doc>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:key name="idkey" match="div" use="@id"/>
<xsl:template match="doc">
<xsl:value-of select="key('idkey','lookup')"/>
</xsl:template>
</xsl:stylesheet>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment