fixed bug 119946, caused by incorrect creation of "extra" variables when
authorWilliam M. Brack <wbrack@src.gnome.org>
Sat, 6 Sep 2003 17:00:16 +0000 (17:00 +0000)
committerWilliam M. Brack <wbrack@src.gnome.org>
Sat, 6 Sep 2003 17:00:16 +0000 (17:00 +0000)
* pattern.c pattern.h imports.c: fixed bug 119946, caused by
  incorrect creation of "extra" variables when compiling
  templates on imported stylesheets.
* tests/docs/Makefile.am tests/docs/bug-130.xml tests/docs/bug-130.doc
  tests/general/Makefile.am test/docs/bug-130*: added tests
  to the regression suite for this bug.

14 files changed:
ChangeLog
libxslt/imports.c
libxslt/pattern.c
libxslt/pattern.h
tests/docs/Makefile.am
tests/docs/bug-130.doc [new file with mode: 0644]
tests/docs/bug-130.xml [new file with mode: 0644]
tests/general/Makefile.am
tests/general/bug-130-imp1.imp [new file with mode: 0644]
tests/general/bug-130-imp2.imp [new file with mode: 0644]
tests/general/bug-130-imp3.imp [new file with mode: 0644]
tests/general/bug-130-imp4.imp [new file with mode: 0644]
tests/general/bug-130.out [new file with mode: 0644]
tests/general/bug-130.xsl [new file with mode: 0644]

index 54f53cc..88da810 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Sep  6 09:57:03 PDT 2003 William Brack <wbrack@mmm.com.hk>
+
+       * pattern.c pattern.h imports.c: fixed bug 119946, caused by
+         incorrect creation of "extra" variables when compiling
+         templates on imported stylesheets.
+       * tests/docs/Makefile.am tests/docs/bug-130.xml tests/docs/bug-130.doc
+         tests/general/Makefile.am test/docs/bug-130*: added tests
+         to the regression suite for this bug.
+
 Wed Sep  3 15:33:40 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
        * tests/xmlspec/*.html: tyny change HTML -> html DOCTYPE due to
index 8b9bdf3..5df2a57 100644 (file)
@@ -44,7 +44,7 @@
 #include "imports.h"
 #include "documents.h"
 #include "security.h"
-
+#include "pattern.h"
 
 
 /************************************************************************
@@ -119,6 +119,8 @@ xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) {
        res->parent = style;
        res->next = style->imports;
        style->imports = res;
+       xmlHashScan(res->templatesHash, 
+                   (xmlHashScanner) xsltNormalizeCompSteps, style);
        style->extrasNr += res->extrasNr;
        ret = 0;
     } else {
index 6d63a15..7eff45f 100644 (file)
@@ -190,6 +190,28 @@ xsltFreeCompMatchList(xsltCompMatchPtr comp) {
 }
 
 /**
+ * xsltNormalizeCompSteps:
+ * @payload: pointer to template hash table entry
+ * @data: pointer to the stylesheet
+ * @name: template match name
+ *
+ * This is a hashtable scanner function to normalize the compiled
+ * steps of an imported stylesheet.
+ */
+void xsltNormalizeCompSteps(void *payload,
+        void *data, const xmlChar *name) {
+    xsltCompMatchPtr comp = payload;
+    xsltStylesheetPtr style = data;
+    int ix;
+
+    for (ix = 0; ix < comp->nbStep; ix++) {
+        comp->steps[ix].previousExtra += style->extrasNr;
+        comp->steps[ix].indexExtra += style->extrasNr;
+        comp->steps[ix].lenExtra += style->extrasNr;
+    }
+}
+
+/**
  * xsltNewParserContext:
  * @style:  the stylesheet
  * @ctxt:  the transformation context, if done at run-time
index b0721c0..3d16610 100644 (file)
@@ -41,6 +41,10 @@ XSLTPUBFUN int XSLTCALL
                xsltTestCompMatchList   (xsltTransformContextPtr ctxt,
                                         xmlNodePtr node,
                                         xsltCompMatchPtr comp);
+XSLTPUBFUN void XSLTCALL
+               xsltNormalizeCompSteps  (void *payload,
+                                        void *data,
+                                        const xmlChar *name);
 
 /*
  * Template related interfaces.
index ffaae2e..94a9c51 100644 (file)
@@ -129,6 +129,7 @@ EXTRA_DIST =        \
        bug-127.xml \
        bug-128.xml \
        bug-129.xml \
+       bug-130.xml bug-130.doc \
        character.xml \
        array.xml \
        items.xml
diff --git a/tests/docs/bug-130.doc b/tests/docs/bug-130.doc
new file mode 100644 (file)
index 0000000..ce28433
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<document>
+<header></header>
+<article><title>title #1</title></article>
+<article><title>title #2</title></article>
+</document>
+
diff --git a/tests/docs/bug-130.xml b/tests/docs/bug-130.xml
new file mode 100644 (file)
index 0000000..c375b9a
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<?xml-stylesheet type="text/xsl" href="./transform.xsl"?>
+<frame content="./content.xml"/>
+
index d3fafa9..1f2a537 100644 (file)
@@ -134,6 +134,8 @@ EXTRA_DIST = \
     bug-127.out bug-127.xsl \
     bug-128.out bug-128.xsl \
     bug-129.out bug-129.xsl \
+    bug-130.out bug-130.xsl \
+    bug-130-imp1.imp bug-130-imp2.imp bug-130-imp3.imp bug-130-imp4.imp \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-130-imp1.imp b/tests/general/bug-130-imp1.imp
new file mode 100644 (file)
index 0000000..0d94b88
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="article">
+  <xsl:text>article in module #1;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+
+<xsl:template match="title">
+  <xsl:text>title in module #1;</xsl:text>
+</xsl:template>
+
+
+<xsl:template match="header">
+  <xsl:text>header #1 in module #1;</xsl:text>
+</xsl:template>
+
+
+<xsl:template match="header[logo]">
+  <xsl:text>header #2 in module #1;</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-130-imp2.imp b/tests/general/bug-130-imp2.imp
new file mode 100644 (file)
index 0000000..4b8cae8
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="article[position()=1]/title">
+  <xsl:text>title #1 in module #2;</xsl:text>
+</xsl:template>
+
+
+<xsl:template match="article[position()>1]/title">
+  <xsl:text>title #2 in module #2;</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-130-imp3.imp b/tests/general/bug-130-imp3.imp
new file mode 100644 (file)
index 0000000..c12538c
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="document">
+  <xsl:text>document in module #3;</xsl:text>
+  <xsl:apply-templates select="article"/>
+</xsl:template>
+
+
+<xsl:template match="article[position()=1]">
+  <xsl:text>article in module #3;</xsl:text>
+  <xsl:apply-templates select="title"/>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-130-imp4.imp b/tests/general/bug-130-imp4.imp
new file mode 100644 (file)
index 0000000..39de3c6
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="frame">
+  <div>
+    <xsl:apply-templates select="$g.doc.root/document/header"/>
+    <xsl:apply-templates select="$g.doc.root/document"/>
+  </div>
+</xsl:template>
+
+
+<xsl:template match="header">
+  <xsl:text>header #1 in module #4;</xsl:text>
+</xsl:template>
+
+
+<xsl:template match="header[logo]">
+  <xsl:text>header #2 in module #4;</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-130.out b/tests/general/bug-130.out
new file mode 100644 (file)
index 0000000..8b82528
--- /dev/null
@@ -0,0 +1 @@
+<html xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><div xmlns="">header #1 in module #4;document in module #3;article in module #3;title #1 in module #2;article in module #1;title #2 in module #2;</div></body></html>
diff --git a/tests/general/bug-130.xsl b/tests/general/bug-130.xsl
new file mode 100644 (file)
index 0000000..1ac6e9f
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns="http://www.w3.org/TR/REC-html40">
+
+<xsl:import href="./bug-130-imp1.imp"/>
+<xsl:import href="./bug-130-imp2.imp"/>
+<xsl:import href="./bug-130-imp3.imp"/>
+<xsl:import href="./bug-130-imp4.imp"/>
+
+<xsl:output method="html" indent="no"/>
+
+<xsl:variable name="g.doc.root" select="document('../docs/bug-130.doc')"/>
+
+<xsl:template match="/">
+  <html>
+    <head></head>
+    <body><xsl:apply-templates select="/frame"/></body>
+  </html>
+</xsl:template>
+
+</xsl:stylesheet>