diff --git a/ChangeLog b/ChangeLog
index d510b2f0d0332fb52c6e83b0a1d9af96fa4c04cd_Q2hhbmdlTG9n..247cd686bfd5f23177f07942e84264bf66e7dc43_Q2hhbmdlTG9n 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jan  7 19:50:02 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+	* libxslt/xslt.[ch]: started parsing stylesheet xsl:stylesheet
+
 Sun Jan  7 16:11:42 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
 	* libxslt/xslt.[ch] libxslt/xsltInternals.h libxslt/xsltproc.c:
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
index d510b2f0d0332fb52c6e83b0a1d9af96fa4c04cd_bGlieHNsdC94c2x0LmM=..247cd686bfd5f23177f07942e84264bf66e7dc43_bGlieHNsdC94c2x0LmM= 100644
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -18,9 +18,11 @@
 #include <libxslt/xslt.h>
 #include <libxslt/xsltInternals.h>
 
+#define DEBUG_PARSING
+
 /*
  * There is no XSLT specific error reporting module yet
  */
 #define xsltGenericError xmlGenericError
 #define xsltGenericErrorContext xmlGenericErrorContext
 
@@ -21,9 +23,55 @@
 /*
  * There is no XSLT specific error reporting module yet
  */
 #define xsltGenericError xmlGenericError
 #define xsltGenericErrorContext xmlGenericErrorContext
 
+/*
+ * Useful macros
+ */
+
+#define IS_XSLT_ELEM(n)							\
+    ((n)->ns != NULL) && (xmlStrEqual(cur->ns->href, XSLT_NAMESPACE))
+
+#define IS_BLANK(c) (((c) == 0x20) || ((c) == 0x09) || ((c) == 0xA) ||	\
+                     ((c) == 0x0D))
+
+#define IS_BLANK_NODE(n)						\
+    (((n)->type == XML_TEXT_NODE) && (xsltIsBlank((n)->content)))
+
+#define TODO 								\
+    xsltGenericError(xsltGenericErrorContext,				\
+	    "Unimplemented block at %s:%d\n",				\
+            __FILE__, __LINE__);
+
+#define STRANGE 							\
+    xsltGenericError(xsltGenericErrorContext,				\
+	    "Internal error at %s:%d\n",				\
+            __FILE__, __LINE__);
+
+/************************************************************************
+ *									*
+ *			Helper functions				*
+ *									*
+ ************************************************************************/
+
+/**
+ * xsltIsBlank:
+ * @str:  a string
+ *
+ * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise
+ */
+int
+xsltIsBlank(xmlChar *str) {
+    if (str == NULL)
+	return(1);
+    while (*str != 0) {
+	if (!(IS_BLANK(*str))) return(0);
+	str++;
+    }
+    return(1);
+}
+
 /************************************************************************
  *									*
  *		Routines to handle XSLT data structures			*
@@ -74,6 +122,143 @@
  ************************************************************************/
 
 /**
+ * xsltParseStylesheetTop:
+ * @style:  the XSLT stylesheet
+ * @top:  the top level "stylesheet" element
+ *
+ * scan the top level elements of an XSL stylesheet
+ */
+
+void
+xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
+    xmlNodePtr cur;
+
+    if (top == NULL)
+	return;
+    cur = top->children;
+
+    while (cur != NULL) {
+	if (IS_BLANK_NODE(cur)) {
+            cur = cur->next;
+	    continue;
+	}
+	if (!(IS_XSLT_ELEM(cur))) {
+#ifdef DEBUG_PARSING
+	    xsltGenericError(xsltGenericErrorContext,
+		    "xsltParseStylesheetTop : found foreign element %s\n",
+		    cur->name);
+#endif
+            cur = cur->next;
+	    continue;
+	}
+	if (xmlStrEqual(cur->name, "import")) {
+	    TODO /* Handle import */
+	} else
+	    break;
+	cur = cur->next;
+    }
+    while (cur != NULL) {
+	if (IS_BLANK_NODE(cur)) {
+            cur = cur->next;
+	    continue;
+	}
+	if (!(IS_XSLT_ELEM(cur))) {
+#ifdef DEBUG_PARSING
+	    xsltGenericError(xsltGenericErrorContext,
+		    "xsltParseStylesheetTop : found foreign element %s\n",
+		    cur->name);
+#endif
+            cur = cur->next;
+	    continue;
+	}
+	if (xmlStrEqual(cur->name, "import")) {
+	    xsltGenericError(xsltGenericErrorContext,
+		"xsltParseStylesheetTop: ignoring misplaced import element\n");
+        } else if (xmlStrEqual(cur->name, "include")) {
+	    TODO /* Handle include */
+        } else if (xmlStrEqual(cur->name, "strip-space")) {
+	    TODO /* Handle strip-space */
+        } else if (xmlStrEqual(cur->name, "preserve-space")) {
+	    TODO /* Handle preserve-space */
+        } else if (xmlStrEqual(cur->name, "output")) {
+	    TODO /* Handle output */
+        } else if (xmlStrEqual(cur->name, "key")) {
+	    TODO /* Handle key */
+        } else if (xmlStrEqual(cur->name, "decimal-format")) {
+	    TODO /* Handle decimal-format */
+        } else if (xmlStrEqual(cur->name, "attribute-set")) {
+	    TODO /* Handle attribute-set */
+        } else if (xmlStrEqual(cur->name, "variable")) {
+	    TODO /* Handle variable */
+        } else if (xmlStrEqual(cur->name, "param")) {
+	    TODO /* Handle param */
+        } else if (xmlStrEqual(cur->name, "template")) {
+	    TODO /* Handle template */
+        } else if (xmlStrEqual(cur->name, "namespace-alias")) {
+	    TODO /* Handle namespace-alias */
+	} else {
+	    xsltGenericError(xsltGenericErrorContext,
+		"xsltParseStylesheetTop: ignoring unknown %s element\n",
+		             cur->name);
+	}
+	cur = cur->next;
+    }
+}
+
+/**
+ * xsltParseStylesheetDoc:
+ * @doc:  and xmlDoc parsed XML
+ *
+ * parse an XSLT stylesheet building the associated structures
+ *
+ * Returns a new XSLT stylesheet structure.
+ */
+
+xsltStylesheetPtr
+xsltParseStylesheetDoc(xmlDocPtr doc) {
+    xsltStylesheetPtr ret;
+    xmlNodePtr cur;
+
+    if (doc == NULL)
+	return(NULL);
+
+    ret = xsltNewStylesheet();
+    if (ret == NULL)
+	return(NULL);
+
+    /*
+     * First step, locate the xsl:stylesheet element and the
+     * namespace declaration.
+     */
+    cur = xmlDocGetRootElement(doc);
+    if (cur == NULL) {
+        xsltGenericError(xsltGenericErrorContext,
+		"xsltParseStylesheetDoc : empty stylesheet\n");
+	xsltFreeStylesheet(ret);
+	return(NULL);
+    }
+
+    if ((IS_XSLT_ELEM(cur)) && (xmlStrEqual(cur->name, "stylesheet"))) {
+#ifdef DEBUG_PARSING
+	xsltGenericError(xsltGenericErrorContext,
+		"xsltParseStylesheetDoc : found stylesheet\n");
+#endif
+    } else {
+
+	TODO /* lookup the stylesheet element down in the tree */
+        xsltGenericError(xsltGenericErrorContext,
+		"xsltParseStylesheetDoc : root is not stylesheet\n");
+	xsltFreeStylesheet(ret);
+	return(NULL);
+    }
+    ret->doc = doc;
+
+    xsltParseStylesheetTop(ret, cur);
+
+    return(ret);
+}
+
+/**
  * xsltParseStylesheetFile:
  * @filename:  the filename/URL to the stylesheet
  *
@@ -86,7 +271,8 @@
 xsltParseStylesheetFile(const xmlChar* filename) {
     xsltStylesheetPtr ret;
     xmlDocPtr doc;
+    
 
     if (filename == NULL)
 	return(NULL);
 
@@ -89,10 +275,15 @@
 
     if (filename == NULL)
 	return(NULL);
 
+#ifdef DEBUG_PARSING
+    xsltGenericError(xsltGenericErrorContext,
+	    "xsltParseStylesheetFile : parse %s\n", filename);
+#endif
+
     doc = xmlParseFile(filename);
     if (doc == NULL) {
         xsltGenericError(xsltGenericErrorContext,
 		"xsltParseStylesheetFile : cannot parse %s\n", filename);
 	return(NULL);
     }
@@ -93,12 +284,12 @@
     doc = xmlParseFile(filename);
     if (doc == NULL) {
         xsltGenericError(xsltGenericErrorContext,
 		"xsltParseStylesheetFile : cannot parse %s\n", filename);
 	return(NULL);
     }
-    ret = xsltNewStylesheet();
+    ret = xsltParseStylesheetDoc(doc);
     if (ret == NULL) {
 	xmlFreeDoc(doc);
 	return(NULL);
     }
 
@@ -100,10 +291,8 @@
     if (ret == NULL) {
 	xmlFreeDoc(doc);
 	return(NULL);
     }
 
-    ret->doc = doc;
-
     return(ret);
 }
 
diff --git a/libxslt/xslt.h b/libxslt/xslt.h
index d510b2f0d0332fb52c6e83b0a1d9af96fa4c04cd_bGlieHNsdC94c2x0Lmg=..247cd686bfd5f23177f07942e84264bf66e7dc43_bGlieHNsdC94c2x0Lmg= 100644
--- a/libxslt/xslt.h
+++ b/libxslt/xslt.h
@@ -19,6 +19,7 @@
  * Constants.
  */
 #define XSLT_DEFAULT_VERSION     "1.0"
+#define XSLT_NAMESPACE "http://www.w3.org/1999/XSL/Transform"
 
 #ifdef __cplusplus
 }