diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2001-01-07 18:51:19 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2001-01-07 18:51:19 +0000 |
commit | aa444f717f42f87e910626870a87a35a8d364e92 (patch) | |
tree | 7d16c3abaea13f4ca63fecc5b9d6714702d978ae | |
parent | 6caca0b4ac5a40da94bbbef24958fedd7150129c (diff) | |
download | libxslt-aa444f717f42f87e910626870a87a35a8d364e92.tar.gz libxslt-aa444f717f42f87e910626870a87a35a8d364e92.tar.bz2 libxslt-aa444f717f42f87e910626870a87a35a8d364e92.zip |
- libxslt/xslt.[ch]: started parsing stylesheet xsl:stylesheet
Daniel
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | libxslt/xslt.c | 195 | ||||
-rw-r--r-- | libxslt/xslt.h | 1 |
3 files changed, 197 insertions, 3 deletions
@@ -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 e88dcda1..c3347f46 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -18,12 +18,60 @@ #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 +/* + * 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 @@ xsltFreeStylesheet(xsltStylesheetPtr sheet) { ************************************************************************/ /** + * 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,24 +271,28 @@ xsltStylesheetPtr xsltParseStylesheetFile(const xmlChar* filename) { xsltStylesheetPtr ret; xmlDocPtr doc; + 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); } - ret = xsltNewStylesheet(); + ret = xsltParseStylesheetDoc(doc); if (ret == NULL) { xmlFreeDoc(doc); return(NULL); } - ret->doc = doc; - return(ret); } diff --git a/libxslt/xslt.h b/libxslt/xslt.h index 516da332..1371dc66 100644 --- a/libxslt/xslt.h +++ b/libxslt/xslt.h @@ -19,6 +19,7 @@ extern "C" { * Constants. */ #define XSLT_DEFAULT_VERSION "1.0" +#define XSLT_NAMESPACE "http://www.w3.org/1999/XSL/Transform" #ifdef __cplusplus } |