Introduction
This tutorial is for developers who want to use Scalable Vector Graphics (SVG) to create interactive SVG graphics and to produce such SVG images from an XML file using XSLT. It discusses the use of ECMAScript (JavaScript) to enable users to interact with and change an existing SVG image in real time without reloading the browser page. It also demonstrates linking from an SVG element.
Readers should have read the Introduction to SVG tutorial here on developerWorks, or have some similar understanding of SVG fundamentals. Some previous knowledge of JavaScript and XSLT is also advantageous.
SVG is a powerful visual tool ideally suited to display data held as XML. This tutorial demonstrates the use of SVG to display a simplified interactive floor plan. JavaScript provides interactivity in SVG images in this tutorial, enabling visitors to the Web page to zoom in and out of the image, scroll between rooms, and perform additional functions. The tutorial covers:
- Creating the initial SVG image
- Zooming in and out of the image
- Using JavaScript to scroll the image from room to room
- Deleting SVG elements
- Adding new SVG elements
- Linking from an SVG element to another document
- Generating the SVG document dynamically using XSLT
The tutorial shows you how to build HTML, SVG, and XSLT documents. To follow along you need a text editor, an SVG viewer, and an XSLT engine:
- A plain text editor is all you need to create SVG files. XML-enabled text editors which can check for well-formedness and/or validity are very useful for detecting coding errors but are not necessary.
- An SVG viewer: The most widely used SVG viewer at the time of this writing is Adobe's SVG Viewer, version 3.0, which is available for free at http://www.adobe.com/svg/viewer/install/main.html. Other SVG viewers are listed in the Resources.
- A browser: The Adobe viewer works best with Microsoft Internet Explorer 5.x and above, and also with Netscape Navigator 4.x and above. The Adobe SVG Viewer version 3 does not work reliably with Mozilla 1.0 and above, particularly when scripting code is present.
- An XSLT processor: The Saxon XSLT processor is used for this example. It can be downloaded from http://saxon.sourceforge.net/.




