Python Integration

Creating an extension with Python

Layout of this Document:

Sample – Building the Python Component

Calling the extension from TransactXML Server

Calling the extension from the XSLT engine

=======  Sample – Building the Python Component =======

  1. (NT only) Install the Python runtime. (copy Python21.dll to your windows system directory)

Unix builds statically link the Python runtime, so no shard libs need to be installed in your machine.

Drivers are built using public source Python available at: http://www.python.org/

Make sure the python driver (PythonDriver.dll or PythonDriver.so) is in the location specified by txml.txt

[Settings] Drivers=

  1. Set the [Python] section in TXML.TXT like this

[Python]
Path=/MyPythonScripts

(use Path=C:\MyPythonScripts if you use Windows)

3. Save the following text to Sample.py in the location you specified in the previous step

##############################################################
# Format: Class::Method[ArgName&&DataType]&&&&
# where [ArgName&&DataType] repeats for each argument
##############################################################
def ExposedMethods(): return \
“Global::SayHello&&&&” \
“Global::FnWithParams&&Name&&String&&Value&&Integer&&&&” \
“MyClass::MyPublic1&&x&&Integer&&y&&Integer&&&&” \
“MyClass::MyPublic2&&x&&Integer&&y&&Integer&&&&” \
“MyClass::MyPublic3&&x&&Integer&&y&&Integer&&&&” \
“AClass::MyPublic1&&x&&Integer&&y&&Integer&&&&” \
“AClass::MyPublic2&&x&&Integer&&y&&Integer&&&&” \
“AClass::MyPublic3&&x&&Integer&&y&&Integer&&&&”

def SayHello():
return “Hello ” \
“from Python”

def FnWithParams(Name, Value):
return “Name[%s] Value[%i]” % (Name, Value)

class MyClass:
def MyPrivate(self, x, y): return “%i-MyPrivate-%i” % (x, y)
def MyPublic1(self, x, y): return “%i-MyPublic1-%i” % (x, y)
def MyPublic2(self, x, y): return “%i-MyPublic2-%i” % (x, y)
def MyPublic3(self, x, y): return “%i-MyPublic3-%i” % (x, y)

class AClass:
def MyPrivate(self, x, y): return “%i-APrivate-%i” % (x, y)
def MyPublic1(self, x, y): return “%i-APublic1-%i” % (x, y)
def MyPublic2(self, x, y): return “%i-APublic2-%i” % (x, y)
def MyPublic3(self, x, y): return “%i-APublic3-%i” % (x, y)

Now your custom python extension is ready to be used from TransactXML Server or the XSLT engine. Both examples are shown.

===  Calling the extension from TXML Server ===

1.      From DesignerXML, double click an element to get the following dialog:

Java-E1 Change the “Element Value Source” to “Custom extension” and the following dialog box will popup. The Dialog will be empty by default. You should set the following values to call the example built above:

Python1This causes the Element “MyElement” to get it’s value from the external Python function.  Double click the parameter to set it’s value.

===  Calling the extension from XSLT Engine ===

XSLT Engine Syntax:

functoid:LANGUAGE%COMPONENT%INTERFACE%METHOD()

To call the example above use the following syntax:

functoid:Python%Sample%Global%FnWithParams()

Here’s a complete example to transform this XML:

<customers at=’yes’>

<name>Chris</name>

<name>Sean</name>

<name>Brian</name>

<name>Lad</name>

</customers>

to this HTML table:

Python2

 by processing this XSL:

<xsl:stylesheet version=’1.0′

xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221;

xmlns:functoid=”functoid”>

<xsl:template match=”customers”>

<table width=”20%” border=”1″>

<tbody>

<xsl:for-each select=”name”>

<!–Sort the table by customer name–>

<xsl:sort/>

<tr>

<th>

<xsl:value-of select= “functoid:Python%Sample%Global%FnWithParams(.,777)”/>

</th>

</tr>

</xsl:for-each>

</tbody>

</table>

</xsl:template>

</xsl:stylesheet>

 © 2015 United Business Technologies, Inc. All Rights Reserved.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s