mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-08-07 10:42:55 +03:00
Added a link to ScrollKeeper, Daniel
This commit is contained in:
@@ -104,8 +104,7 @@ A:link, A:visited, A:active { text-decoration: underline }
|
|||||||
provides libxml/libxslt <a href="http://www.rexx.com/~dkuhlman">wrappers
|
provides libxml/libxslt <a href="http://www.rexx.com/~dkuhlman">wrappers
|
||||||
for Python</a>
|
for Python</a>
|
||||||
</li>
|
</li>
|
||||||
<li>Steve Ball and contributors maintains
|
<li>Steve Ball and contributors maintains <a href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
||||||
<a href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
|
||||||
Tcl</a>
|
Tcl</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -111,6 +111,9 @@ few pointers and informations which may be helpful:</p>
|
|||||||
<li>Linux Documentation Project <a href="http://www.linuxdoc.org/HOWTO/mini/DocBook-Install/">
|
<li>Linux Documentation Project <a href="http://www.linuxdoc.org/HOWTO/mini/DocBook-Install/">
|
||||||
DocBook-Install-mini-HOWTO</a>
|
DocBook-Install-mini-HOWTO</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>ScrollKeeper the open documentation cataloging project has a <a href="http://scrollkeeper.sourceforge.net/docbook.shtml">DocBook
|
||||||
|
section</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Do not use the --docbook option of xsltproc to process XML DocBook
|
<p>Do not use the --docbook option of xsltproc to process XML DocBook
|
||||||
documents, this option is only intended to provide some (limited) support of
|
documents, this option is only intended to provide some (limited) support of
|
||||||
|
137
doc/python.html
137
doc/python.html
@@ -95,13 +95,11 @@ or libxslt wrappers or bindings:</p>
|
|||||||
<li>Wai-Sun "Squidster" Chia provides <a href="http://www.rubycolor.org/arc/redist/">bindings for Ruby</a> and
|
<li>Wai-Sun "Squidster" Chia provides <a href="http://www.rubycolor.org/arc/redist/">bindings for Ruby</a> and
|
||||||
libxml2 bindings are also available in Ruby through the <a href="http://libgdome-ruby.berlios.de/">libgdome-ruby</a> module
|
libxml2 bindings are also available in Ruby through the <a href="http://libgdome-ruby.berlios.de/">libgdome-ruby</a> module
|
||||||
maintained by Tobias Peters.</li>
|
maintained by Tobias Peters.</li>
|
||||||
<li>Steve Ball and contributors maintains
|
<li>Steve Ball and contributors maintains <a href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
||||||
<a href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
|
||||||
Tcl</a>
|
Tcl</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>The libxslt Python module depends on the <a href="http://xmlsoft.org/python.html">libxml2 Python</a> module.
|
<p>The libxslt Python module depends on the <a href="http://xmlsoft.org/python.html">libxml2 Python</a> module.</p>
|
||||||
</p>
|
|
||||||
<p>The distribution includes a set of Python bindings, which are garanteed to
|
<p>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
|
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
|
interface have not yet reached the maturity of the C API. The distribution
|
||||||
@@ -109,8 +107,8 @@ includes a set of examples and regression tests for the python bindings in
|
|||||||
the <code>python/tests</code> directory. Here are some excepts from those
|
the <code>python/tests</code> directory. Here are some excepts from those
|
||||||
tests:</p>
|
tests:</p>
|
||||||
<h3>basic.py:</h3>
|
<h3>basic.py:</h3>
|
||||||
<p>This is a basic test of XSLT interfaces: loading a stylesheet and
|
<p>This is a basic test of XSLT interfaces: loading a stylesheet and a
|
||||||
a document, transforming the document and saving the result.</p>
|
document, transforming the document and saving the result.</p>
|
||||||
<pre>import libxml2
|
<pre>import libxml2
|
||||||
import libxslt
|
import libxslt
|
||||||
|
|
||||||
@@ -127,28 +125,32 @@ for the operations on XML trees. Let's have a look at the objects manipulated
|
|||||||
in that example and how is the processing done:</p>
|
in that example and how is the processing done:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<code>styledoc</code>: is a libxml2 document tree. It is obtained by
|
<code>styledoc</code>
|
||||||
parsing the XML file "test.xsl" containing the stylesheet.</li>
|
: is a libxml2 document tree. It is obtained by parsing the XML file
|
||||||
|
"test.xsl" containing the stylesheet.</li>
|
||||||
<li>
|
<li>
|
||||||
<code>style</code>: this is a precompiled stylesheet ready to be used
|
<code>style</code>
|
||||||
by the following transformations (note the plural form, multiple
|
: this is a precompiled stylesheet ready to be used by the following
|
||||||
transformations can resuse the same stylesheet).</li>
|
transformations (note the plural form, multiple transformations can
|
||||||
|
resuse the same stylesheet).</li>
|
||||||
<li>
|
<li>
|
||||||
<code>doc</code>: this is the document to apply the transformation to.
|
<code>doc</code>
|
||||||
In this case it is simply generated by parsing it from a file but any
|
: this is the document to apply the transformation to. In this case it is
|
||||||
other processing is possible as long as one get a libxml2 Doc. Note
|
simply generated by parsing it from a file but any other processing is
|
||||||
that HTML tree are suitable for XSLT processing in libxslt. This is
|
possible as long as one get a libxml2 Doc. Note that HTML tree are
|
||||||
actually how this page is generated !</li>
|
suitable for XSLT processing in libxslt. This is actually how this page
|
||||||
|
is generated !</li>
|
||||||
<li>
|
<li>
|
||||||
<code>result</code>: this is a document generated by applying the
|
<code>result</code>
|
||||||
stylesheet to the document. Note that some of the stylesheet informations
|
: this is a document generated by applying the stylesheet to the
|
||||||
may be related to the serialization of that document and as in this
|
document. Note that some of the stylesheet informations may be related to
|
||||||
example a specific saveResultToFilename() method of the stylesheet
|
the serialization of that document and as in this example a specific
|
||||||
should be used to save it to a file (in that case to "foo").</li>
|
saveResultToFilename() method of the stylesheet should be used to save it
|
||||||
|
to a file (in that case to "foo").</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Also note the need to explicitely deallocate documents with freeDoc()
|
<p>Also note the need to explicitely deallocate documents with freeDoc()
|
||||||
except for the stylesheet document which is freed when its compiled form
|
except for the stylesheet document which is freed when its compiled form is
|
||||||
is garbage collected.</p>
|
garbage collected.</p>
|
||||||
<h3>extfunc.py:</h3>
|
<h3>extfunc.py:</h3>
|
||||||
<p>This one is a far more complex test. It shows how to modify the behaviour
|
<p>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
|
of an XSLT transformation by passing parameters and how to extend the XSLT
|
||||||
@@ -175,25 +177,22 @@ def f(ctx, str):
|
|||||||
return string.upper(str)
|
return string.upper(str)
|
||||||
|
|
||||||
libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)</pre>
|
libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)</pre>
|
||||||
<p> This code defines and register an extension function. Note that the
|
<p>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
|
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
|
associated to a namespace name "http://example.com/foo". From an XSLT point
|
||||||
XSLT point of view the function just returns an upper case version of the
|
of view the function just returns an upper case version of the string passed
|
||||||
string passed as a parameter. But the first part of the function also
|
as a parameter. But the first part of the function also read some contextual
|
||||||
read some contextual information from the current XSLT processing environement,
|
information from the current XSLT processing environement, in that case it
|
||||||
in that case it looks for the current insertion node in the resulting output
|
looks for the current insertion node in the resulting output (either the
|
||||||
(either the resulting document or the Result Value Tree being generated), and
|
resulting document or the Result Value Tree being generated), and saves it to
|
||||||
saves it to a global variable for checking that the access actually worked.
|
a global variable for checking that the access actually worked.</p>
|
||||||
</p>
|
<p>For more informations on the xpathParserContext and transformContext
|
||||||
<p> For more informations on the xpathParserContext and transformContext
|
|
||||||
objects check the <a href="internals.html">libray internals description</a>.
|
objects check the <a href="internals.html">libray internals description</a>.
|
||||||
The pctxt is actually an object from a class derived from the
|
The pctxt is actually an object from a class derived from the
|
||||||
libxml2.xpathParserContext() with just a couple more properties including
|
libxml2.xpathParserContext() with just a couple more properties including the
|
||||||
the possibility to look up the XSLT transformation context from the XPath
|
possibility to look up the XSLT transformation context from the XPath
|
||||||
context.
|
context.</p>
|
||||||
</p>
|
<pre>styledoc = libxml2.parseDoc("""
|
||||||
<pre>
|
|
||||||
styledoc = libxml2.parseDoc("""
|
|
||||||
<xsl:stylesheet version='1.0'
|
<xsl:stylesheet version='1.0'
|
||||||
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
||||||
xmlns:foo='http://example.com/foo'
|
xmlns:foo='http://example.com/foo'
|
||||||
@@ -205,34 +204,27 @@ styledoc = libxml2.parseDoc("""
|
|||||||
</xsl:template>
|
</xsl:template>
|
||||||
</xsl:stylesheet>
|
</xsl:stylesheet>
|
||||||
""")</pre>
|
""")</pre>
|
||||||
<p> Here is a simple example of how to read an XML document from a python
|
<p>Here is a simple example of how to read an XML document from a python
|
||||||
string with libxml2. Note how this stylesheet:
|
string with libxml2. Note how this stylesheet:</p>
|
||||||
</p>
|
|
||||||
<ul>
|
<ul>
|
||||||
<li> Uses a global parameter <code>bar</code>
|
<li>Uses a global parameter <code>bar</code>
|
||||||
</li>
|
|
||||||
<li> Reference the extension function f
|
|
||||||
</li>
|
|
||||||
<li> how the Namespace name "http://example.com/foo" has to be bound to
|
|
||||||
a prefix
|
|
||||||
</li>
|
|
||||||
<li> how that prefix is excluded from the output
|
|
||||||
</li>
|
|
||||||
<li> how the function is called from the select
|
|
||||||
</li>
|
</li>
|
||||||
|
<li>Reference the extension function f</li>
|
||||||
|
<li>how the Namespace name "http://example.com/foo" has to be bound to a
|
||||||
|
prefix</li>
|
||||||
|
<li>how that prefix is excluded from the output</li>
|
||||||
|
<li>how the function is called from the select</li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre>style = libxslt.parseStylesheetDoc(styledoc)
|
<pre>style = libxslt.parseStylesheetDoc(styledoc)
|
||||||
doc = libxml2.parseDoc("<doc/>")
|
doc = libxml2.parseDoc("<doc/>")
|
||||||
result = style.applyStylesheet(doc, { "bar": "'success'" })
|
result = style.applyStylesheet(doc, { "bar": "'success'" })
|
||||||
style.freeStylesheet()
|
style.freeStylesheet()
|
||||||
doc.freeDoc()</pre>
|
doc.freeDoc()</pre>
|
||||||
<p> that part is identical, to the basic example except that the
|
<p>that part is identical, to the basic example except that the
|
||||||
transformation is passed a dictionnary of parameters. Note that the
|
transformation is passed a dictionnary of parameters. Note that the string
|
||||||
string passed "success" had to be quoted, otherwise it is interpreted
|
passed "success" had to be quoted, otherwise it is interpreted as an XPath
|
||||||
as an XPath query for the childs of root named "success".
|
query for the childs of root named "success".</p>
|
||||||
</p>
|
<pre>root = result.children
|
||||||
<pre>
|
|
||||||
root = result.children
|
|
||||||
if root.name != "article":
|
if root.name != "article":
|
||||||
print "Unexpected root node name"
|
print "Unexpected root node name"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -243,27 +235,20 @@ if nodeName != 'article':
|
|||||||
print "The function callback failed to access its context"
|
print "The function callback failed to access its context"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
result.freeDoc()
|
result.freeDoc()</pre>
|
||||||
</pre>
|
<p>That part just verifies that the transformation worked, that the parameter
|
||||||
<p> 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
|
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.
|
it properly accessed the context to find the name of the insertion node.</p>
|
||||||
|
|
||||||
</p>
|
|
||||||
<h3>pyxsltproc.py:</h3>
|
<h3>pyxsltproc.py:</h3>
|
||||||
<p> this module is a bit too long to be described there but it is basically
|
<p>this module is a bit too long to be described there but it is basically a
|
||||||
a rewrite of the xsltproc command line interface of libxslt in Python. It
|
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
|
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
|
module to write Python customized XSLT processors. One of the thing to notice
|
||||||
to notice are:
|
are:</p>
|
||||||
</p>
|
|
||||||
<pre>libxml2.lineNumbersDefault(1)
|
<pre>libxml2.lineNumbersDefault(1)
|
||||||
libxml2.substituteEntitiesDefault(1)
|
libxml2.substituteEntitiesDefault(1)</pre>
|
||||||
</pre>
|
<p>those two calls in the main() function are needed to force the libxml2
|
||||||
<p> those two calls in the main() function are needed to force the libxml2
|
processor to generate DOM trees compliant with the XPath data model.</p>
|
||||||
processor to generate DOM trees compliant with the XPath data model.
|
|
||||||
|
|
||||||
</p>
|
|
||||||
<p><a href="mailto:daniel@veillard.com">Daniel Veillard</a></p>
|
<p><a href="mailto:daniel@veillard.com">Daniel Veillard</a></p>
|
||||||
</td></tr></table></td></tr></table></td></tr></table></td>
|
</td></tr></table></td></tr></table></td></tr></table></td>
|
||||||
</tr></table></td></tr></table>
|
</tr></table></td></tr></table>
|
||||||
|
148
doc/xslt.html
148
doc/xslt.html
@@ -602,6 +602,9 @@ few pointers and informations which may be helpful:</p>
|
|||||||
<li>Linux Documentation Project <a
|
<li>Linux Documentation Project <a
|
||||||
href="http://www.linuxdoc.org/HOWTO/mini/DocBook-Install/">
|
href="http://www.linuxdoc.org/HOWTO/mini/DocBook-Install/">
|
||||||
DocBook-Install-mini-HOWTO</a></li>
|
DocBook-Install-mini-HOWTO</a></li>
|
||||||
|
<li>ScrollKeeper the open documentation cataloging project has a <a
|
||||||
|
href="http://scrollkeeper.sourceforge.net/docbook.shtml">DocBook
|
||||||
|
section</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>Do not use the --docbook option of xsltproc to process XML DocBook
|
<p>Do not use the --docbook option of xsltproc to process XML DocBook
|
||||||
@@ -677,12 +680,14 @@ or libxslt wrappers or bindings:</p>
|
|||||||
libxml2 bindings are also available in Ruby through the <a
|
libxml2 bindings are also available in Ruby through the <a
|
||||||
href="http://libgdome-ruby.berlios.de/">libgdome-ruby</a> module
|
href="http://libgdome-ruby.berlios.de/">libgdome-ruby</a> module
|
||||||
maintained by Tobias Peters.</li>
|
maintained by Tobias Peters.</li>
|
||||||
<li>Steve Ball and contributors maintains
|
<li>Steve Ball and contributors maintains <a
|
||||||
<a href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
||||||
Tcl</a>
|
Tcl</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>The libxslt Python module depends on the <a href="http://xmlsoft.org/python.html">libxml2 Python</a> module.
|
<p>The libxslt Python module depends on the <a
|
||||||
|
href="http://xmlsoft.org/python.html">libxml2 Python</a> module.</p>
|
||||||
|
|
||||||
<p>The distribution includes a set of Python bindings, which are garanteed to
|
<p>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
|
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
|
interface have not yet reached the maturity of the C API. The distribution
|
||||||
@@ -692,8 +697,8 @@ tests:</p>
|
|||||||
|
|
||||||
<h3>basic.py:</h3>
|
<h3>basic.py:</h3>
|
||||||
|
|
||||||
<p>This is a basic test of XSLT interfaces: loading a stylesheet and
|
<p>This is a basic test of XSLT interfaces: loading a stylesheet and a
|
||||||
a document, transforming the document and saving the result.</p>
|
document, transforming the document and saving the result.</p>
|
||||||
<pre>import libxml2
|
<pre>import libxml2
|
||||||
import libxslt
|
import libxslt
|
||||||
|
|
||||||
@@ -710,28 +715,33 @@ result.freeDoc()</pre>
|
|||||||
for the operations on XML trees. Let's have a look at the objects manipulated
|
for the operations on XML trees. Let's have a look at the objects manipulated
|
||||||
in that example and how is the processing done:</p>
|
in that example and how is the processing done:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>styledoc</code>: is a libxml2 document tree. It is obtained by
|
<li><code>styledoc</code>
|
||||||
parsing the XML file "test.xsl" containing the stylesheet.</li>
|
: is a libxml2 document tree. It is obtained by parsing the XML file
|
||||||
<li><code>style</code>: this is a precompiled stylesheet ready to be used
|
"test.xsl" containing the stylesheet.</li>
|
||||||
by the following transformations (note the plural form, multiple
|
<li><code>style</code>
|
||||||
transformations can resuse the same stylesheet).</li>
|
: this is a precompiled stylesheet ready to be used by the following
|
||||||
<li><code>doc</code>: this is the document to apply the transformation to.
|
transformations (note the plural form, multiple transformations can
|
||||||
In this case it is simply generated by parsing it from a file but any
|
resuse the same stylesheet).</li>
|
||||||
other processing is possible as long as one get a libxml2 Doc. Note
|
<li><code>doc</code>
|
||||||
that HTML tree are suitable for XSLT processing in libxslt. This is
|
: this is the document to apply the transformation to. In this case it is
|
||||||
actually how this page is generated !</li>
|
simply generated by parsing it from a file but any other processing is
|
||||||
<li><code>result</code>: this is a document generated by applying the
|
possible as long as one get a libxml2 Doc. Note that HTML tree are
|
||||||
stylesheet to the document. Note that some of the stylesheet informations
|
suitable for XSLT processing in libxslt. This is actually how this page
|
||||||
may be related to the serialization of that document and as in this
|
is generated !</li>
|
||||||
example a specific saveResultToFilename() method of the stylesheet
|
<li><code>result</code>
|
||||||
should be used to save it to a file (in that case to "foo").</li>
|
: 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").</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>Also note the need to explicitely deallocate documents with freeDoc()
|
<p>Also note the need to explicitely deallocate documents with freeDoc()
|
||||||
except for the stylesheet document which is freed when its compiled form
|
except for the stylesheet document which is freed when its compiled form is
|
||||||
is garbage collected.</p>
|
garbage collected.</p>
|
||||||
|
|
||||||
<h3>extfunc.py:</h3>
|
<h3>extfunc.py:</h3>
|
||||||
|
|
||||||
<p>This one is a far more complex test. It shows how to modify the behaviour
|
<p>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
|
of an XSLT transformation by passing parameters and how to extend the XSLT
|
||||||
engine with functions defined in python:</p>
|
engine with functions defined in python:</p>
|
||||||
@@ -757,23 +767,24 @@ def f(ctx, str):
|
|||||||
return string.upper(str)
|
return string.upper(str)
|
||||||
|
|
||||||
libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)</pre>
|
libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)</pre>
|
||||||
<p> This code defines and register an extension function. Note that the
|
|
||||||
|
<p>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
|
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
|
associated to a namespace name "http://example.com/foo". From an XSLT point
|
||||||
XSLT point of view the function just returns an upper case version of the
|
of view the function just returns an upper case version of the string passed
|
||||||
string passed as a parameter. But the first part of the function also
|
as a parameter. But the first part of the function also read some contextual
|
||||||
read some contextual information from the current XSLT processing environement,
|
information from the current XSLT processing environement, in that case it
|
||||||
in that case it looks for the current insertion node in the resulting output
|
looks for the current insertion node in the resulting output (either the
|
||||||
(either the resulting document or the Result Value Tree being generated), and
|
resulting document or the Result Value Tree being generated), and saves it to
|
||||||
saves it to a global variable for checking that the access actually worked.
|
a global variable for checking that the access actually worked.</p>
|
||||||
<p> For more informations on the xpathParserContext and transformContext
|
|
||||||
|
<p>For more informations on the xpathParserContext and transformContext
|
||||||
objects check the <a href="internals.html">libray internals description</a>.
|
objects check the <a href="internals.html">libray internals description</a>.
|
||||||
The pctxt is actually an object from a class derived from the
|
The pctxt is actually an object from a class derived from the
|
||||||
libxml2.xpathParserContext() with just a couple more properties including
|
libxml2.xpathParserContext() with just a couple more properties including the
|
||||||
the possibility to look up the XSLT transformation context from the XPath
|
possibility to look up the XSLT transformation context from the XPath
|
||||||
context.
|
context.</p>
|
||||||
<pre>
|
<pre>styledoc = libxml2.parseDoc("""
|
||||||
styledoc = libxml2.parseDoc("""
|
|
||||||
<xsl:stylesheet version='1.0'
|
<xsl:stylesheet version='1.0'
|
||||||
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
||||||
xmlns:foo='http://example.com/foo'
|
xmlns:foo='http://example.com/foo'
|
||||||
@@ -785,28 +796,28 @@ styledoc = libxml2.parseDoc("""
|
|||||||
</xsl:template>
|
</xsl:template>
|
||||||
</xsl:stylesheet>
|
</xsl:stylesheet>
|
||||||
""")</pre>
|
""")</pre>
|
||||||
<p> Here is a simple example of how to read an XML document from a python
|
|
||||||
string with libxml2. Note how this stylesheet:
|
|
||||||
<ul>
|
|
||||||
<li> Uses a global parameter <code>bar</code>
|
|
||||||
<li> Reference the extension function f
|
|
||||||
<li> how the Namespace name "http://example.com/foo" has to be bound to
|
|
||||||
a prefix
|
|
||||||
<li> how that prefix is excluded from the output
|
|
||||||
<li> how the function is called from the select
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
|
<p>Here is a simple example of how to read an XML document from a python
|
||||||
|
string with libxml2. Note how this stylesheet:</p>
|
||||||
|
<ul>
|
||||||
|
<li>Uses a global parameter <code>bar</code></li>
|
||||||
|
<li>Reference the extension function f</li>
|
||||||
|
<li>how the Namespace name "http://example.com/foo" has to be bound to a
|
||||||
|
prefix</li>
|
||||||
|
<li>how that prefix is excluded from the output</li>
|
||||||
|
<li>how the function is called from the select</li>
|
||||||
|
</ul>
|
||||||
<pre>style = libxslt.parseStylesheetDoc(styledoc)
|
<pre>style = libxslt.parseStylesheetDoc(styledoc)
|
||||||
doc = libxml2.parseDoc("<doc/>")
|
doc = libxml2.parseDoc("<doc/>")
|
||||||
result = style.applyStylesheet(doc, { "bar": "'success'" })
|
result = style.applyStylesheet(doc, { "bar": "'success'" })
|
||||||
style.freeStylesheet()
|
style.freeStylesheet()
|
||||||
doc.freeDoc()</pre>
|
doc.freeDoc()</pre>
|
||||||
<p> that part is identical, to the basic example except that the
|
|
||||||
transformation is passed a dictionnary of parameters. Note that the
|
<p>that part is identical, to the basic example except that the
|
||||||
string passed "success" had to be quoted, otherwise it is interpreted
|
transformation is passed a dictionnary of parameters. Note that the string
|
||||||
as an XPath query for the childs of root named "success".
|
passed "success" had to be quoted, otherwise it is interpreted as an XPath
|
||||||
<pre>
|
query for the childs of root named "success".</p>
|
||||||
root = result.children
|
<pre>root = result.children
|
||||||
if root.name != "article":
|
if root.name != "article":
|
||||||
print "Unexpected root node name"
|
print "Unexpected root node name"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -817,23 +828,24 @@ if nodeName != 'article':
|
|||||||
print "The function callback failed to access its context"
|
print "The function callback failed to access its context"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
result.freeDoc()
|
result.freeDoc()</pre>
|
||||||
</pre>
|
|
||||||
<p> That part just verifies that the transformation worked, that the parameter
|
<p>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
|
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.
|
it properly accessed the context to find the name of the insertion node.</p>
|
||||||
|
|
||||||
<h3>pyxsltproc.py:</h3>
|
<h3>pyxsltproc.py:</h3>
|
||||||
<p> 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
|
<p>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
|
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
|
module to write Python customized XSLT processors. One of the thing to notice
|
||||||
to notice are:
|
are:</p>
|
||||||
<pre>libxml2.lineNumbersDefault(1)
|
<pre>libxml2.lineNumbersDefault(1)
|
||||||
libxml2.substituteEntitiesDefault(1)
|
libxml2.substituteEntitiesDefault(1)</pre>
|
||||||
</pre>
|
|
||||||
<p> those two calls in the main() function are needed to force the libxml2
|
<p>those two calls in the main() function are needed to force the libxml2
|
||||||
processor to generate DOM trees compliant with the XPath data model.
|
processor to generate DOM trees compliant with the XPath data model.</p>
|
||||||
|
|
||||||
<h2><a name="Internals">Library internals</a></h2>
|
<h2><a name="Internals">Library internals</a></h2>
|
||||||
|
|
||||||
@@ -1769,9 +1781,9 @@ close the connection to the database to keep the same example.</p>
|
|||||||
<li><a href="mailto:dkuhlman@cutter.rexx.com">Dave Kuhlman</a>
|
<li><a href="mailto:dkuhlman@cutter.rexx.com">Dave Kuhlman</a>
|
||||||
provides libxml/libxslt <a href="http://www.rexx.com/~dkuhlman">wrappers
|
provides libxml/libxslt <a href="http://www.rexx.com/~dkuhlman">wrappers
|
||||||
for Python</a></li>
|
for Python</a></li>
|
||||||
<li>Steve Ball and contributors maintains
|
<li>Steve Ball and contributors maintains <a
|
||||||
<a href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
href="http://tclxml.sourceforge.net/">libxml2 and libxslt bindings for
|
||||||
Tcl</a>
|
Tcl</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>I'm still waiting for someone to contribute a simple XSLT processing
|
<p>I'm still waiting for someone to contribute a simple XSLT processing
|
||||||
|
Reference in New Issue
Block a user