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
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

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

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