File libxml2-xpath-ns-attr-axis.patch of Package libxml2
From 91d19754d46acd4a639a8b9e31f50f31c78f8c9c Mon Sep 17 00:00:00 2001
From: Daniel Veillard <veillard@redhat.com>
Date: Fri, 15 Oct 2010 14:30:52 +0200
Subject: [PATCH] Fix the semantic of XPath axis for namespace/attribute context nodes
The processing of namespace and attributes nodes was not compliant
to the XPath-1.0 specification
---
xpath.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
Index: libxml2-2.7.7/xpath.c
===================================================================
--- libxml2-2.7.7.orig/xpath.c
+++ libxml2-2.7.7/xpath.c
@@ -8106,9 +8106,17 @@ xmlXPathNextPrecedingSibling(xmlXPathPar
xmlNodePtr
xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
- if (cur != NULL && cur->children != NULL)
- return cur->children ;
- if (cur == NULL) cur = ctxt->context->node;
+ if ((cur != NULL) && (cur->type != XML_ATTRIBUTE_NODE) &&
+ (cur->type != XML_NAMESPACE_DECL) && (cur->children != NULL))
+ return(cur->children);
+
+ if (cur == NULL) {
+ cur = ctxt->context->node;
+ if (cur->type == XML_NAMESPACE_DECL)
+ return(NULL);
+ if (cur->type == XML_ATTRIBUTE_NODE)
+ cur = cur->parent;
+ }
if (cur == NULL) return(NULL) ; /* ERROR */
if (cur->next != NULL) return(cur->next) ;
do {
@@ -8162,8 +8170,13 @@ xmlNodePtr
xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur)
{
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
- if (cur == NULL)
+ if (cur == NULL) {
cur = ctxt->context->node;
+ if (cur->type == XML_NAMESPACE_DECL)
+ return(NULL);
+ if (cur->type == XML_ATTRIBUTE_NODE)
+ return(cur->parent);
+ }
if (cur == NULL)
return (NULL);
if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE))
@@ -8208,7 +8221,7 @@ xmlXPathNextPrecedingInternal(xmlXPathPa
if (cur == NULL)
return (NULL);
if (cur->type == XML_NAMESPACE_DECL)
- cur = (xmlNodePtr)((xmlNsPtr)cur)->next;
+ return (NULL);
ctxt->ancestor = cur->parent;
}
if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE))