From aa250927e6a919ba1a35189635e2e5084416f489 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Sun, 4 Aug 2013 22:25:03 +0200
Subject: [PATCH 08/14] Fix direct pattern matching

xsltTestCompMatchDirect must match against the original node.
---
 libxslt/pattern.c         |  5 +++--
 tests/REC/test-5.2-22.out |  2 ++
 tests/REC/test-5.2-22.xml |  3 +++
 tests/REC/test-5.2-22.xsl | 13 +++++++++++++
 4 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 tests/REC/test-5.2-22.out
 create mode 100644 tests/REC/test-5.2-22.xml
 create mode 100644 tests/REC/test-5.2-22.xsl

diff --git a/libxslt/pattern.c b/libxslt/pattern.c
index 414363b..058917a 100644
--- a/libxslt/pattern.c
+++ b/libxslt/pattern.c
@@ -906,9 +906,10 @@ xsltTestPredicateMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp,
  */
 static int
 xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp,
-	          xmlNodePtr node, const xmlChar *mode,
+	          xmlNodePtr matchNode, const xmlChar *mode,
 		  const xmlChar *modeURI) {
     int i;
+    xmlNodePtr node = matchNode;
     xsltStepOpPtr step, sel = NULL;
     xsltStepStates states = {0, 0, NULL}; /* // may require backtrack */
 
@@ -1137,7 +1138,7 @@ restart:
 			/* Free the rollback states */
 			xmlFree(states.states);
 		    }
-		    return(xsltTestCompMatchDirect(ctxt, comp, node,
+		    return(xsltTestCompMatchDirect(ctxt, comp, matchNode,
 						   comp->nsList, comp->nsNr));
 		}
 
diff --git a/tests/REC/test-5.2-22.out b/tests/REC/test-5.2-22.out
new file mode 100644
index 0000000..951594e
--- /dev/null
+++ b/tests/REC/test-5.2-22.out
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc>success</doc>
diff --git a/tests/REC/test-5.2-22.xml b/tests/REC/test-5.2-22.xml
new file mode 100644
index 0000000..658099d
--- /dev/null
+++ b/tests/REC/test-5.2-22.xml
@@ -0,0 +1,3 @@
+<doc>
+    <elem/>
+</doc>
diff --git a/tests/REC/test-5.2-22.xsl b/tests/REC/test-5.2-22.xsl
new file mode 100644
index 0000000..5c1f1f7
--- /dev/null
+++ b/tests/REC/test-5.2-22.xsl
@@ -0,0 +1,13 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+    <xsl:template match="doc">
+        <xsl:copy>
+            <xsl:apply-templates select="*"/>
+        </xsl:copy>
+    </xsl:template>
+
+    <xsl:template match="doc[last()][last()]/elem">
+        <xsl:text>success</xsl:text>
+    </xsl:template>
+
+</xsl:stylesheet>
-- 
1.8.4.1

