* xmlXPathNameFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the name() XPath function * string name(node-set?) * The name function returns a string containing a QName representing * the name of the node in the argument node-set that is first in document * order. The QName must represent the name with respect to the namespace * declaration
| 7744 | * returned. |
| 7745 | */ |
| 7746 | static void |
| 7747 | xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) |
| 7748 | { |
| 7749 | xmlXPathObjectPtr cur; |
| 7750 | |
| 7751 | if (nargs == 0) { |
| 7752 | valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt, ctxt->context->node)); |
| 7753 | nargs = 1; |
| 7754 | } |
| 7755 | |
| 7756 | CHECK_ARITY(1); |
| 7757 | if ((ctxt->value == NULL) || |
| 7758 | ((ctxt->value->type != XPATH_NODESET) && |
| 7759 | (ctxt->value->type != XPATH_XSLT_TREE))) |
| 7760 | XP_ERROR(XPATH_INVALID_TYPE); |
| 7761 | cur = valuePop(ctxt); |
| 7762 | |
| 7763 | if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { |
| 7764 | valuePush(ctxt, xmlXPathCacheNewCString(ctxt, "")); |
| 7765 | } else { |
| 7766 | int i = 0; /* Should be first in document order !!!!! */ |
| 7767 | |
| 7768 | switch (cur->nodesetval->nodeTab[i]->type) { |
| 7769 | case XML_ELEMENT_NODE: |
| 7770 | case XML_ATTRIBUTE_NODE: |
| 7771 | if (cur->nodesetval->nodeTab[i]->name[0] == ' ') |
| 7772 | valuePush(ctxt, |
| 7773 | xmlXPathCacheNewCString(ctxt, "")); |
| 7774 | else if ((cur->nodesetval->nodeTab[i]->ns == NULL) || |
| 7775 | (cur->nodesetval->nodeTab[i]->ns->prefix == NULL)) { |
| 7776 | valuePush(ctxt, xmlXPathCacheNewString(ctxt, |
| 7777 | cur->nodesetval->nodeTab[i]->name)); |
| 7778 | } else { |
| 7779 | xmlChar *fullname; |
| 7780 | |
| 7781 | fullname = xmlBuildQName(cur->nodesetval->nodeTab[i]->name, |
| 7782 | cur->nodesetval->nodeTab[i]->ns->prefix, |
| 7783 | NULL, 0); |
| 7784 | if (fullname == cur->nodesetval->nodeTab[i]->name) |
| 7785 | fullname = xmlStrdup(cur->nodesetval->nodeTab[i]->name); |
| 7786 | if (fullname == NULL) |
| 7787 | xmlXPathPErrMemory(ctxt); |
| 7788 | valuePush(ctxt, xmlXPathCacheWrapString(ctxt, fullname)); |
| 7789 | } |
| 7790 | break; |
| 7791 | default: |
| 7792 | valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt, |
| 7793 | cur->nodesetval->nodeTab[i])); |
| 7794 | xmlXPathLocalNameFunction(ctxt, 1); |
| 7795 | } |
| 7796 | } |
| 7797 | xmlXPathReleaseObject(ctxt->context, cur); |
| 7798 | } |
| 7799 | |
| 7800 | |
| 7801 | /** |
nothing calls this directly
no test coverage detected