mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-11-08 11:02:18 +03:00
- libxslt/xslt.c: check version on stylesheets
- libxslt/xslt.c libxslt/xsltInternals.h libxslt/variables[.ch]: started adding variables interfaces and modules. Daniel
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Thu Jan 18 16:08:38 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||||
|
|
||||||
* libxslt/xslt.c: added support for disable-output-escaping
|
* libxslt/xslt.c: added support for disable-output-escaping
|
||||||
|
|||||||
5
TODO
5
TODO
@@ -40,3 +40,8 @@ Sorting:
|
|||||||
-> add lang and case-order
|
-> add lang and case-order
|
||||||
-> add foreign sorting functions (interfaces ?).
|
-> add foreign sorting functions (interfaces ?).
|
||||||
|
|
||||||
|
Validity:
|
||||||
|
-> should we add validation by default ? Make this an option
|
||||||
|
-> redirrect validity errors
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ libxslt_la_SOURCES = \
|
|||||||
xsltutils.h \
|
xsltutils.h \
|
||||||
pattern.c \
|
pattern.c \
|
||||||
pattern.h \
|
pattern.h \
|
||||||
|
variables.c \
|
||||||
|
variables.h \
|
||||||
transform.c \
|
transform.c \
|
||||||
transform.h \
|
transform.h \
|
||||||
xsltInternals.h
|
xsltInternals.h
|
||||||
|
|||||||
111
libxslt/variables.c
Normal file
111
libxslt/variables.c
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
32
libxslt/variables.h
Normal file
32
libxslt/variables.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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 "xslt.h"
|
||||||
#include "xsltInternals.h"
|
#include "xsltInternals.h"
|
||||||
#include "pattern.h"
|
#include "pattern.h"
|
||||||
|
#include "variables.h"
|
||||||
#include "xsltutils.h"
|
#include "xsltutils.h"
|
||||||
|
|
||||||
#define DEBUG_PARSING
|
#define DEBUG_PARSING
|
||||||
@@ -161,6 +162,7 @@ xsltFreeStylesheet(xsltStylesheetPtr sheet) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
xsltFreeTemplateHashes(sheet);
|
xsltFreeTemplateHashes(sheet);
|
||||||
|
xsltFreeVariableHashes(sheet);
|
||||||
xsltFreeTemplateList(sheet->templates);
|
xsltFreeTemplateList(sheet->templates);
|
||||||
if (sheet->doc != NULL)
|
if (sheet->doc != NULL)
|
||||||
xmlFreeDoc(sheet->doc);
|
xmlFreeDoc(sheet->doc);
|
||||||
@@ -704,12 +706,27 @@ xsltParseStylesheetTemplate(xsltStylesheetPtr style, xmlNodePtr template) {
|
|||||||
void
|
void
|
||||||
xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
|
xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
|
xmlChar *prop;
|
||||||
#ifdef DEBUG_PARSING
|
#ifdef DEBUG_PARSING
|
||||||
int templates = 0;
|
int templates = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (top == NULL)
|
if (top == NULL)
|
||||||
return;
|
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;
|
cur = top->children;
|
||||||
|
|
||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
|
|||||||
@@ -45,6 +45,15 @@ struct _xsltTemplate {
|
|||||||
typedef struct _xsltStylesheet xsltStylesheet;
|
typedef struct _xsltStylesheet xsltStylesheet;
|
||||||
typedef xsltStylesheet *xsltStylesheetPtr;
|
typedef xsltStylesheet *xsltStylesheetPtr;
|
||||||
struct _xsltStylesheet {
|
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 */
|
xmlDocPtr doc; /* the parsed XML stylesheet */
|
||||||
xmlHashTablePtr stripSpaces;/* the hash table of the strip-space
|
xmlHashTablePtr stripSpaces;/* the hash table of the strip-space
|
||||||
preserve space and cdata-section elements */
|
preserve space and cdata-section elements */
|
||||||
@@ -55,6 +64,11 @@ struct _xsltStylesheet {
|
|||||||
xsltTemplatePtr templates; /* the ordered list of templates */
|
xsltTemplatePtr templates; /* the ordered list of templates */
|
||||||
void *templatesHash; /* hash table or wherever compiled templates
|
void *templatesHash; /* hash table or wherever compiled templates
|
||||||
informations are stored */
|
informations are stored */
|
||||||
|
/*
|
||||||
|
* Variable descriptions
|
||||||
|
*/
|
||||||
|
void *variablesHash; /* hash table or wherever variables
|
||||||
|
informations are stored */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output related stuff.
|
* Output related stuff.
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
xmlChar *xmlSplitQName2(const xmlChar *name, xmlChar **prefix);
|
xmlChar *xmlSplitQName2(const xmlChar *name, xmlChar **prefix);
|
||||||
void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
|
void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
|
||||||
|
xmlAttrPtr xmlSetNsProp (xmlNodePtr node, xmlNsPtr ns, const xmlChar *name,
|
||||||
|
const xmlChar *value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Useful macros
|
* Useful macros
|
||||||
|
|||||||
Reference in New Issue
Block a user