Fix bug 602515
authorNick Wellnhofer <wellnhofer@aevum.de>
Mon, 8 Nov 2010 09:59:24 +0000 (10:59 +0100)
committerDaniel Veillard <veillard@redhat.com>
Mon, 8 Nov 2010 09:59:24 +0000 (10:59 +0100)
Pattern matching with predicates

libxslt/pattern.c
tests/docs/bug-171.xml [new file with mode: 0644]
tests/general/Makefile.am
tests/general/bug-171.out [new file with mode: 0644]
tests/general/bug-171.xsl [new file with mode: 0644]

index 58bd6ed..6161376 100644 (file)
@@ -888,11 +888,10 @@ restart:
                    (node->type == XML_ELEMENT_NODE) &&
                    (node->parent != NULL)) {
                    xmlNodePtr previous;
-                   int ix, nocache = 0;
+                   int nocache = 0;
 
                    previous = (xmlNodePtr)
                        XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
-                   ix = XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival);
                    if ((previous != NULL) &&
                        (previous->parent == node->parent)) {
                        /*
@@ -904,7 +903,7 @@ restart:
                        while (sibling != NULL) {
                            if (sibling == previous)
                                break;
-                           if ((previous->type == XML_ELEMENT_NODE) &&
+                           if ((sibling->type == XML_ELEMENT_NODE) &&
                                (previous->name != NULL) &&
                                (sibling->name != NULL) &&
                                (previous->name[0] == sibling->name[0]) &&
@@ -925,7 +924,7 @@ restart:
                            while (sibling != NULL) {
                                if (sibling == previous)
                                    break;
-                               if ((previous->type == XML_ELEMENT_NODE) &&
+                               if ((sibling->type == XML_ELEMENT_NODE) &&
                                    (previous->name != NULL) &&
                                    (sibling->name != NULL) &&
                                    (previous->name[0] == sibling->name[0]) &&
@@ -943,7 +942,8 @@ restart:
                            }
                        }
                        if (sibling != NULL) {
-                           pos = ix + indx;
+                           pos = XSLT_RUNTIME_EXTRA(ctxt,
+                                sel->indexExtra, ival) + indx;
                            /*
                             * If the node is in a Value Tree we need to
                             * save len, but cannot cache the node!
@@ -959,7 +959,6 @@ restart:
                                        sel->indexExtra, ival) = pos;
                                }
                            }
-                           ix = pos;
                        } else
                            pos = 0;
                    } else {
@@ -1020,11 +1019,10 @@ restart:
                } else if ((sel != NULL) && (sel->op == XSLT_OP_ALL) &&
                           (node->type == XML_ELEMENT_NODE)) {
                    xmlNodePtr previous;
-                   int ix, nocache = 0;
+                   int nocache = 0;
 
                    previous = (xmlNodePtr)
                        XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
-                   ix = XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival);
                    if ((previous != NULL) &&
                        (previous->parent == node->parent)) {
                        /*
@@ -1053,7 +1051,8 @@ restart:
                            }
                        }
                        if (sibling != NULL) {
-                           pos = ix + indx;
+                           pos = XSLT_RUNTIME_EXTRA(ctxt,
+                                sel->indexExtra, ival) + indx;
                            /*
                             * If the node is in a Value Tree we cannot
                             * cache it !
diff --git a/tests/docs/bug-171.xml b/tests/docs/bug-171.xml
new file mode 100644 (file)
index 0000000..658021b
--- /dev/null
@@ -0,0 +1,4 @@
+<root>
+  <text>one</text>
+  <text>two</text>
+</root>
index e33a6c6..7207e15 100644 (file)
@@ -178,6 +178,7 @@ EXTRA_DIST = \
     bug-168.out bug-168.xsl \
     bug-169.out bug-169.xsl bug-169.imp \
     bug-170.out bug-170.xsl \
+    bug-171.out bug-171.xsl \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-171.out b/tests/general/bug-171.out
new file mode 100644 (file)
index 0000000..5b87d4f
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+two
diff --git a/tests/general/bug-171.xsl b/tests/general/bug-171.xsl
new file mode 100644 (file)
index 0000000..25a7c94
--- /dev/null
@@ -0,0 +1,7 @@
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:template match="text[2]">
+    <xsl:value-of select="."/>
+  </xsl:template>
+
+  <xsl:template match="text()"/>
+</xsl:transform>