SVG, Unicode, and XSLT - Part 3 of Chapter 7 from Perl Graphics Programming (3/5) | WebReference

SVG, Unicode, and XSLT - Part 3 of Chapter 7 from Perl Graphics Programming (3/5)

To page 1To page 2current pageTo page 4To page 5
[previous] [next]

Perl Graphics Programming, Chapter 7: Creating SVG with Perl

Transformation with XSLT and Perl

The XML Stylesheet Language Transformations (XSLT) specification describes an XML-based scripting language that can be used to create rules for transforming one XML format into another. In some cases you may wish to use XSLT instead of a Perl-based solution. You can still use Perl to interpret the XSLT rules, however. The XSLT specification is available online at http://www.w3.org/TR/xslt.

Example 7-3 reimplements part of the slide-show generator script introduced in Chapter 6, this time using XSLT. The example uses a slightly different version of the slide XML description language discussed there.

Example 7-3: A slightly different XML slide presentation format

<slide title="Perl for Graphics">
    <image>http://shawn.apocabilly.org/PFG/examples/shawn.png
    </image>
    <textline>Section I: Raster Graphics</textline>
    <bulletlist>
        <bullet>1. PNG, GIF, and JPEG</bullet>
        <bullet>2. Using GD</bullet>
        <bullet>3. Using Image::Magick</bullet>
        <bullet>4. Using GD::Chart</bullet>
        <bullet>5. Scripting Gimp plug-ins</bullet>
    </bulletlist>
    <textline>Section II: Vector graphics</textline>
    <bulletlist>
      <bullet>6. The SVG format</bullet>
      <bullet>7. SVG Recipes</bullet>
      <bullet>8. The SWF format</bullet>
      <bullet>9. Generating SWF files with Ming </bullet>
    </bulletlist>
    <textline>Section III: Printing formats</textline>
    <bulletlist>
      <bullet>10. PostScript and PDF</bullet> 
      <bullet>11. Using the Postscript modules </bullet>
      <bullet>12. Using the Text::PDF module </bullet>
    </bulletlist>
  </slide>

That is our input XML; the output is an SVG image for the slide.

XSLT is an evolutionary child of Cascading Style Sheets (CSS) and the Extensible Stylesheet Language (XSL). XSLT defines a collection of XML elements (in the xsl namespace) that forms almost a kind of internal XML scripting language. An XSLT document is applied to a source XML document, and provides a series of rules or "templates" that match elements in the source document. Each template can add new XML elements or rearrange the source XML tree. Templates are applied to the entire source document; if a template matches an element, the rule is applied. If it doesn't match any text in the source document, the source text is passed on unmodified to the output tree.


To page 1To page 2current pageTo page 4To page 5
[previous] [next]

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

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