[libxslt.wiki] Update Python bindings
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxslt.wiki] Update Python bindings
- Date: Sat, 12 Feb 2022 17:29:39 +0000 (UTC)
commit 17f14b5e45f2fd30127f4ae85f04c86fe8cf3710
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Sat Feb 12 17:29:39 2022 +0000
Update Python bindings
Python-bindings.md | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/Python-bindings.md b/Python-bindings.md
index 4d5ed34..669ef5d 100644
--- a/Python-bindings.md
+++ b/Python-bindings.md
@@ -13,11 +13,11 @@ To install the Python bindings there are 2 options:
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](http://basic.py):
+### basic.py
This is a basic test of XSLT interfaces: loading a stylesheet and a document, transforming the document and
saving the result.
-```
+```plaintext
import libxml2
import libxslt
@@ -40,11 +40,11 @@ The Python module is called libxslt, you will also need the libxml2 module for t
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](http://extfunc.py):
+### 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:
-```
+```plaintext
import libxml2
import libxslt
import string
@@ -73,7 +73,7 @@ This code defines and register an extension function. Note that the function can
For more information on the xpathParserContext and transformContext objects check the [libray internals
description](http://xmlsoft.org/XSLT/internals.html). 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.
-```
+```plaintext
styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
@@ -96,7 +96,7 @@ Here is a simple example of how to read an XML document from a python string wit
* how that prefix is excluded from the output
* how the function is called from the select
-```
+```plaintext
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseDoc("<doc/>")
result = style.applyStylesheet(doc, { "bar": "'success'" })
@@ -106,7 +106,7 @@ doc.freeDoc()
that part is identical, to the basic example except that the transformation is passed a dictionary 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".
-```
+```plaintext
root = result.children
if root.name != "article":
print "Unexpected root node name"
@@ -123,11 +123,11 @@ 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](http://pyxsltproc.py):
+### 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:
-```
+```plaintext
libxml2.lineNumbersDefault(1)
libxml2.substituteEntitiesDefault(1)
```
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]