Solution 1: Fabrication de travaux.svg avec un processeur XSLT:
saxon -o travaux.svg travaux.xml travaux.xsl
Solution 2: XSLT avec un service de traduction en ligne:
Solution 3: XSLT server-side avec PHP:
<?php
header("Content-type: image/svg+xml") ;
header("Content-type: image/svg+xml");
error_reporting(E_ALL);
$xml_file = 'travaux.xml';
$xsl_file = 'travaux.xsl';
// load the xml file (and test first if it exists)
$dom_object = new DomDocument();
if (!file_exists($xml_file)) exit('Failed to open $xml_file');
$dom_object->load($xml_file);
// create dom object for the XSL stylesheet and configure the transformer
$xsl_obj = new DomDocument();
if (!file_exists($xsl_file)) exit('Failed to open $xsl_file');
$xsl_obj->load($xsl_file);
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl_obj); // attach the xsl rules
$html_fragment = $proc->transformToXML($dom_object);
print ($html_fragment);
Afficher travaux.xml (avec FireFox !) ou travaux.svg et lire ci-dessous
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"
encoding="ISO-8859-1"
standalone="no"
doctype-public="-//W3C//DTD SVG 1.0//EN"
doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" />
<!-- GLOBAL PARAMETERS - you may change this -->
<xsl:param name="increase-y" select="60"/>
<xsl:param name="element-length" select="150"/>
<xsl:param name="element-height" select="30"/>
<xsl:param name="space" select="10"/>
<!-- XSLT Functions -->
<!-- Display a single exercise -->
<xsl:template name="render-exercise">
<xsl:param name="position-x"/>
<xsl:param name="position-y"/>
<rect x="{$position-x * ( $element-length + $space ) }"
y="{$position-y * $increase-y }"
width="{$element-length}"
height="{$element-height}"
style="fill:yellow; stroke:black; stroke-width:3"/>
<text x="{$position-x * ( $element-length + $space ) }"
y="{$position-y * $increase-y + 15 }" style="stroke:#000099;fill:#000099;font-size:10;">
<xsl:value-of select="title"/>
</text>
</xsl:template>
<!-- Display a course (Text + each exercise a box on the same line -->
<xsl:template name="render-course">
<xsl:param name="position-y"/>
<text x="{$space}" y="{$position-y * $increase-y - $space } "
style="stroke:#000099;fill:#000099;font-size:12;">
<xsl:value-of select="title"/>
</text>
<xsl:for-each select="exercise">
<xsl:call-template name="render-exercise">
<xsl:with-param name="position-x" select="position()"/>
<xsl:with-param name="position-y" select="$position-y"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template match="student">
<svg width="1000" height="900">
<!-- xmlns="http://www.w3.org/2000/svg"> -->
<text x="{$space}" y="90" style="stroke:#000099;fill:#000099;font-size:24;">
Example visualisation of a student's work page</text>
<svg y="3cm">
<xsl:for-each select="//course">
<xsl:call-template name="render-course">
<xsl:with-param name="position-y" select="position() "/>
</xsl:call-template>
</xsl:for-each>
</svg>
</svg>
</xsl:template>
</xsl:stylesheet>
<xsl:template match="/">
<html xmlns:svg="http://www.w3.org/2000/svg">
<head><title>Client-side XHTML / SVG generation</title></head>
<body>
<p> ..... </p>
<svg width="1000" height="900" xmlns="http://www.w3.org/2000/svg">
<text x="{$space}" y="90" style="stroke:#000099;fill:#000099;font-size:24;">Example visualisation of a student's work page</text>
<svg y="3cm">
<xsl:for-each select="//course">
<xsl:call-template name="render-course">
<xsl:with-param name="position-y" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</svg>
</svg>
</body>
</html>
</xsl:template>
<html xmlns:svg="http://www.w3.org/2000/svg">
<xsl:template match="/">
<html xmlns:svg="http://www.w3.org/2000/svg">
<object id="AdobeSVG" CLASSID="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2"> </object>
<xsl:processing-instruction name="import">namespace="svg" implementation="#AdobeSVG"</xsl:processing-instruction>
<head><title>Client-side XHTML / SVG generation</title></head>
<body>
<p> Read this article:
<a href="http://surguy.net/articles/client-side-svg.xml">http://surguy.net/articles/client-side-svg.xml</a>.
It explains how to generate SVG plugin code within XHTML.
</p>
<svg:svg width="1000" height="900" xmlns:svg="http://www.w3.org/2000/svg">
<svg:text x="{$space}" y="90" style="stroke:#000099;fill:#000099;font-size:24;">Example visualisation of a student's work page</svg:text>
<svg:svg y="3cm">
<xsl:for-each select="//course">
<xsl:call-template name="render-course">
<xsl:with-param name="position-y" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</svg:svg>
</svg:svg>
</body>
</html>
</xsl:template>