# HG changeset patch
# User Daniel Veillard <veillard@src.gnome.org>
# Date 1042412339 0
#      Sun Jan 12 22:58:59 2003 +0000
# Node ID f15da7b56debabf12178452578d2ec346d55e437
# Parent  06b7f9bd83afd1e7346a48e2465074553eb9b95b
fixed bug #101003 on attribute-sets value computation in the presence of

* libxslt/attributes.c libxslt/xsltInternals.h libxslt/imports.c
  libxslt/xslt.c: fixed bug #101003 on attribute-sets value
  computation in the presence of imports
* tests/docs/Makefile.am tests/docs/bug-102.xml
  tests/general/Makefile.am tests/general/bug-102*: added an
  example in the regression tests for this case
Daniel

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sun Jan 12 23:56:18 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+	* libxslt/attributes.c libxslt/xsltInternals.h libxslt/imports.c
+	  libxslt/xslt.c: fixed bug #101003 on attribute-sets value
+	  computation in the presence of imports
+	* tests/docs/Makefile.am tests/docs/bug-102.xml
+	  tests/general/Makefile.am tests/general/bug-102*: added an
+	  example in the regression tests for this case
+
 Fri Jan 10 10:34:23 CET 2003 Daniel Veillard <daniel@veillard.com>
 
 	* xsltproc/xsltproc.c: final touch to #102800 fix
diff --git a/libxslt/imports.c b/libxslt/imports.c
--- a/libxslt/imports.c
+++ b/libxslt/imports.c
@@ -114,7 +114,7 @@
 	goto error;
     }
 
-    res = xsltParseStylesheetDoc(import);
+    res = xsltParseStylesheetImportedDoc(import);
     if (res != NULL) {
 	res->parent = style;
 	res->next = style->imports;
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -1945,7 +1945,38 @@
 	template->content = doc->children;
 	xsltAddTemplate(ret, template, NULL, NULL);
     }
-    xsltResolveStylesheetAttributeSet(ret);
+
+    return(ret);
+}
+
+/**
+ * xsltParseStylesheetImportedDoc:
+ * @doc:  and xmlDoc parsed XML
+ *
+ * parse an XSLT stylesheet building the associated structures
+ * except the processing not needed for imported documents.
+ *
+ * Returns a new XSLT stylesheet structure.
+ */
+
+xsltStylesheetPtr
+xsltParseStylesheetImportedDoc(xmlDocPtr doc) {
+    xsltStylesheetPtr ret;
+
+    if (doc == NULL)
+	return(NULL);
+
+    ret = xsltNewStylesheet();
+    if (ret == NULL)
+	return(NULL);
+    
+    ret->doc = doc;
+    xsltGatherNamespaces(ret);
+    if (xsltParseStylesheetProcess(ret, doc) == NULL) {
+	ret->doc = NULL;
+	xsltFreeStylesheet(ret);
+	ret = NULL;
+    }
 
     return(ret);
 }
@@ -1963,20 +1994,11 @@
 xsltParseStylesheetDoc(xmlDocPtr doc) {
     xsltStylesheetPtr ret;
 
-    if (doc == NULL)
-	return(NULL);
-
-    ret = xsltNewStylesheet();
+    ret = xsltParseStylesheetImportedDoc(doc);
     if (ret == NULL)
 	return(NULL);
-    
-    ret->doc = doc;
-    xsltGatherNamespaces(ret);
-	if (xsltParseStylesheetProcess(ret, doc) == NULL) {
-		ret->doc = NULL;
-		xsltFreeStylesheet(ret);
-		ret = NULL;
-	}
+
+    xsltResolveStylesheetAttributeSet(ret);
 
     return(ret);
 }
diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h
--- a/libxslt/xsltInternals.h
+++ b/libxslt/xsltInternals.h
@@ -542,6 +542,7 @@
 void			xsltParseStylesheetOutput(xsltStylesheetPtr style,
 						  xmlNodePtr cur);
 xsltStylesheetPtr	xsltParseStylesheetDoc	(xmlDocPtr doc);
+xsltStylesheetPtr	xsltParseStylesheetImportedDoc(xmlDocPtr doc);
 xsltStylesheetPtr	xsltLoadStylesheetPI	(xmlDocPtr doc);
 void 			xsltNumberFormat	(xsltTransformContextPtr ctxt,
 						 xsltNumberDataPtr data,
diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am
--- a/tests/docs/Makefile.am
+++ b/tests/docs/Makefile.am
@@ -101,6 +101,7 @@
 	bug-99.xml \
 	bug-100.xml \
 	bug-101.xml \
+	bug-102.xml \
 	character.xml \
 	array.xml \
 	items.xml
diff --git a/tests/docs/bug-102.xml b/tests/docs/bug-102.xml
new file mode 100644
--- /dev/null
+++ b/tests/docs/bug-102.xml
@@ -0,0 +1,1 @@
+<doc/>
diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am
--- a/tests/general/Makefile.am
+++ b/tests/general/Makefile.am
@@ -105,6 +105,8 @@
     bug-99.out bug-99.xsl \
     bug-100.out bug-100.xsl \
     bug-101.out bug-101.xsl \
+    bug-102.out bug-102.xsl \
+    bug-102-inc.out bug-102-inc.xsl \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-102-inc.out b/tests/general/bug-102-inc.out
new file mode 100644
--- /dev/null
+++ b/tests/general/bug-102-inc.out
@@ -0,0 +1,3 @@
+<font text-align="start" size="+1">
+    foo
+    </font>
diff --git a/tests/general/bug-102-inc.xsl b/tests/general/bug-102-inc.xsl
new file mode 100644
--- /dev/null
+++ b/tests/general/bug-102-inc.xsl
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0" 
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:output method="html"/>
+ 
+  <xsl:attribute-set name="foo-attribs">
+    <xsl:attribute name="size">+1</xsl:attribute>
+  </xsl:attribute-set>
+
+  <xsl:attribute-set name="foo-dep-attribs"
+    use-attribute-sets="foo-attribs">
+    <xsl:attribute name="text-align">start</xsl:attribute>
+  </xsl:attribute-set>
+ 
+  <xsl:template match="/">
+    <font xsl:use-attribute-sets="foo-dep-attribs">
+    foo
+    </font>
+  </xsl:template>
+ 
+</xsl:stylesheet>
diff --git a/tests/general/bug-102.out b/tests/general/bug-102.out
new file mode 100644
--- /dev/null
+++ b/tests/general/bug-102.out
@@ -0,0 +1,3 @@
+<font text-align="start" size="+2">
+    foo
+    </font>
diff --git a/tests/general/bug-102.xsl b/tests/general/bug-102.xsl
new file mode 100644
--- /dev/null
+++ b/tests/general/bug-102.xsl
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0" 
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
+  <xsl:import href="bug-102-inc.xsl"/>
+  
+  <xsl:attribute-set name="foo-attribs">
+    <xsl:attribute name="size">+2</xsl:attribute>
+  </xsl:attribute-set>
+  
+</xsl:stylesheet>