ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

XSLTPUBFUN int XSLTCALL xsltAddKey ( xsltStylesheetPtr  style,
const xmlChar name,
const xmlChar nameURI,
const xmlChar match,
const xmlChar use,
xmlNodePtr  inst 
)

Definition at line 274 of file keys.c.

Referenced by xsltParseStylesheetKey().

                                            {
    xsltKeyDefPtr key;
    xmlChar *pattern = NULL;
    int current, end, start, i = 0;

    if ((style == NULL) || (name == NULL) || (match == NULL) || (use == NULL))
    return(-1);

#ifdef WITH_XSLT_DEBUG_KEYS
    xsltGenericDebug(xsltGenericDebugContext,
    "Add key %s, match %s, use %s\n", name, match, use);
#endif

    key = xsltNewKeyDef(name, nameURI);
    key->match = xmlStrdup(match);
    key->use = xmlStrdup(use);
    key->inst = inst;
    key->nsList = xmlGetNsList(inst->doc, inst);
    if (key->nsList != NULL) {
        while (key->nsList[i] != NULL)
        i++;
    }
    key->nsNr = i;

    /*
     * Split the | and register it as as many keys
     */
    current = end = 0;
    while (match[current] != 0) {
    start = current;
    while (IS_BLANK_CH(match[current]))
        current++;
    end = current;
    while ((match[end] != 0) && (match[end] != '|')) {
        if (match[end] == '[') {
            end = skipPredicate(match, end);
        if (end <= 0) {
            xsltTransformError(NULL, style, inst,
                               "key pattern is malformed: %s",
                       key->match);
            if (style != NULL) style->errors++;
            goto error;
        }
        } else
        end++;
    }
    if (current == end) {
        xsltTransformError(NULL, style, inst,
                   "key pattern is empty\n");
        if (style != NULL) style->errors++;
        goto error;
    }
    if (match[start] != '/') {
        pattern = xmlStrcat(pattern, (xmlChar *)"//");
        if (pattern == NULL) {
        if (style != NULL) style->errors++;
        goto error;
        }
    }
    pattern = xmlStrncat(pattern, &match[start], end - start);
    if (pattern == NULL) {
        if (style != NULL) style->errors++;
        goto error;
    }

    if (match[end] == '|') {
        pattern = xmlStrcat(pattern, (xmlChar *)"|");
        end++;
    }
    current = end;
    }
#ifdef WITH_XSLT_DEBUG_KEYS
    xsltGenericDebug(xsltGenericDebugContext,
    "   resulting pattern %s\n", pattern);
#endif
    /*
    * XSLT-1: "It is an error for the value of either the use
    *  attribute or the match attribute to contain a
    *  VariableReference."
    * TODO: We should report a variable-reference at compile-time.
    *   Maybe a search for "$", if it occurs outside of quotation
    *   marks, could be sufficient.
    */
    key->comp = xsltXPathCompile(style, pattern);
    if (key->comp == NULL) {
    xsltTransformError(NULL, style, inst,
        "xsl:key : XPath pattern compilation failed '%s'\n",
                 pattern);
    if (style != NULL) style->errors++;
    }
    key->usecomp = xsltXPathCompile(style, use);
    if (key->usecomp == NULL) {
    xsltTransformError(NULL, style, inst,
        "xsl:key : XPath pattern compilation failed '%s'\n",
                 use);
    if (style != NULL) style->errors++;
    }

    /*
     * Sometimes the stylesheet writer use the order to ease the
     * resolution of keys when they are dependant, keep the provided
     * order so add the new one at the end.
     */
    if (style->keys == NULL) {
    style->keys = key;
    } else {
        xsltKeyDefPtr prev = style->keys;

    while (prev->next != NULL)
        prev = prev->next;

    prev->next = key;
    }
    key->next = NULL;

error:
    if (pattern != NULL)
    xmlFree(pattern);
    return(0);
}

Generated on Fri May 25 2012 04:48:37 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.