Transforming XML into SVG:
http://www-106.ibm.com/developerworks/education/transforming-xml/xmltosvg/index.html
Doug Tidwell: Cyber Evangelist, developerWorks XML Team
SVG Adobe's Tutorial:
http://www.adobe.com/svg/basics/getstarted.html
Ce premier développement a nécessité l'apprentissage
de nombreuses technologies: des langages dont Java, XML, et XSL, des concepts
tels les DOM ou les DTM, des normes particulières dont MusicXML
et SVG, et des librairies en cours de développement dont Xerces
et Xalan.
Le fonctionnement reste pourtant simple en apparence: un programme
Java charge un processeur Xalan, puis lui demande d'appliquer sur un fichier
XML une feuille de style XSLT, et de retourner le résultat dans
un fichier quelconque, ici ce sera un fichier SVG.
Ce code fonctionne, mais la feuille de style se limite pour l'instant
à détecter une partition MusicXML (part-wise) pour générer
une portée en SVG. Il reste une semaine pour développer l'ensemble
du code, notamment pour modéliser un ensemble de règles de
paramétrage typographique. Cela risque de poser certains problèmes
techniques au niveau de localisation des calculs, soit dans le programme
Java, soit dans la feuille de style, ou encore au niveau de la gestion
des polices musicales, qui doivent être True Type 1, ce qui n'est
pas le cas.
Suivent une exécution, puis l'ensemble du code:
[barkati@ceres musicxml2svg]$ java MusicXML2SVG
************* The result is in mutshortshort.svg *************
import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;
/**
* Simple sample code to show how to run the XSL processor
* from the API.
*/
public class MusicXML2SVG
{
public static void main(String[] args)
throws java.io.IOException,
java.net.MalformedURLException,
org.xml.sax.SAXException
{
// Have the XSLTProcessorFactory obtain a interface
to a
// new XSLTProcessor object.
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
// Have the XSLTProcessor processor object transform
"birds.xml" to
// System.out, using the XSLT instructions found
in "birds.xsl".
processor.process(new XSLTInputSource("mutshortshort.xml"),
new XSLTInputSource("mutshortshort.xsl"),
new XSLTResultTarget("mutshortshort.svg"));
System.out.println("************* The result is in mutshortshort.svg
*************");
}
}
<xsl:template match="score-partwise">
<svg width="800" height="600" viewBox="0 0 1000 600">
<line x1="50" y1="150" x2="950" y2="150" style="stroke-width:1;
stroke:black" />
<line x1="50" y1="200" x2="950" y2="200" style="stroke-width:1;
stroke:black" />
<line x1="50" y1="250" x2="950" y2="250" style="stroke-width:1;
stroke:black" />
<line x1="50" y1="300" x2="950" y2="300" style="stroke-width:1;
stroke:black" />
<line x1="50" y1="350" x2="950" y2="350" style="stroke-width:1;
stroke:black" />
</svg>
</xsl:template>
</xsl:stylesheet>