/* * keys.c: Implemetation of the keys support * * Reference: * http://www.w3.org/TR/1999/REC-xslt-19991116 * * See Copyright for the status of this software. * * [email protected] */ #define IN_LIBXSLT #include "libxslt.h" #include <string.h> #include <libxml/xmlmemory.h> #include <libxml/tree.h> #include <libxml/valid.h> #include <libxml/hash.h> #include <libxml/xmlerror.h> #include <libxml/parserInternals.h> #include <libxml/xpathInternals.h> #include <libxml/xpath.h> #include "xslt.h" #include "xsltInternals.h" #include "xsltutils.h" #include "imports.h" #include "templates.h" #include "keys.h" #ifdef WITH_XSLT_DEBUG #define WITH_XSLT_DEBUG_KEYS #endif static int xsltInitDocKeyTable(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI); /************************************************************************ * * * Type functions * * * ************************************************************************/ /** * xsltNewKeyDef: * @name: the key name or NULL * @nameURI: the name URI or NULL * * Create a new XSLT KeyDef * * Returns the newly allocated xsltKeyDefPtr or NULL in case of error */ static xsltKeyDefPtr xsltNewKeyDef(const xmlChar *name, const xmlChar *nameURI) { … } /** * xsltFreeKeyDef: * @keyd: an XSLT key definition * * Free up the memory allocated by @keyd */ static void xsltFreeKeyDef(xsltKeyDefPtr keyd) { … } /** * xsltFreeKeyDefList: * @keyd: an XSLT key definition list * * Free up the memory allocated by all the elements of @keyd */ static void xsltFreeKeyDefList(xsltKeyDefPtr keyd) { … } /** * xsltNewKeyTable: * @name: the key name or NULL * @nameURI: the name URI or NULL * * Create a new XSLT KeyTable * * Returns the newly allocated xsltKeyTablePtr or NULL in case of error */ static xsltKeyTablePtr xsltNewKeyTable(const xmlChar *name, const xmlChar *nameURI) { … } static void xsltFreeNodeSetEntry(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) { … } /** * xsltFreeKeyTable: * @keyt: an XSLT key table * * Free up the memory allocated by @keyt */ static void xsltFreeKeyTable(xsltKeyTablePtr keyt) { … } /** * xsltFreeKeyTableList: * @keyt: an XSLT key table list * * Free up the memory allocated by all the elements of @keyt */ static void xsltFreeKeyTableList(xsltKeyTablePtr keyt) { … } /************************************************************************ * * * The interpreter for the precompiled patterns * * * ************************************************************************/ /** * xsltFreeKeys: * @style: an XSLT stylesheet * * Free up the memory used by XSLT keys in a stylesheet */ void xsltFreeKeys(xsltStylesheetPtr style) { … } /** * skipString: * @cur: the current pointer * @end: the current offset * * skip a string delimited by " or ' * * Returns the byte after the string or -1 in case of error */ static int skipString(const xmlChar *cur, int end) { … } /** * skipPredicate: * @cur: the current pointer * @end: the current offset * * skip a predicate * * Returns the byte after the predicate or -1 in case of error */ static int skipPredicate(const xmlChar *cur, int end) { … } /** * xsltAddKey: * @style: an XSLT stylesheet * @name: the key name or NULL * @nameURI: the name URI or NULL * @match: the match value * @use: the use value * @inst: the key instruction * * add a key definition to a stylesheet * * Returns 0 in case of success, and -1 in case of failure. */ int xsltAddKey(xsltStylesheetPtr style, const xmlChar *name, const xmlChar *nameURI, const xmlChar *match, const xmlChar *use, xmlNodePtr inst) { … } /** * xsltGetKey: * @ctxt: an XSLT transformation context * @name: the key name or NULL * @nameURI: the name URI or NULL * @value: the key value to look for * * Looks up a key of the in current source doc (the document info * on @ctxt->document). Computes the key if not already done * for the current source doc. * * Returns the nodeset resulting from the query or NULL */ xmlNodeSetPtr xsltGetKey(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI, const xmlChar *value) { … } /** * xsltInitDocKeyTable: * * INTERNAL ROUTINE ONLY * * Check if any keys on the current document need to be computed */ static int xsltInitDocKeyTable(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI) { … } /** * xsltInitAllDocKeys: * @ctxt: transformation context * * INTERNAL ROUTINE ONLY * * Check if any keys on the current document need to be computed * * Returns 0 in case of success, -1 in case of failure */ int xsltInitAllDocKeys(xsltTransformContextPtr ctxt) { … } /** * xsltInitCtxtKey: * @ctxt: an XSLT transformation context * @idoc: the document information (holds key values) * @keyDef: the key definition * * Computes the key tables this key and for the current input document. * * Returns: 0 on success, -1 on error */ int xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr idoc, xsltKeyDefPtr keyDef) { … } /** * xsltInitCtxtKeys: * @ctxt: an XSLT transformation context * @idoc: a document info * * Computes all the keys tables for the current input document. * Should be done before global varibales are initialized. * NOTE: Not used anymore in the refactored code. */ void xsltInitCtxtKeys(xsltTransformContextPtr ctxt, xsltDocumentPtr idoc) { … } /** * xsltFreeDocumentKeys: * @idoc: a XSLT document * * Free the keys associated to a document */ void xsltFreeDocumentKeys(xsltDocumentPtr idoc) { … }