"""Demonstrates how to pass top-level XSLT parameters in Pyana.
Notice how, in the first call to transformToString, "Python" is quoted twice. This is because
the value of parameters are treated as XPath and literal strings must be quoted, just like
they must be in normal XPaths e.g.
<xsl:value-of select='"Python"'/>
"""
import Pyana
inputExampleXSL = r'''
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="lang"/>
<xsl:output method="text"/>
<xsl:template match="message"><xsl:value-of select="concat(child::text(),$lang)"/></xsl:template>
</xsl:stylesheet>
'''
inputExampleXML = r'''
<message>The only thing better than XSLT is </message>
'''
print Pyana.transform2String(source=inputExampleXML, style=inputExampleXSL, params={'lang': '"Python"'})
print Pyana.transform2String(source=inputExampleXML, style=inputExampleXSL, params={'lang': 'concat("Py", "thon")'})
|