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

Initial revision

parent 84d14a83c691
No related branches found
No related tags found
No related merge requests found
AUTHORS 0 → 100644
Daniel Veillard:
Daniel.Veillard@imag.fr
DV on #gnome IRC channel
http://veillard.com/
Used to work at W3C, now Red Hat
co-chair of W3C XML Linking WG
invited expert on the W3C XML Core WG
Author of libxml upon which this library is based.
Sun Jan 7 13:51:30 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* libxslt/xslt.[ch] libxslt/xsltInternals.h libxslt/xsltproc.c:
first steps toward building the framework
Sun Jan 7 12:22:13 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* NOTES: added notes taken while reading the spec.
Fri Jan 5 11:34:12 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* test/REC1 test/REC2: added examples from the XSLT REC
Fri Jan 5 11:14:29 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* README: basic informations
* Changelog: created
SUBDIRS = \
libxslt \
tests
confexecdir=$(libdir)
confexec_DATA = xsltConf.sh
bin_SCRIPTS = xslt-config
EXTRA_DIST = xsltConf.sh.in xslt-config.in
## We create xsltConf.sh here and not from configure because we want
## to get the paths expanded correctly. Macros like srcdir are given
## the value NONE in configure if the user doesn't specify them (this
## is an autoconf feature, not a bug).
xsltConf.sh: xsltConf.sh.in Makefile
## Use sed and then mv to avoid problems if the user interrupts.
sed -e 's?\@XSLT_LIBDIR\@?$(XSLT_LIBDIR)?g' \
-e 's?\@XSLT_INCLUDEDIR\@?$(XSLT_INCLUDEDIR)?g' \
-e 's?\@VERSION\@?$(VERSION)?g' \
-e 's?\@XSLT_LIBS\@?$(XSLT_LIBS)?g' \
< $(srcdir)/xsltConf.sh.in > xsltConf.tmp \
&& mv xsltConf.tmp xsltConf.sh
NEWS 0 → 100644
Sun Jan 7 14:54:28 CET 2001
Creating libxslt project in Gnome CVS base
Fri Jan 5
Started reading the XSLT 1.0 spec:
http://www.w3.org/TR/xslt
W3C Recommendation 16 November 1999
NOTES 0 → 100644
NOTES relative to the implementation
====================================
xsl:stylesheet:
all children except xsl:import can be in any order, so this
can be stored as one big structure.
xsl:include:
this is really similar to XInclude, can be implemented as a
nearly separate processing just after the XML stylesheet has been
parsed.
Detect loops using a limited stack ...
xsl:import:
seems this should be really implemented as having a stylesheet
sublist being itself an import list
add the list at the end
when doing a resolution explore child before siblings in the list
3 Data Model, we should operate on parsed trees
3.1 No problem
3.2 use the XML Base call, XSLT-1.1 references it
3.4 Whitespace Stripping
Seems one may have to do a bit of preprocessing on both the
stylesheet trees and the source trees.
4 Expressions
looks okay, wondering about variable bindings though...
default namespace not in scope
5.1 Processing Model
look in Michael Kay's book about how to efficiently find the
template applying to a node. Might influence the in-memory stylesheet
representation
5.2 Patterns
the end of that section suggest that the expression could be computed in
a simpler way. Maybe templates needs to be evaluated differently than
through the normal XPath processing. This can be implemented separately
or build an expression tree in the XPath module and use a different
evaluation mechanism. Not sure this is best.
5.4 Applying Template Rules
xsl:apply-templates is the recurstion mechanism, note the select
mechanism.
detection of loop: once the applied nodeset has been computed,
check that none of the elements is part of the existing set in use, this
may be costly and should be triggered only at a certain depth.
5.5 Conflict Resolution for Template Rules
Sounds again that evaluation of a pattern rule should provide one
more information not provided by the standard XPath evaluation
5.6 Overriding Template Rules
another recursion mechanism, confirm that it is needed to separate
the imported stylesheets.
5.7 Modes
Confusing ??? need an example.
6 Named Templates
No big deal it seems
7.1.1 Literal Result Elements
cleanup of the namespace template should be done initially at stylesheet
parsing.
7.1.2 Creating Elements with xsl:element
okay, I bet it's usually used with { } expression computations
7.1.3 Creating Attributes with xsl:attribute
need some running code to better understand all the subtilties
7.1.4 Named Attribute Sets
Okay just a way to mimick param entities use fo attrib groups in Dtd's
7.2 Creating Text
adjacent text nodes are merged ... okay
output escapeing might need a libxml API extension
7.3 Creating Processing Instructions
7.4 Creating Comments
RAS, one just need to make a couple of trivial checks
7.5 Copying
Okay will need some testing
7.6.1 Generating Text with xsl:value-of
will be a good test for XPath string() function
note in the example that the text nodes are coalesced
7.6.2 Attribute Value Templates
hum, this is
- contextual
- uses XPath
best seems to parse, generate an evaluation tree then evaluate
when accessed. Note that multipe expressions can be associated to
a single attribute. Sounds like i will have to introduce a new
element type inserted in the attribute nodelist. dohh ...
7.7 Numbering
sounds interesting for users but might be costly, we will see ...
7.7.1 Number to String Conversion Attributes
format="..." :-( it's gonna be painful ...
8 Repetition
9 Conditional Processing
doesn't sounds hard to implement since we are at an interpreter
level but really useful in practice. Will be simple once the overall
framework is set-up.
10 Sorting
Okay applied to the node list of an xsl:apply-templates or xsl:for-each
The NOTEs are a bit scary ...
11 Variables and Parameters
Variables can only be afttected at the top level, so it
seems they act only as global variables ...
But this is by regions .... so some of the statements within
a stylesheet my use a different set than others ... in practice
it turns to be nearly like loacal variables ....
Need more thinking on this to handle it properly.
Might explain on of TOM's requests w.r.t. variable resolution
11.1 Result Tree Fragments
Dohhh a new type ...
actually it's just a node set restricted type
11.2 Values of Variables and Parameters
okay, real problem is scoping ...
11.3 Using Values of Variables and Parameters with xsl:copy-of
No surprize
11.4 Top-level Variables and Parameters
It is an error if a stylesheet contains more than one binding
of a top-level variable with the same name and same import precedence
=> ah ah, so it seems one can associate the variable bindings
to a stylesheet and if needed recurse down the import list if not
found, would simplify things a lot !
If the template or expression specifying the value of a global variable
x references a global variable y, then the value for y must be computed
before the value of x.
=> Values can probably be computed dynamically at reference
time, if this generate a loop, then it's an error. Lazy computations
are great ...
11.5 Variables and Parameters within Templates
xsl:variable is allowed anywhere within a template that an instruction
is allowed. In this case, the binding is visible for all following siblings
and their descendants.
It is an error if a binding established by an xsl:variable or xsl:param
element within a template shadows another binding established by an
xsl:variable or xsl:param element also within the template.
=> the example seems to imply that we can simply keep a list of
local variable binding to a template ... sounds fine.
11.6 Passing Parameters to Templates
=> Okay the parameter overrides the local binding
12.1 Multiple Source Documents
12.2 Keys
skipped for now
12.3 Number Formatting
reimplementing Java formatting in C is gonna be a pain !
12.4 Miscellaneous Additional Functions
current() => trivial
unparsed-entity-uri() => support in uri.c should do
generate-id() => use the in-memory address of the node ???
system-property() => sounds simple
13 Messages
trivial I/Os
14 Extensions
15 Fallback
skipped for now
16 Output
16.1 XML Output Method
sounds that calling directly libxml output on the result tree
should do it with a few caveats, for example one need to be
able to parametrize the output
16.2 HTML Output Method
sounds that calling libxml HTML output should do it too
16.3 Text Output Method
doesn't sounds too hard ...
16.4 Disabling Output Escaping
hum ... might be a bit painful to implement with the current framework.
README 0 → 100644
XSLT support for libxml
http://xmlsoft.org/
Requires libxml2 with XPath support.
Currently unusable, very early steps ...
Daniel Veillard
Daniel.Veillard@imag.fr
$Id$
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
THEDIR=`pwd`
cd $srcdir
DIE=0
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile gnome-xml."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
(libtool --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have libtool installed to compile gnome-xml."
echo "Get ftp://alpha.gnu.org/gnu/libtool-1.0h.tar.gz"
echo "(or a newer version if it is available)"
DIE=1
}
(automake --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have automake installed to compile gnome-xml."
echo "Get ftp://ftp.cygnus.com/pub/home/tromey/automake-1.2d.tar.gz"
echo "(or a newer version if it is available)"
DIE=1
}
if test "$DIE" -eq 1; then
exit 1
fi
test -f libxslt/xslt.h || {
echo "You must run this script in the top-level gdome directory"
exit 1
}
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
echo "Running libtoolize..."
libtoolize --copy --force
echo "Running aclocal..."
aclocal $ACLOCAL_FLAGS
echo "Running automake..."
automake --add-missing
echo "Running autoconf..."
autoconf
cd $THEDIR
if test x$OBJ_DIR != x; then
mkdir -p "$OBJ_DIR"
cd "$OBJ_DIR"
fi
conf_flags="--enable-maintainer-mode --enable-compile-warnings" #--enable-iso-c
echo Running configure $conf_flags "$@" ...
$srcdir/configure $conf_flags "$@"
echo
echo "Now type 'make' to compile libxslt."
/* config.h.in. Generated automatically from configure.in by autoheader. */
/* Define if you need to in order for stat and other things to work. */
#undef _POSIX_SOURCE
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
AC_INIT(libxslt/xslt.c)
VERSION=0.0
PACKAGE=libxslt
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
AM_MAINTAINER_MODE
dnl
dnl The following new parameters were added to offer
dnl the ability to specify the location of the libxml
dnl library during linking and compilation.
dnl Mathieu Lacage 30/03/2000
dnl
LIBXML_PREFIX=""
AC_ARG_WITH(libxml-prefix,
[ --with-libxml-prefix=[PFX] Specify location of libxml],
LIBXML_PREFIX=$withval
)
AC_ARG_WITH(libxml-include-prefix,
[ --with-libxml-include-prefix=[PFX] Specify location of libxml headers],
LIBXML_CFLAGS="-I$withval"
)
AC_ARG_WITH(libxml-libs-prefix,
[ --with-libxml-libs-prefix=[PFX] Specify location of libxml libs],
LIBXML_LIBS="-L$withval -lxml -lz"
)
dnl
dnl Check the environment
dnl
AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AC_ARG_PROGRAM
AM_PROG_LIBTOOL
dnl No internationalization (yet ?)
dnl
dnl ALL_LINGUAS="it ko fr de es no ga sv pt ja fi cs"
dnl AM_GNU_GETTEXT
dnl
dnl AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
dnl
dnl find libxml
dnl
XML_CONFIG="xml-config"
AC_MSG_CHECKING(for libxml libraries >= 2.x)
if test "x$LIBXML_PREFIX" != "x"
then
if ${LIBXML_PREFIX}/bin/xml-config --libs print > /dev/null 2>&1
then
XML_CONFIG=${LIBXML_PREFIX}/bin/xml-config
else
XML_CONFIG=xml-config
fi
fi
dnl
dnl test version and init our variables
dnl
if test "x$XML_CONFIG" != "x"
then
vers=`$XML_CONFIG --version | sed -e 's/libxml //' | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
if test "$vers" -ge 2000000
then
LIBXML_LIBS="`$XML_CONFIG --libs`"
LIBXML_CFLAGS="`$XML_CONFIG --cflags`"
AC_MSG_RESULT(found)
else
AC_MSG_ERROR(You need at least libxml 2.x for this version of libxml)
fi
else
AC_MSG_ERROR(Could not find libxml anywhere.)
fi
AC_SUBST(XML_CONFIG)
AC_SUBST(LIBXML_LIBS)
AC_SUBST(LIBXML_CFLAGS)
XSLT_LIBDIR='-L${libdir}'
XSLT_INCLUDEDIR='-I${includedir}'
XSLT_LIBS="-lxslt $LIBXML_LIBS"
AC_SUBST(XSLT_LIBDIR)
AC_SUBST(XSLT_INCLUDEDIR)
AC_SUBST(XSLT_LIBS)
AC_OUTPUT([
Makefile
libxslt/Makefile
tests/Makefile
xslt-config
])
INCLUDES = -I$(top_srcdir)/libxslt \
$(LIBXML_CFLAGS) -Wall -ansi
lib_LTLIBRARIES = libxslt.la
libxslt_la_SOURCES = \
xslt.c \
xslt.h \
xsltInternals.h
# what is this include dir ?
# libxsltincdir = $(includedir)/libxslt
noinst_PROGRAMS = xsltproc
DEPS = $(top_builddir)/libxslt/libxslt.la
LDADDS = $(top_builddir)/libxslt/libxslt.la $(LIBXML_LIBS)
xsltproc_SOURCES = xsltproc.c
xsltproc_LDFLAGS =
xsltproc_DEPENDENCIES = $(DEPS)
xsltproc_LDADD = $(LDADDS)
/*
* xslt.h: Implemetation of an XSL Transformation 1.0 engine
*
* Reference:
* http://www.w3.org/TR/1999/REC-xslt-19991116
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@imag.fr
*/
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
/************************************************************************
* *
* Routines to handle XSLT data structures *
* *
************************************************************************/
/**
* xsltFreeStylesheet:
* @sheet: an XSLT stylesheet
*
* Free up the memory allocated by @sheet
*/
void
xsltFreeStylesheet(xsltStylesheetPtr sheet) {
}
/************************************************************************
* *
* Parsing of an XSLT Stylesheet *
* *
************************************************************************/
/**
* xsltParseStylesheetFile:
* @filename: the filename/URL to the stylesheet
*
* Load and parse an XSLT stylesheet
*
* Returns a new XSLT stylesheet structure.
*/
xsltStylesheetPtr
xsltParseStylesheetFile(const xmlChar* filename) {
xsltStylesheetPtr ret;
return(ret);
}
/*
* xslt.h: Interfaces, constants and types related to the XSLT engine
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@imag.fr
*/
#ifndef __XML_XSLT_H__
#define __XML_XSLT_H__
#include <libxml/tree.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants.
*/
#define XSLT_DEFAULT_VERSION "1.0"
#ifdef __cplusplus
}
#endif
#endif /* __XML_XSLT_H__ */
/*
* xsltInternals.h: internal data structures, constants and functions used
* by the XSLT engine
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@imag.fr
*/
#ifndef __XML_XSLT_INTERNALS_H__
#define __XML_XSLT_INTERNALS_H__
#include <libxml/tree.h>
#include <libxml/hash.h>
#include <libxslt/xslt.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _xsltStylesheet xsltStylesheet;
typedef xsltStylesheet *xsltStylesheetPtr;
struct _xsltStylesheet {
};
/*
* Functions associated to the internal types
*/
xsltStylesheetPtr xsltParseStylesheetFile (const xmlChar* filename);
#ifdef __cplusplus
}
#endif
#endif /* __XML_XSLT_H__ */
/*
* xsltproc.c: user program for the XSL Transformation 1.0 engine
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@imag.fr
*/
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
static int debug = 0;
int
main(int argc, char **argv) {
int i, count;
int files = 0;
xsltStylesheetPtr cur;
LIBXML_TEST_VERSION
for (i = 1; i < argc ; i++) {
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
debug++;
}
xmlSubstituteEntitiesDefault(1);
for (i = 1; i < argc ; i++) {
if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
cur = xsltParseStylesheetFile(argv[i]);
xsltFreeStylesheet(cur);
break;
}
}
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
## Process this file with automake to produce Makefile.in
INCLUDES = -I$(srcdir) -I$(top_srcdir)/libxslt \
$(LIBXML_CFLAGS) -Wall -ansi
noinst_PROGRAMS = # testxslt testevents
DEPS = $(top_builddir)/libxslt/libxslt.la
LDADDS = $(top_builddir)/libxslt/libxslt.la $(LIBXML_LIBS)
#testxslt_SOURCES = test-xslt.c
#testxslt_LDFLAGS =
#testxslt_DEPENDENCIES = $(DEPS)
#testxslt_LDADD = $(LDADDS)
#
#testevents_SOURCES = test-events.c
#testevents_LDFLAGS =
#testevents_DEPENDENCIES = $(DEPS)
#testevents_LDADD = $(LDADDS)
<!ELEMENT doc (title, chapter*)>
<!ELEMENT chapter (title, (para|note)*, section*)>
<!ELEMENT section (title, (para|note)*)>
<!ELEMENT title (#PCDATA|emph)*>
<!ELEMENT para (#PCDATA|emph)*>
<!ELEMENT note (#PCDATA|emph)*>
<!ELEMENT emph (#PCDATA|emph)*>
<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>
<title>Document Title</title>
<chapter>
<title>Chapter Title</title>
<section>
<title>Section Title</title>
<para>This is a test.</para>
<note>This is a note.</note>
</section>
<section>
<title>Another Section Title</title>
<para>This is <emph>another</emph> test.</para>
<note>This is another note.</note>
</section>
</chapter>
</doc>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:strip-space elements="doc chapter section"/>
<xsl:output
method="xml"
indent="yes"
encoding="iso-8859-1"
/>
<xsl:template match="doc">
<html>
<head>
<title>
<xsl:value-of select="title"/>
</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="doc/title">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>
<xsl:template match="chapter/title">
<h2>
<xsl:apply-templates/>
</h2>
</xsl:template>
<xsl:template match="section/title">
<h3>
<xsl:apply-templates/>
</h3>
</xsl:template>
<xsl:template match="para">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="note">
<p class="note">
<b>NOTE: </b>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="emph">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<title>Document Title</title>
</head>
<body>
<h1>Document Title</h1>
<h2>Chapter Title</h2>
<h3>Section Title</h3>
<p>This is a test.</p>
<p class="note">
<b>NOTE: </b>This is a note.</p>
<h3>Another Section Title</h3>
<p>This is <em>another</em> test.</p>
<p class="note">
<b>NOTE: </b>This is another note.</p>
</body>
</html>
<sales>
<division id="North">
<revenue>10</revenue>
<growth>9</growth>
<bonus>7</bonus>
</division>
<division id="South">
<revenue>4</revenue>
<growth>3</growth>
<bonus>4</bonus>
</division>
<division id="West">
<revenue>6</revenue>
<growth>-1.5</growth>
<bonus>2</bonus>
</division>
</sales>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment