spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / perl / graphics / chap7 / 3 To page 1To page 2To page 3To page 4current page
[previous]

Perl Graphics Programming, Chapter 7: Creating SVG with Perl

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Example 7-4 defines five templates, one for matching each of the XML element types in the input document. When a <slide> element is encountered, the first template is matched, and the following actions occur:

The remaining four templates perform the following actions:

Once we have created an XSLT script, we need to apply it to the input XML. For this you can use one of several freely available XSLT processors, many of which have Perl interfaces. Example 7-5 uses the Sablotron module, available on CPAN. Sablotron (see http://www.gingerall.com/ for more information) builds on the free Expat XML parser.

The Sablotron processor object maintains a set of internal "named buffers" that hold the result of a processed file. Example 7-5 is a simple wrapper that passes an XML file and template (XSLT) file to the Sablotron processor and prints the result in the internal arg:/result buffer.

Example 7-5: A simple XSLT processor

#!/usr/bin/perl
#
# Example 7-5. Using XSLT.
   
use strict;
use XML::Sablotron;
   
unless (defined($ARGV[0]) && defined $ARGV[1]) {
   die "Usage: xsltprocessor.pl xml_input.xml xslt_input.xslt\n";
}
   
my $processor = new XML::Sablotron(  );
$processor->runProcessor($ARGV[1], 
                         $ARGV[0], 
                         'arg:/result',
                         undef, undef);
   
print $processor->getResultArg("arg:/result");

The output is shown in Figure 7-4.

An SVG image generated from an XSLT transformation
Figure 7-4. An SVG image generated from an XSLT transformation


home / programming / perl / graphics / chap7 / 3 To page 1To page 2To page 3To page 4current page
[previous]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: February 26, 2003
Revised: February 26, 2003

URL: http://webreference.com/programming/perl/chap7/3/5.html