In the libxslt SRPM are 3 main things to test and the devel package.
- libxslt1
- libxslt-devel
- python-libxslt
- xsltproc
#urpmq -i lib64xslt1 Name : lib64xslt1 Version : 1.1.26 Release : 5.1.mga1 Group : System/Libraries Size : 380539 Architecture: x86_64 Source RPM : libxslt-1.1.26-5.1.mga1.src.rpm URL : http://xmlsoft.org/XSLT/ Summary : Library providing XSLT support Description : This C library allows to transform XML files into other XML files (or HTML, text, ...) using the standard XSLT stylesheet transformation mechanism. A xslt processor based on this library, named xsltproc, is provided by the libxslt-proc package. # urpmq -i python-libxslt Name : python-libxslt Version : 1.1.26 Release : 5.1.mga1 Group : Development/Python Size : 155358 Architecture: x86_64 Source RPM : libxslt-1.1.26-5.1.mga1.src.rpm URL : http://xmlsoft.org/XSLT/ Summary : Python bindings for the libxslt library Description : The libxslt-python package contains a module that permits applications written in the Python programming language to use the interface supplied by the libxslt library to apply XSLT transformations. This library allows to parse sytlesheets, uses the libxml2-python to load and save XML and HTML files. Direct access to XPath and the XSLT transformation context are possible to extend the XSLT language with XPath functions written in Python. # urpmq -i xsltproc Name : xsltproc Version : 1.1.26 Release : 5.1.mga1 Group : System/Libraries Size : 25956 Architecture: x86_64 Source RPM : libxslt-1.1.26-5.1.mga1.src.rpm URL : http://xmlsoft.org/XSLT/ Summary : XSLT processor using libxslt Description : This package provides an XSLT processor based on the libxslt C library. It allows to transform XML files into other XML files (or HTML, text, ...) using the standard XSLT stylesheet transformation mechanism.
Testing lib(64)xslt1 can be done with chromium-browser by browsing xhtml web pages such as the test pages here or here and also by testing with the other tools - xsltproc and python-libxslt.
xsltproc
The files referenced below are available for download from https://bugs.mageia.org/show_bug.cgi?id=20760
xsltproc can be tested by following the instructions here and creating cdcatalog.xml and cdcatalog.xsl as below:
<?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> </catalog>
There is an extended version you can download from here - right click & save link as.
The xsl stylesheet should be saved as cdcatalog.xsl as below. direct download here.
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
When you have the two files you can use the command below and see the html output it produces.
$ xsltproc cdcatalog.xsl cdcatalog.xml <html><body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr> <td>Empire Burlesque</td> <td>Bob Dylan</td> </tr> </table> </body></html>
python-libxslt
Using the same two files, cdcatalog.xml and cdcatalog.xsl, it is easy to test python-libxslt using a modified version of the script available here called libxml_xslt_transform_example.py. A direct link (right click, save link as) is here
Once you have the file, you just need to alter the variables in the middle of the script, they are currently windows paths.
#!/usr/bin/env python # this is libxml_xslt_transform_example.py """ Example XSLT transformation script that uses the Gnome libxml XML C parser and toolkit On Windows, Python can make use of the libxml2 and libxslt C libraries (http://www.xmlsoft.org/) through the following Python bindings http://users.skynet.be/sbi/libxml-python/. Other bindings can be found here http://codespeak.net/lxml/. The Windows installer includes the C libraries in form of DLLs. Most Linux distributions already include the C libraries. Usage: Python 2.6 Wolfgang Grunberg Arizona Geological Survey 11/09/2009 """ # Library Imports import sys import libxml2 # binding to C library of same name http://www.xmlsoft.org import libxslt # binding to C library of same name http://www.xmlsoft.org # Some variables transform_xslt = "cdcatalog.xsl" source_xml = "cdcatalog.xml" out_xml = "output.xml" def xslt_transform(): styledoc = libxml2.parseFile(transform_xslt) style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseFile(source_xml) # XSLT transform with parameters #result = style.applyStylesheet(doc, {"parameter1":"'1'","parameter2":"'string'"}) # XSLT transform without parameters result = style.applyStylesheet(doc, None) # style.saveResultToFilename(out_xml, result, 0) # save to file result_xml = style.saveResultToString(result) # save to string # cleanup - you are dealing with C libraries style.freeStylesheet() doc.freeDoc() result.freeDoc() print result_xml if __name__=="__main__": xslt_transform()
You can then follow below and it should produce similar output to the xsltproc results and also save it to the output.xml file:
$ python libxml_xslt_transform_example.py <html><body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr> <td>Empire Burlesque</td> <td>Bob Dylan</td> </tr> </table> </body></html>