fixed bug #86421 added the example in the regression tests for this case
authorDaniel Veillard <veillard@src.gnome.org>
Thu, 17 Oct 2002 14:34:07 +0000 (14:34 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Thu, 17 Oct 2002 14:34:07 +0000 (14:34 +0000)
* libxslt/variables.c: fixed bug #86421
* tests/docs/Makefile.am tests/docs/bug-94.xml
  tests/general/Makefile.am tests/general/bug-94.*: added the
  example in the regression tests for this case
Daniel

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

index bf9c7dd..530b33c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Oct 17 16:32:44 CEST 2002 Daniel Veillard <daniel@veillard.com>
+
+       * libxslt/variables.c: fixed bug #86421 
+       * tests/docs/Makefile.am tests/docs/bug-94.xml
+         tests/general/Makefile.am tests/general/bug-94.*: added the
+         example in the regression tests for this case
+
 Thu Oct 17 15:50:04 CEST 2002 Daniel Veillard <daniel@veillard.com>
 
        * xsltproc: added and tested the --path option to close #79638
index 61f5d3e..0bcb59b 100644 (file)
@@ -142,7 +142,8 @@ xsltFreeStackElemList(xsltStackElemPtr elem) {
  *
  * check wether the variable or param is already defined
  *
- * Returns 1 if present, 0 if not, -1 in case of failure.
+ * Returns 1 if variable is present, 2 if param is present, 3 if this
+ *         is an inherited param, 0 if not found, -1 in case of failure.
  */
 static int
 xsltCheckStackElem(xsltTransformContextPtr ctxt, const xmlChar *name,
@@ -158,6 +159,12 @@ xsltCheckStackElem(xsltTransformContextPtr ctxt, const xmlChar *name,
            if (((nameURI == NULL) && (cur->nameURI == NULL)) ||
                ((nameURI != NULL) && (cur->nameURI != NULL) &&
                 (xmlStrEqual(nameURI, cur->nameURI)))) {
+               if ((cur->comp != NULL) &&
+                   (cur->comp->type == XSLT_FUNC_WITHPARAM))
+                   return(3);
+               if ((cur->comp != NULL) &&
+                   (cur->comp->type == XSLT_FUNC_PARAM))
+                   return(2);
                return(1);
            }
        }
@@ -1035,16 +1042,24 @@ static int
 xsltRegisterVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
                     xmlNodePtr tree, int param) {
     xsltStackElemPtr elem;
+    int present;
 
-    if (xsltCheckStackElem(ctxt, comp->name, comp->ns) != 0) {
-       if (!param) {
+    present = xsltCheckStackElem(ctxt, comp->name, comp->ns);
+    if (param == 0) {
+       if ((present != 0) && (present != 3)) {
            xsltTransformError(ctxt, NULL, comp->inst,
-           "xsl:variable : redefining %s\n", comp->name);
+               "xsl:variable : redefining %s\n", comp->name);
+           return(0);
+       }
+    } else if (present != 0) {
+       if ((present == 1) || (present == 2)) {
+           xsltTransformError(ctxt, NULL, comp->inst,
+               "xsl:param : redefining %s\n", comp->name);
+           return(0);
        }
 #ifdef WITH_XSLT_DEBUG_VARIABLE
-       else
-           xsltGenericDebug(xsltGenericDebugContext,
-                    "param %s defined by caller\n", comp->name);
+       xsltGenericDebug(xsltGenericDebugContext,
+                "param %s defined by caller\n", comp->name);
 #endif
        return(0);
     }
index 9cb56fa..4438444 100644 (file)
@@ -93,6 +93,7 @@ EXTRA_DIST =  \
        bug-91.xml \
        bug-92.xml \
        bug-93.xml \
+       bug-94.xml \
        character.xml \
        array.xml \
        items.xml
diff --git a/tests/docs/bug-94.xml b/tests/docs/bug-94.xml
new file mode 100644 (file)
index 0000000..10935f7
--- /dev/null
@@ -0,0 +1,9 @@
+<source>
+
+<number>1</number>
+<number>3</number>
+<number>4</number>
+<number>17</number>
+<number>8</number>
+
+</source> 
index 0903b3a..705cc31 100644 (file)
@@ -97,6 +97,7 @@ EXTRA_DIST = \
     bug-92.out bug-92.xsl \
     bug-93.out bug-93.xsl \
     bug-93-inc.out bug-93-inc.xsl \
+    bug-94.out bug-94.xsl \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-94.out b/tests/general/bug-94.out
new file mode 100644 (file)
index 0000000..a484d1e
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<TABLE><TR><TH>1 (even)</TH></TR><TR><TH>3 (even)</TH></TR><TR><TH>4 (even)</TH></TR><TR><TH>17 (even)</TH></TR><TR><TH>8 (even)</TH></TR></TABLE>
diff --git a/tests/general/bug-94.xsl b/tests/general/bug-94.xsl
new file mode 100644 (file)
index 0000000..2cb2ff4
--- /dev/null
@@ -0,0 +1,35 @@
+<xsl:stylesheet version = '1.0'
+     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
+<!-- borrowed from http://www.zvon.org/xxl/XSLTutorial/Output/example35_ch9.html -->
+
+<xsl:template match="/">
+     <TABLE>
+          <xsl:for-each select="//number">
+               <TR>
+                    <TH>
+                         <xsl:choose>
+                              <xsl:when test="text() mod 2">
+                                   <xsl:apply-templates select=".">
+                                        <xsl:with-param name="type">odd</xsl:with-param>
+                                   </xsl:apply-templates>
+                              </xsl:when>
+                              <xsl:otherwise>
+                                   <xsl:apply-templates select="."/>
+                              </xsl:otherwise>
+                         </xsl:choose>
+                    </TH>
+               </TR>
+          </xsl:for-each>
+     </TABLE>
+</xsl:template>
+
+<xsl:template match="number">
+     <xsl:variable name="type">even</xsl:variable>
+     <xsl:value-of select="."/>
+     <xsl:text> (</xsl:text>
+     <xsl:value-of select="$type"/>
+     <xsl:text>)</xsl:text>
+</xsl:template>
+
+
+</xsl:stylesheet>