Hello,
I'm a newby, and I'm trying to use Xalan to perform a transformation
from XML to SVG. Java tells me that 'The XML declaration must end with
"?>". ', but I don't understand why, as my declaration seems to be
correct: <?xml version="1.0" encoding="UTF-8" standalone="no"?>. I only
modified the SimpleTransform.java sample file. The main difference I can
see is that I use dtds while the sample files don't. Could it be the
reason?
Any help would be appreciated,
-Karim Barkati
Here's the exception:
[barkati@ceres musicxml2svg]$ java MusicXML2SVG
file:///home/barkati/musicxml2svg/mutshortshort.xml; Line 1; Column 54
XSL Error: Could not parse mutshortshort.xml document!
XSL Error: SAX Exception
Exception in thread "main" org.apache.xalan.xslt.XSLProcessorException:
The XML declaration must end with "?>".
at
org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1753)
at
org.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLTEngineImpl.java:971)
at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:643)
at MusicXML2SVG.main(MusicXML2SVG.java:81)
And my source files:
MusicXML2SVG.java:
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
*************");
}
}
mutshortshort.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML
Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<work>
<work-number>D. 911</work-number>
<work-title>Winterreise</work-title>
</work>
<movement-number>22</movement-number>
<movement-title>Mut</movement-title>
<identification>
<creator type="composer">Franz Schubert</creator>
<creator type="poet">Wilhelm Müller</creator>
<rights>Electronic edition Copyright © 2001 Recordare. All rights
reserved.</rights>
<encoding>
<encoding-date>2001-01-12</encoding-date>
<encoder>Michael Good</encoder>
<software>Finale 2001c for Windows</software>
<encoding-description>MusicXML 0.1b example</encoding-description>
</encoding>
<source>Based on Dover reprint of Breitkopf & Härtel edition of
1895. Original A-minor version; later transposed to G minor.</source>
</identification>
<part-list>
<score-part id="P1">
<part-name>Singstimme.</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>4</divisions>
<key>
<fifths>0</fifths>
<mode>minor</mode>
</key>
<time>
<beats>2</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction>
<direction-type>
<words xml:lang="de">Ziemlich geschwind, kräftig</words>
</direction-type>
</direction>
<note>
<rest/>
<duration>8</duration>
<type>half</type>
</note>
<barline>
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
mutshortshort.xsl:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"
"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="score-partwise">
<svg width="12cm" height="4cm" viewBox="0 0 1200 400">
<desc>Example line01 - lines expressed in user coordinates</desc>
<g style="fill:none; stroke:green">
<line x1="100" y1="300" x2="300" y2="100"
style="stroke-width:5" />
<line x1="300" y1="300" x2="500" y2="100"
style="stroke-width:10" />
<line x1="500" y1="300" x2="700" y2="100"
style="stroke-width:15" />
<line x1="700" y1="300" x2="900" y2="100"
style="stroke-width:20" />
<line x1="900" y1="300" x2="1100" y2="100"
style="stroke-width:25" />
</g>
</svg>
</xsl:template>
</xsl:stylesheet>