From 89d6d235cdb0a8af8172e8956abdf895ea1d73d7 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 21 Feb 2002 12:01:37 +0000 Subject: [PATCH] added documentation for the wrappers and python modules. Daniel * doc/site.xml doc/xslt.html doc/python.html doc/*.html: added documentation for the wrappers and python modules. Daniel --- ChangeLog | 5 + doc/API.html | 1 + doc/FAQ.html | 1 + doc/Makefile.am | 3 +- doc/bugs.html | 1 + doc/contribs.html | 1 + doc/docbook.html | 1 + doc/docs.html | 1 + doc/downloads.html | 1 + doc/extensions.html | 1 + doc/help.html | 1 + doc/index.html | 1 + doc/internals.html | 1 + doc/intro.html | 1 + doc/libxslt-api.xml | 17 ++- doc/libxslt-decl.txt | 41 +++--- doc/libxslt-refs.xml | 19 +-- doc/news.html | 1 + doc/python.html | 267 ++++++++++++++++++++++++++++++++++++++++ doc/site.xsl | 3 + doc/xslt.html | 181 +++++++++++++++++++++++++++ doc/xsltproc2.html | 1 + libxslt/extensions.h | 25 ++-- libxslt/preproc.h | 3 +- libxslt/xslt.c | 4 +- libxslt/xsltInternals.h | 2 + 26 files changed, 536 insertions(+), 48 deletions(-) create mode 100644 doc/python.html diff --git a/ChangeLog b/ChangeLog index a623fe8f..be59384f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 21 12:59:59 CET 2002 Daniel Veillard + + * doc/site.xml doc/xslt.html doc/python.html doc/*.html: added + documentation for the wrappers and python modules. + Wed Feb 13 14:22:22 CET 2002 Daniel Veillard * tests/docs/Makefile.am tests/docs/bug-74.xml diff --git a/doc/API.html b/doc/API.html index 8e85eafc..7dbe1311 100644 --- a/doc/API.html +++ b/doc/API.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/FAQ.html b/doc/FAQ.html index f630e0f0..792f09cd 100644 --- a/doc/FAQ.html +++ b/doc/FAQ.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/Makefile.am b/doc/Makefile.am index 109e3618..1bd57a10 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -76,7 +76,8 @@ rebuild: libxslt-sections.txt templates sgml html install-data-local: $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR) - -@INSTALL@ -m 0644 $(srcdir)/xml.html $(DESTDIR)$(TARGET_DIR) + -@INSTALL@ -m 0644 $(srcdir)/*.html $(DESTDIR)$(TARGET_DIR) + -@INSTALL@ -m 0644 $(srcdir)/*.gif $(DESTDIR)$(TARGET_DIR) -@INSTALL@ -m 0644 $(srcdir)/html/*.html $(DESTDIR)$(TARGET_DIR) -@INSTALL@ -m 0644 $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR)/tutorial diff --git a/doc/bugs.html b/doc/bugs.html index 3329b863..16ee5c51 100644 --- a/doc/bugs.html +++ b/doc/bugs.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/contribs.html b/doc/contribs.html index 324fca7b..5c6478df 100644 --- a/doc/contribs.html +++ b/doc/contribs.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/docbook.html b/doc/docbook.html index a4d22ca9..534e6690 100644 --- a/doc/docbook.html +++ b/doc/docbook.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/docs.html b/doc/docs.html index c3447bcb..b4b74ad5 100644 --- a/doc/docs.html +++ b/doc/docs.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/downloads.html b/doc/downloads.html index 7d73fa36..df1ecf14 100644 --- a/doc/downloads.html +++ b/doc/downloads.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/extensions.html b/doc/extensions.html index 478ecdd3..b6b15202 100644 --- a/doc/extensions.html +++ b/doc/extensions.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/help.html b/doc/help.html index ad13d921..232421db 100644 --- a/doc/help.html +++ b/doc/help.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/index.html b/doc/index.html index 840ecdbe..d83521c9 100644 --- a/doc/index.html +++ b/doc/index.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/internals.html b/doc/internals.html index 4a3b8e01..88b1c473 100644 --- a/doc/internals.html +++ b/doc/internals.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/intro.html b/doc/intro.html index 2e14305b..7939d043 100644 --- a/doc/intro.html +++ b/doc/intro.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/libxslt-api.xml b/doc/libxslt-api.xml index 1e92e45c..034b4c89 100644 --- a/doc/libxslt-api.xml +++ b/doc/libxslt-api.xml @@ -58,16 +58,17 @@ + - + @@ -99,6 +100,7 @@ + @@ -412,6 +414,8 @@ + + This is Michael Kay's Saxon processor namespace for extensions @@ -811,6 +815,11 @@ + + + + + Looks up an extension module function @@ -1080,7 +1089,7 @@ This function tries to locate the stylesheet PI in the given document If found, and if contained within the document, it will extract that subtree to build the stylesheet to process doc (doc itself will be modified). If found but referencing an external document it will attempt to load it and generate a stylesheet from it. In both cases, the resulting stylesheet and the document need to be freed once the transformation is done. - + Determine if a node matches a pattern. @@ -1580,6 +1589,10 @@ + + + + This is the entry point when a varibale is needed by the XPath interpretor. diff --git a/doc/libxslt-decl.txt b/doc/libxslt-decl.txt index c63d1638..bb1ebdb3 100644 --- a/doc/libxslt-decl.txt +++ b/doc/libxslt-decl.txt @@ -29,15 +29,15 @@ void LIBXSLT_DOTTED_VERSION -#define LIBXSLT_DOTTED_VERSION "1.0.11" +#define LIBXSLT_DOTTED_VERSION "1.0.12" LIBXSLT_VERSION -#define LIBXSLT_VERSION 10011 +#define LIBXSLT_VERSION 10012 LIBXSLT_VERSION_STRING -#define LIBXSLT_VERSION_STRING "10011" +#define LIBXSLT_VERSION_STRING "10012" WITH_XSLT_DEBUG @@ -590,15 +590,15 @@ void *ctxt,const xmlChar *name,const xmlChar *ns_uri LIBXSLT_DOTTED_VERSION -#define LIBXSLT_DOTTED_VERSION "1.0.11" +#define LIBXSLT_DOTTED_VERSION "1.0.12" LIBXSLT_VERSION -#define LIBXSLT_VERSION 10011 +#define LIBXSLT_VERSION 10012 LIBXSLT_VERSION_STRING -#define LIBXSLT_VERSION_STRING "10011" +#define LIBXSLT_VERSION_STRING "10012" WITH_XSLT_DEBUG @@ -743,6 +743,11 @@ xsltTransformContextPtr ctxt xsltStylesheetPtr style +xsltXPathGetTransformContext +xsltTransformContextPtr +xmlXPathParserContextPtr ctxt + + xsltRegisterExtModuleFunction int const xmlChar *name,const xmlChar *URI,xmlXPathFunction function @@ -763,13 +768,8 @@ const xmlChar *name,const xmlChar *URI const xmlChar *name,const xmlChar *URI -xsltElemPreCompPtr -typedef -*xsltPreComputeFunction) (xsltStylesheetPtr style,xmlNodePtr inst,xsltTransformFunction function - - xsltNewElemPreComp -xsltElemPreCompPtr +xsltElemPreCompPtr xsltStylesheetPtr style,xmlNodePtr inst,xsltTransformFunction function @@ -784,12 +784,17 @@ const xmlChar *name,const xmlChar *URI,xsltPreComputeFunction precomp,xsltTransf xsltExtElementLookup -xsltTransformFunction +xsltTransformFunction xsltTransformContextPtr ctxt,const xmlChar *name,const xmlChar *URI xsltExtModuleElementLookup -xsltTransformFunction +xsltTransformFunction +const xmlChar *name,const xmlChar *URI + + +xsltExtModuleElementPreComputeLookup +xsltPreComputeFunction const xmlChar *name,const xmlChar *URI @@ -855,7 +860,7 @@ xsltStylesheetPtr style xsltPreComputeExtModuleElement -xsltElemPreCompPtr +xsltElemPreCompPtr xsltStylesheetPtr style,xmlNodePtr inst @@ -1041,7 +1046,7 @@ extern const xmlChar *xsltExtMarker; xsltDocumentComp -xsltElemPreCompPtr +xsltElemPreCompPtr xsltStylesheetPtr style,xmlNodePtr inst,xsltTransformFunction function @@ -1092,6 +1097,10 @@ struct xsltRuntimeExtra { XSLT_RUNTIME_EXTRA #define XSLT_RUNTIME_EXTRA(ctxt, nr) (ctxt)->extras[(nr)].info + +XSLT_RUNTIME_EXTRA_FREE +#define XSLT_RUNTIME_EXTRA_FREE(ctxt, nr) (ctxt)->extras[(nr)].deallocate + xsltTemplate diff --git a/doc/libxslt-refs.xml b/doc/libxslt-refs.xml index cd99b49f..762fb635 100644 --- a/doc/libxslt-refs.xml +++ b/doc/libxslt-refs.xml @@ -489,9 +489,6 @@ - - - @@ -557,6 +554,9 @@ + + + @@ -577,6 +577,7 @@ + @@ -585,9 +586,6 @@ - - - @@ -655,6 +653,8 @@ + + @@ -802,7 +802,6 @@ - @@ -872,6 +871,7 @@ + @@ -1085,7 +1085,6 @@ - @@ -1120,16 +1119,17 @@ + - + @@ -1292,6 +1292,7 @@ + diff --git a/doc/news.html b/doc/news.html index be5569dc..c73ae213 100644 --- a/doc/news.html +++ b/doc/news.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/doc/python.html b/doc/python.html new file mode 100644 index 00000000..3e4222c1 --- /dev/null +++ b/doc/python.html @@ -0,0 +1,267 @@ + + + + + +Python and bindings + + + + + +
    +Gnome LogoRed Hat Logo +
    +

    The XSLT C library for Gnome

    +

    Python and bindings

    +
    +
    + + +
    + + + +
    Main Menu
    + + + +
    API Indexes
    + + + +
    Related links
    +
    +

    There is a number of language bindings and wrappers available for libxml2, +the list below is not exhaustive. Please contact the xml-bindings@gnome.org +(archives) in +order to get updates to this list or to discuss the specific topic of libxml2 +or libxslt wrappers or bindings:

    + +

    The libxslt Python module depends on the libxml2 Python module. +

    +

    The distribution includes a set of Python bindings, which are garanteed to +be maintained as part of the library in the future, though the Python +interface have not yet reached the maturity of the C API. The distribution +includes a set of examples and regression tests for the python bindings in +the python/tests directory. Here are some excepts from those +tests:

    +

    basic.py:

    +

    This is a basic test of XSLT interfaces: loading a stylesheet and +a document, transforming the document and saving the result.

    +
    import libxml2
    +import libxslt
    +
    +styledoc = libxml2.parseFile("test.xsl")
    +style = libxslt.parseStylesheetDoc(styledoc)
    +doc = libxml2.parseFile("test.xml")
    +result = style.applyStylesheet(doc, None)
    +style.saveResultToFilename("foo", result, 0)
    +style.freeStylesheet()
    +doc.freeDoc()
    +result.freeDoc()
    +

    The Python module is called libxslt, you will also need the libxml2 module +for the operations on XML trees. Let's have a look at the objects manipulated +in that example and how is the processing done:

    +
      +
    • +styledoc: is a libxml2 document tree. It is obtained by + parsing the XML file "test.xsl" containing the stylesheet.
    • +
    • +style: this is a precompiled stylesheet ready to be used + by the following transformations (note the plural form, multiple + transformations can resuse the same stylesheet).
    • +
    • +doc: this is the document to apply the transformation to. + In this case it is simply generated by parsing it from a file but any + other processing is possible as long as one get a libxml2 Doc. Note + that HTML tree are suitable for XSLT processing in libxslt. This is + actually how this page is generated !
    • +
    • +result: this is a document generated by applying the + stylesheet to the document. Note that some of the stylesheet informations + may be related to the serialization of that document and as in this + example a specific saveResultToFilename() method of the stylesheet + should be used to save it to a file (in that case to "foo").
    • +
    +

    Also note the need to explicitely deallocate documents with freeDoc() +except for the stylesheet document which is freed when its compiled form +is garbage collected.

    +

    extfunc.py:

    +

    This one is a far more complex test. It shows how to modify the behaviour +of an XSLT transformation by passing parameters and how to extend the XSLT +engine with functions defined in python:

    +
    import libxml2
    +import libxslt
    +import string
    +
    +nodeName = None
    +def f(ctx, str):
    +    global nodeName
    +
    +    #
    +    # Small check to verify the context is correcly accessed
    +    #
    +    try:
    +        pctxt = libxslt.xpathParserContext(_obj=ctx)
    +        ctxt = pctxt.context()
    +        tctxt = ctxt.transformContext()
    +        nodeName = tctxt.insertNode().name
    +    except:
    +        pass
    +
    +    return string.upper(str)
    +
    +libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)
    +

    This code defines and register an extension function. Note that the +function can be bound to any name (foo) and how the binding is also +associated to a namespace name "http://example.com/foo". From an +XSLT point of view the function just returns an upper case version of the +string passed as a parameter. But the first part of the function also +read some contextual information from the current XSLT processing environement, +in that case it looks for the current insertion node in the resulting output +(either the resulting document or the Result Value Tree being generated), and +saves it to a global variable for checking that the access actually worked. +

    +

    For more informations on the xpathParserContext and transformContext +objects check the libray internals description. +The pctxt is actually an object from a class derived from the +libxml2.xpathParserContext() with just a couple more properties including +the possibility to look up the XSLT transformation context from the XPath +context. +

    +
    +styledoc = libxml2.parseDoc("""
    +<xsl:stylesheet version='1.0'
    +  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    +  xmlns:foo='http://example.com/foo'
    +  xsl:exclude-result-prefixes='foo'>
    +
    +  <xsl:param name='bar'>failure</xsl:param>
    +  <xsl:template match='/'>
    +    <article><xsl:value-of select='foo:foo($bar)'/></article>
    +  </xsl:template>
    +</xsl:stylesheet>
    +""")
    +

    Here is a simple example of how to read an XML document from a python +string with libxml2. Note how this stylesheet: +

    +
      +
    • Uses a global parameter bar +
    • +
    • Reference the extension function f +
    • +
    • how the Namespace name "http://example.com/foo" has to be bound to + a prefix +
    • +
    • how that prefix is excluded from the output +
    • +
    • how the function is called from the select +
    • +
    +
    style = libxslt.parseStylesheetDoc(styledoc)
    +doc = libxml2.parseDoc("<doc/>")
    +result = style.applyStylesheet(doc, { "bar": "'success'" })
    +style.freeStylesheet()
    +doc.freeDoc()
    +

    that part is identical, to the basic example except that the +transformation is passed a dictionnary of parameters. Note that the +string passed "success" had to be quoted, otherwise it is interpreted +as an XPath query for the childs of root named "success". +

    +
    +root = result.children
    +if root.name != "article":
    +    print "Unexpected root node name"
    +    sys.exit(1)
    +if root.content != "SUCCESS":
    +    print "Unexpected root node content, extension function failed"
    +    sys.exit(1)
    +if nodeName != 'article':
    +    print "The function callback failed to access its context"
    +    sys.exit(1)
    +
    +result.freeDoc()
    +
    +

    That part just verifies that the transformation worked, that the parameter +got properly passed to the engine, that the function f() got called and that +it properly accessed the context to find the name of the insertion node. + +

    +

    pyxsltproc.py:

    +

    this module is a bit too long to be described there but it is basically +a rewrite of the xsltproc command line interface of libxslt in Python. It +provides nearly all the functionalities of xsltproc and can be used as a base +module to write Python customized XSLT processors. One of the thing +to notice are: +

    +
    libxml2.lineNumbersDefault(1)
    +libxml2.substituteEntitiesDefault(1)
    +
    +

    those two calls in the main() function are needed to force the libxml2 +processor to generate DOM trees compliant with the XPath data model. + +

    +

    Daniel Veillard

    +
    + + diff --git a/doc/site.xsl b/doc/site.xsl index 3baeaeeb..6a826775 100644 --- a/doc/site.xsl +++ b/doc/site.xsl @@ -49,6 +49,9 @@ FAQ.html + + python.html + unknown.html diff --git a/doc/xslt.html b/doc/xslt.html index 00193523..6e39f99b 100644 --- a/doc/xslt.html +++ b/doc/xslt.html @@ -651,6 +651,187 @@ processing needs and environment for example if reading/saving from/to memory, or if you want to apply XInclude processing to the stylesheet or input documents.

    +

    Python and bindings

    + +

    There is a number of language bindings and wrappers available for libxml2, +the list below is not exhaustive. Please contact the xml-bindings@gnome.org +(archives) in +order to get updates to this list or to discuss the specific topic of libxml2 +or libxslt wrappers or bindings:

    + + +

    The libxslt Python module depends on the libxml2 Python module. +

    The distribution includes a set of Python bindings, which are garanteed to +be maintained as part of the library in the future, though the Python +interface have not yet reached the maturity of the C API. The distribution +includes a set of examples and regression tests for the python bindings in +the python/tests directory. Here are some excepts from those +tests:

    + +

    basic.py:

    + +

    This is a basic test of XSLT interfaces: loading a stylesheet and +a document, transforming the document and saving the result.

    +
    import libxml2
    +import libxslt
    +
    +styledoc = libxml2.parseFile("test.xsl")
    +style = libxslt.parseStylesheetDoc(styledoc)
    +doc = libxml2.parseFile("test.xml")
    +result = style.applyStylesheet(doc, None)
    +style.saveResultToFilename("foo", result, 0)
    +style.freeStylesheet()
    +doc.freeDoc()
    +result.freeDoc()
    + +

    The Python module is called libxslt, you will also need the libxml2 module +for the operations on XML trees. Let's have a look at the objects manipulated +in that example and how is the processing done:

    +
      +
    • styledoc: is a libxml2 document tree. It is obtained by + parsing the XML file "test.xsl" containing the stylesheet.
    • +
    • style: this is a precompiled stylesheet ready to be used + by the following transformations (note the plural form, multiple + transformations can resuse the same stylesheet).
    • +
    • doc: this is the document to apply the transformation to. + In this case it is simply generated by parsing it from a file but any + other processing is possible as long as one get a libxml2 Doc. Note + that HTML tree are suitable for XSLT processing in libxslt. This is + actually how this page is generated !
    • +
    • result: this is a document generated by applying the + stylesheet to the document. Note that some of the stylesheet informations + may be related to the serialization of that document and as in this + example a specific saveResultToFilename() method of the stylesheet + should be used to save it to a file (in that case to "foo").
    • +
    + +

    Also note the need to explicitely deallocate documents with freeDoc() +except for the stylesheet document which is freed when its compiled form +is garbage collected.

    + +

    extfunc.py:

    +

    This one is a far more complex test. It shows how to modify the behaviour +of an XSLT transformation by passing parameters and how to extend the XSLT +engine with functions defined in python:

    +
    import libxml2
    +import libxslt
    +import string
    +
    +nodeName = None
    +def f(ctx, str):
    +    global nodeName
    +
    +    #
    +    # Small check to verify the context is correcly accessed
    +    #
    +    try:
    +        pctxt = libxslt.xpathParserContext(_obj=ctx)
    +        ctxt = pctxt.context()
    +        tctxt = ctxt.transformContext()
    +        nodeName = tctxt.insertNode().name
    +    except:
    +        pass
    +
    +    return string.upper(str)
    +
    +libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)
    +

    This code defines and register an extension function. Note that the +function can be bound to any name (foo) and how the binding is also +associated to a namespace name "http://example.com/foo". From an +XSLT point of view the function just returns an upper case version of the +string passed as a parameter. But the first part of the function also +read some contextual information from the current XSLT processing environement, +in that case it looks for the current insertion node in the resulting output +(either the resulting document or the Result Value Tree being generated), and +saves it to a global variable for checking that the access actually worked. +

    For more informations on the xpathParserContext and transformContext +objects check the libray internals description. +The pctxt is actually an object from a class derived from the +libxml2.xpathParserContext() with just a couple more properties including +the possibility to look up the XSLT transformation context from the XPath +context. +

    +styledoc = libxml2.parseDoc("""
    +<xsl:stylesheet version='1.0'
    +  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    +  xmlns:foo='http://example.com/foo'
    +  xsl:exclude-result-prefixes='foo'>
    +
    +  <xsl:param name='bar'>failure</xsl:param>
    +  <xsl:template match='/'>
    +    <article><xsl:value-of select='foo:foo($bar)'/></article>
    +  </xsl:template>
    +</xsl:stylesheet>
    +""")
    +

    Here is a simple example of how to read an XML document from a python +string with libxml2. Note how this stylesheet: +

      +
    • Uses a global parameter bar +
    • Reference the extension function f +
    • how the Namespace name "http://example.com/foo" has to be bound to + a prefix +
    • how that prefix is excluded from the output +
    • how the function is called from the select +
    + +
    style = libxslt.parseStylesheetDoc(styledoc)
    +doc = libxml2.parseDoc("<doc/>")
    +result = style.applyStylesheet(doc, { "bar": "'success'" })
    +style.freeStylesheet()
    +doc.freeDoc()
    +

    that part is identical, to the basic example except that the +transformation is passed a dictionnary of parameters. Note that the +string passed "success" had to be quoted, otherwise it is interpreted +as an XPath query for the childs of root named "success". +

    +root = result.children
    +if root.name != "article":
    +    print "Unexpected root node name"
    +    sys.exit(1)
    +if root.content != "SUCCESS":
    +    print "Unexpected root node content, extension function failed"
    +    sys.exit(1)
    +if nodeName != 'article':
    +    print "The function callback failed to access its context"
    +    sys.exit(1)
    +
    +result.freeDoc()
    +
    +

    That part just verifies that the transformation worked, that the parameter +got properly passed to the engine, that the function f() got called and that +it properly accessed the context to find the name of the insertion node. + +

    pyxsltproc.py:

    +

    this module is a bit too long to be described there but it is basically +a rewrite of the xsltproc command line interface of libxslt in Python. It +provides nearly all the functionalities of xsltproc and can be used as a base +module to write Python customized XSLT processors. One of the thing +to notice are: +

    libxml2.lineNumbersDefault(1)
    +libxml2.substituteEntitiesDefault(1)
    +
    +

    those two calls in the main() function are needed to force the libxml2 +processor to generate DOM trees compliant with the XPath data model. +

    Library internals

    Table of contents

    diff --git a/doc/xsltproc2.html b/doc/xsltproc2.html index 4124a2f8..d2d0b333 100644 --- a/doc/xsltproc2.html +++ b/doc/xsltproc2.html @@ -38,6 +38,7 @@ A:link, A:visited, A:active { text-decoration: underline }
  • The xsltproc tool
  • DocBook
  • The programming API
  • +
  • Python and bindings
  • Library internals
  • Writing extensions
  • Contributions
  • diff --git a/libxslt/extensions.h b/libxslt/extensions.h index bdffcd62..71bd719b 100644 --- a/libxslt/extensions.h +++ b/libxslt/extensions.h @@ -90,8 +90,7 @@ void xsltShutdownCtxtExts (xsltTransformContextPtr ctxt); void xsltShutdownExts (xsltStylesheetPtr style); -xsltTransformContextPtr - xsltXPathGetTransformContext +xsltTransformContextPtr xsltXPathGetTransformContext (xmlXPathParserContextPtr ctxt); /* @@ -113,13 +112,12 @@ int xsltUnregisterExtModuleFunction (const xmlChar *name, /* * extension elements */ -typedef xsltElemPreCompPtr - (*xsltPreComputeFunction) (xsltStylesheetPtr style, +typedef xsltElemPreCompPtr (*xsltPreComputeFunction) + (xsltStylesheetPtr style, xmlNodePtr inst, xsltTransformFunction function); -xsltElemPreCompPtr - xsltNewElemPreComp (xsltStylesheetPtr style, +xsltElemPreCompPtr xsltNewElemPreComp (xsltStylesheetPtr style, xmlNodePtr inst, xsltTransformFunction function); void xsltInitElemPreComp (xsltElemPreCompPtr comp, @@ -132,16 +130,12 @@ int xsltRegisterExtModuleElement (const xmlChar *name, const xmlChar *URI, xsltPreComputeFunction precomp, xsltTransformFunction transform); -xsltTransformFunction - xsltExtElementLookup (xsltTransformContextPtr ctxt, +xsltTransformFunction xsltExtElementLookup(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *URI); -xsltTransformFunction - xsltExtModuleElementLookup (const xmlChar *name, +xsltTransformFunction xsltExtModuleElementLookup(const xmlChar *name, const xmlChar *URI); -xsltPreComputeFunction - xsltExtModuleElementPreComputeLookup - (const xmlChar *name, +xsltPreComputeFunction xsltExtModuleElementPreComputeLookup (const xmlChar *name, const xmlChar *URI); int xsltUnregisterExtModuleElement (const xmlChar *name, const xmlChar *URI); @@ -171,7 +165,7 @@ int xsltRegisterExtElement (xsltTransformContextPtr ctxt, const xmlChar *URI, xsltTransformFunction function); -/** +/* * Extension Prefix handling API * Those are used by the XSLT (pre)processor. */ @@ -185,8 +179,7 @@ int xsltInitCtxtExts (xsltTransformContextPtr ctxt); void xsltFreeCtxtExts (xsltTransformContextPtr ctxt); void xsltFreeExts (xsltStylesheetPtr style); -xsltElemPreCompPtr - xsltPreComputeExtModuleElement (xsltStylesheetPtr style, +xsltElemPreCompPtr xsltPreComputeExtModuleElement(xsltStylesheetPtr style, xmlNodePtr inst); /** diff --git a/libxslt/preproc.h b/libxslt/preproc.h index 1349132d..507e4f14 100644 --- a/libxslt/preproc.h +++ b/libxslt/preproc.h @@ -21,8 +21,7 @@ extern "C" { */ extern const xmlChar *xsltExtMarker; -xsltElemPreCompPtr - xsltDocumentComp (xsltStylesheetPtr style, +xsltElemPreCompPtr xsltDocumentComp (xsltStylesheetPtr style, xmlNodePtr inst, xsltTransformFunction function); diff --git a/libxslt/xslt.c b/libxslt/xslt.c index 059b46ae..3b87ae59 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -2021,7 +2021,7 @@ xsltParseStylesheetFile(const xmlChar* filename) { /** * xsltParseStylesheetPI: - * value: the value of the PI + * @value: the value of the PI * * This function checks that the type is text/xml and extracts * the URI-Reference for the stylesheet @@ -2107,7 +2107,7 @@ xsltParseStylesheetPI(const xmlChar *value) { /** * xsltLoadStylesheetPI: - * doc: a document to process + * @doc: a document to process * * This function tries to locate the stylesheet PI in the given document * If found, and if contained within the document, it will extract diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index 878b4f3f..7458578b 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -201,7 +201,9 @@ struct _xsltElemPreComp { * precomputed data. */ typedef struct _xsltStylePreComp xsltStylePreComp; + typedef xsltStylePreComp *xsltStylePreCompPtr; + struct _xsltStylePreComp { xsltElemPreCompPtr next; /* chained list */ xsltStyleType type; /* type of the element */