| home / programming / perl / graphics / chap7 / 3 | [previous] [next] |
|
Our example uses only three XSLT elements to transform the slide description format into SVG:
<template>match attribute allows you to match a tag name; every tag of the matched type has this template applied to it. For example, the following template:
<xsl:template match="slide">
<foo>Bar</foo>
</xsl:template>
<slide> element (and anything contained within it) with the given <foo> tag.
<apply-templates>
<value-of><value-of> tag. To retrieve an attribute from the tag that has been matched with the <template> tag, use the syntax:
<xsl:template match="tag">
<xsl:value-of select="@attribute"/>
</xsl:template>
Additionally, you can retrieve the content of any element with the tag {element}, where element is the first tag that matches that name. This is used to extract the image URL in the following example.
The XSLT script in Example 7-4 uses these basic XSLT commands to convert the source XML into a valid SVG document.
Example 7-4: An XSLT transform
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="slide">
<svg width="600" height="400"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<text x="130" y="48" style="font-size:24;fill:#000000">
<xsl:value-of select="@title"/>
</text>
<image x="20" y="20" width="100" height="100"
xlink:href="{image}"/>
<text x="150" y="60" style="font-size:14;fill:#000000">
<xsl:apply-templates/>
</text>
</svg>
</xsl:template>
<xsl:template match="textline">
<tspan x="130" dy="20" font-size="16">
<xsl:apply-templates/>
</tspan>
</xsl:template>
<xsl:template match="bulletlist">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="bullet">
<tspan x="150" dy="16">
• <xsl:apply-templates/>
</tspan>
</xsl:template>
<xsl:template match="image">
</xsl:template>
</xsl:stylesheet>
| home / programming / perl / graphics / chap7 / 3 | [previous] [next] |
Created: February 26, 2003
Revised: February 26, 2003
URL: http://webreference.com/programming/perl/chap7/3/4.html