Skip to content
Snippets Groups Projects
Commit 633bc556eed6 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

- libxslt/xslt.c: check version on stylesheets

- libxslt/xslt.c libxslt/xsltInternals.h libxslt/variables[.ch]:
  started adding variables interfaces and modules.
Daniel
parent 2ba2d52a199b
Branches
No related tags found
No related merge requests found
Fri Jan 19 13:16:57 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* libxslt/xslt.c: check version on stylesheets
* libxslt/xslt.c libxslt/xsltInternals.h libxslt/variables[.ch]:
started adding variables interfaces and modules.
Thu Jan 18 16:08:38 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* libxslt/xslt.c: added support for disable-output-escaping
......
......@@ -40,3 +40,8 @@
-> add lang and case-order
-> add foreign sorting functions (interfaces ?).
Validity:
-> should we add validation by default ? Make this an option
-> redirrect validity errors
......@@ -10,6 +10,8 @@
xsltutils.h \
pattern.c \
pattern.h \
variables.c \
variables.h \
transform.c \
transform.h \
xsltInternals.h
......
/*
* variables.c: Implementation of the variable storage and lookup
*
* Reference:
* http://www.w3.org/TR/1999/REC-xslt-19991116
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@imag.fr
*/
#include "xsltconfig.h"
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/valid.h>
#include <libxml/hash.h>
#include <libxml/xmlerror.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "xsltutils.h"
#include "variables.h"
#define DEBUG_VARIABLES
/*
* Types are private:
*/
/************************************************************************
* *
* Module interfaces *
* *
************************************************************************/
/**
* xsltRegisterVariable:
* @style: the XSLT stylesheet
* @name: the variable name
* @ns_uri: the variable namespace URI
* @value: the variable value or NULL
*
* Register a new variable value. If @value is NULL it unregisters
* the variable
*
* Returns 0 in case of success, -1 in case of error
*/
int
xsltRegisterVariable(xsltStylesheetPtr style, const xmlChar *name,
const xmlChar *ns_uri, xmlXPathObjectPtr value) {
if (style == NULL)
return(-1);
if (name == NULL)
return(-1);
if (style->variablesHash == NULL)
style->variablesHash = xmlHashCreate(0);
if (style->variablesHash == NULL)
return(-1);
return(xmlHashUpdateEntry2((xmlHashTablePtr) style->variablesHash,
name, ns_uri,
(void *) value,
(xmlHashDeallocator) xmlXPathFreeObject));
}
/**
* xsltVariableLookup:
* @style: the XSLT stylesheet
* @name: the variable name
* @ns_uri: the variable namespace URI
*
* Search in the Variable array of the context for the given
* variable value.
*
* Returns the value or NULL if not found
*/
xmlXPathObjectPtr
xsltVariableLookup(xsltStylesheetPtr style, const xmlChar *name,
const xmlChar *ns_uri) {
if (style == NULL)
return(NULL);
if (style->variablesHash == NULL)
return(NULL);
if (name == NULL)
return(NULL);
return((xmlXPathObjectPtr)
xmlHashLookup2((xmlHashTablePtr) style->variablesHash,
name, ns_uri));
}
/**
* xsltFreeVariableHashes:
* @style: an XSLT stylesheet
*
* Free up the memory used by xsltAddVariable/xsltGetVariable mechanism
*/
void
xsltFreeVariableHashes(xsltStylesheetPtr style) {
if (style->variablesHash != NULL)
xmlHashFree((xmlHashTablePtr) style->variablesHash,
(xmlHashDeallocator) xmlXPathFreeObject);
}
/*
* variable.h: interface for the variable matching and lookup.
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@imag.fr
*/
#ifndef __XML_XSLT_VARIABLES_H__
#define __XML_XSLT_VARIABLES_H__
#include <libxml/xpath.h>
#include "xsltInternals.h"
#ifdef __cplusplus
extern "C" {
#endif
void xsltFreeVariableHashes (xsltStylesheetPtr style);
xmlXPathObjectPtr xsltVariableLookup (xsltStylesheetPtr style,
const xmlChar *name,
const xmlChar *ns_uri);
int xsltRegisterVariable (xsltStylesheetPtr style,
const xmlChar *name,
const xmlChar *ns_uri,
xmlXPathObjectPtr value);
#ifdef __cplusplus
}
#endif
#endif /* __XML_XSLT_VARIABLES_H__ */
......@@ -23,6 +23,7 @@
#include "xslt.h"
#include "xsltInternals.h"
#include "pattern.h"
#include "variables.h"
#include "xsltutils.h"
#define DEBUG_PARSING
......@@ -161,6 +162,7 @@
return;
xsltFreeTemplateHashes(sheet);
xsltFreeVariableHashes(sheet);
xsltFreeTemplateList(sheet->templates);
if (sheet->doc != NULL)
xmlFreeDoc(sheet->doc);
......@@ -704,9 +706,10 @@
void
xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
xmlNodePtr cur;
xmlChar *prop;
#ifdef DEBUG_PARSING
int templates = 0;
#endif
if (top == NULL)
return;
......@@ -707,9 +710,23 @@
#ifdef DEBUG_PARSING
int templates = 0;
#endif
if (top == NULL)
return;
prop = xmlGetNsProp(cur, (const xmlChar *)"version", XSLT_NAMESPACE);
if (prop == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xsl:version is missing: document may not be a stylesheet\n");
} else {
if (!xmlStrEqual(prop, (const xmlChar *)"1.0")) {
xsltGenericError(xsltGenericErrorContext,
"xsl:version: only 1.0 features are supported\n");
TODO /* set up compatibility when not XSLT 1.0 */
}
xmlFree(prop);
}
cur = top->children;
while (cur != NULL) {
......
......@@ -45,6 +45,15 @@
typedef struct _xsltStylesheet xsltStylesheet;
typedef xsltStylesheet *xsltStylesheetPtr;
struct _xsltStylesheet {
/*
* The stylesheet import relation is kept as a tree
*/
struct _xsltStylesheet *parent;
struct _xsltStylesheet *imports;
/*
* General data on the style sheet document
*/
xmlDocPtr doc; /* the parsed XML stylesheet */
xmlHashTablePtr stripSpaces;/* the hash table of the strip-space
preserve space and cdata-section elements */
......@@ -55,6 +64,11 @@
xsltTemplatePtr templates; /* the ordered list of templates */
void *templatesHash; /* hash table or wherever compiled templates
informations are stored */
/*
* Variable descriptions
*/
void *variablesHash; /* hash table or wherever variables
informations are stored */
/*
* Output related stuff.
......
......@@ -22,6 +22,8 @@
*/
xmlChar *xmlSplitQName2(const xmlChar *name, xmlChar **prefix);
void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
xmlAttrPtr xmlSetNsProp (xmlNodePtr node, xmlNsPtr ns, const xmlChar *name,
const xmlChar *value);
/*
* Useful macros
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment