1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-11-08 11:02:18 +03:00

- libxslt/xslt.[ch]: started parsing stylesheet xsl:stylesheet

Daniel
This commit is contained in:
Daniel Veillard
2001-01-07 18:51:19 +00:00
parent 6caca0b4ac
commit aa444f717f
3 changed files with 197 additions and 3 deletions

View File

@@ -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> Sun Jan 7 16:11:42 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* libxslt/xslt.[ch] libxslt/xsltInternals.h libxslt/xsltproc.c: * libxslt/xslt.[ch] libxslt/xsltInternals.h libxslt/xsltproc.c:

View File

@@ -18,12 +18,60 @@
#include <libxslt/xslt.h> #include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h> #include <libxslt/xsltInternals.h>
#define DEBUG_PARSING
/* /*
* There is no XSLT specific error reporting module yet * There is no XSLT specific error reporting module yet
*/ */
#define xsltGenericError xmlGenericError #define xsltGenericError xmlGenericError
#define xsltGenericErrorContext xmlGenericErrorContext #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 * * Routines to handle XSLT data structures *
@@ -73,6 +121,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: * xsltParseStylesheetFile:
* @filename: the filename/URL to the stylesheet * @filename: the filename/URL to the stylesheet
@@ -87,23 +272,27 @@ xsltParseStylesheetFile(const xmlChar* filename) {
xsltStylesheetPtr ret; xsltStylesheetPtr ret;
xmlDocPtr doc; xmlDocPtr doc;
if (filename == NULL) if (filename == NULL)
return(NULL); return(NULL);
#ifdef DEBUG_PARSING
xsltGenericError(xsltGenericErrorContext,
"xsltParseStylesheetFile : parse %s\n", filename);
#endif
doc = xmlParseFile(filename); doc = xmlParseFile(filename);
if (doc == NULL) { if (doc == NULL) {
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
"xsltParseStylesheetFile : cannot parse %s\n", filename); "xsltParseStylesheetFile : cannot parse %s\n", filename);
return(NULL); return(NULL);
} }
ret = xsltNewStylesheet(); ret = xsltParseStylesheetDoc(doc);
if (ret == NULL) { if (ret == NULL) {
xmlFreeDoc(doc); xmlFreeDoc(doc);
return(NULL); return(NULL);
} }
ret->doc = doc;
return(ret); return(ret);
} }

View File

@@ -19,6 +19,7 @@ extern "C" {
* Constants. * Constants.
*/ */
#define XSLT_DEFAULT_VERSION "1.0" #define XSLT_DEFAULT_VERSION "1.0"
#define XSLT_NAMESPACE "http://www.w3.org/1999/XSL/Transform"
#ifdef __cplusplus #ifdef __cplusplus
} }