Python
Use Xalan from Python
21:37, 10 Jul 2001 UTC | Edd Dumbill

Python programmers can now use the Apache XML Project's Xalan XSLT processor thanks to Pyana.

Currently at version 0.1.0, Pyana is available as Windows binaries or as source code from Pyana's CVS repository. Pyana allows the definition of XPath extension functions in Python. Announcing release 0.1.0, Brian Quinlan gave the following example usage:

def sum(*args):
    """Compute the sum of all arguments"""
    s = 0
    for i in args:
        s += i
    return s

Pyana.install( 'exampleNS', sum, 'sum' )
inputExampleXSL = r'''
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:py="exampleNS" version="1.0">
    <xsl:output method="text"/>
    <xsl:template match="message"><xsl:value-of
select="py:sum(1,2,3,4,5)"/></xsl:template>
</xsl:stylesheet>
'''
inputExampleXML = r'''
<message>ignored</message>
'''
print Pyana.transform(inputExampleXML, inputExampleXSL) # => '15'

  
xmlhack: developer news from the XML community

Front page | Search | Find XML jobs

Related categories
Python
XSLT