Perl Integration

Creating an extension with Perl

Layout of this Document:

Sample – Building the Perl Component

Calling the extension from TransactXML Server

Calling the extension from the XSLT engine

=======  Sample – Building the Perl Component =======

  1. Select and install a perl runtime.

Both of most popular perls are supported.

The public source at CPAN (Comprehensive Perl Archive Network)  https://www.perl.org/cpan.html

and

ActivePerl by ActiveState   http://www.activestate.com/activeperl/downloads

Select the correct perl driver described in the Readme.txt file in the

PearlDriver directory for your operating system.

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

[Perl]
Path=/MyPerlScripts

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

  1. Save the following text to Example.pl in the location you specified in the previous stepsub ExposedMethods
    {
    ##############################################################
    # Format: Method[ArgName&&DataType]&&&&
    # where [ArgName&&DataType] repeats for each argument
    #
    # This example exposes the first two routines
    # showtime
    # – takes no arguments
    # LeftString
    # – takes a String called “Input” and an Int called “NewLen”
    ##############################################################”
    showtime&&&&
    LeftString&&Input&&String&&NewLen&&Integer&&&&

    }

    sub showtime
    {
    time;
    }

    sub LeftString
    {
    my($s, $n) = @_ ;
    substr($s, 0, $n);
    }

    sub PrivateRoutines
    {
    # any routine not exposed in ExposedMethods
    # cannot be accessed directly
    }

    Now your custom perl 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:

Perl-E2This causes the Element “MyElement” to get it’s value from the external Perl 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:Perl%Example.pl%Example%LeftString()

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:

Perl-E3

 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:Perl%Example.pl%Example%LeftString(.,3)”/>

</th>

</tr>

</xsl:for-each>

</tbody>

</table>

</xsl:template>

</xsl:stylesheet>

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