We will cover in this chapter the different ways you dispose to transform your XML document to the graphical document (SVG document) from a console.
This mode of transformation is used when XSLT stylesheets and definitions documents are correct.
To transform your XML document to a SVG document, the Transformer needs the following things :
The class to instantiate is transformer.TransformerXMLToSVG
.
The list of parameters is :
Attribute name | Description | Allowed values | Default value | Mandatory |
-debug |
Enters in debug mode (the graphic shows the boxes and the springs, and information about the intermediary document is displayed). | This parameter accepts no value. | - | No |
-defs |
Specifies the Definitions document that contains the background definitions. | Relative or absolute path to any Definitions document. | - | Yes |
-grp_dtd |
Specifies the GRP DTD (file name or URL). | If a file, relative or absolute path, or a URL to GRP DTD. | - | No |
-grp_dtdoutput |
In the case the GRP Doctype is a file, specifies whether, inside the GRP document, path to GRP DTD is absolute or relative. | absolute or relative . |
absolute |
No |
-grp_dtdpublicID |
In the case the GRP Doctype is a URL, specifies the public ID of the Doctype. | Any possible string for a public ID. | - | No |
-grp_schema |
Specifies the GRP Schema (file name or URL). If you don't specify a value for this
parameter, and if you don't use the parameter -grp_dtd , it will be assumed
that the file grp.xsd is present in the directory containing the XML document
you intend to transform. |
If a file, relative or absolute path, or a URL to GRP Schema. | - | No |
-grp_schemanamespace |
Specifies the GRP Schema namespace. It must be the same than the namespace specified by the Schema you use. | Any valid value for a namespace. | - | No |
-grp_schemaoutput |
In the case the GRP Schema is a file, specifies whether, inside the GRP document, path to GRP Schema is absolute or relative. | absolute or relative . |
absolute |
No |
-grp_schemaxsi |
Specifies the GRP document namespace. Generally http://www.w3.org/2001/XMLSchema-instance . |
Any valid value for a namespace. | http://www.w3.org/2001/XMLSchema-instance |
No |
-height |
Specifies the height of the resulting graphic. | Any positive real. If you specify this parameter, you must specify the -width
parameter too. |
- | No |
-svg_dtd |
Specifies the SVG DTD (file name or URL). If you don't specify a value for this
parameter, and if you don't use the parameter -svg_schema , it will be
assumed that the file svg.dtd is present in the directory containing the
XML document you intend to transform. |
If a file, relative or absolute path, or a URL to SVG DTD. | - | No |
-svg_dtdoutput |
In the case the SVG Doctype is a file, specifies whether, inside the SVG document, path to SVG DTD is absolute or relative. | absolute or relative . |
absolute |
No |
-svg_dtdpublicID |
In the case the SVG Doctype is a URL, specifies the public ID of the Doctype. | Any possible string for a public ID. | - | No |
-svg_schema |
Specifies the SVG Schema (file name or URL). | If a file, relative or absolute path, or a URL to SVG Schema. | - | No |
-svg_schemanamespace |
Specifies the SVG Schema namespace. It must be the same than the namespace specified by the Schema you use. | Any valid value for a namespace. | - | No |
-svg_schemaoutput |
In the case the SVG Schema is a file, specifies whether, inside the SVG document, path to SVG Schema is absolute or relative. | absolute or relative . |
absolute |
No |
-svg_schemaxsi |
Specifies the SVG document namespace. Generally http://www.w3.org/2001/XMLSchema-instance . |
Any valid value for a namespace. | http://www.w3.org/2001/XMLSchema-instance |
No |
-width |
Specifies the width of the resulting graphic. | Any positive real. If you specify this parameter, you must specify the -height
parameter too. |
- | No |
-xml_in |
Specifies the XML document to transform. | Relative or absolute path to any XML document. | - | Yes |
-xsl |
Specifies the XSLT stylesheet that contains the rules of transformation to get the GRP document. | Relative or absolute path to any XSLT stylesheet. | - | Yes |
We will transform an existing XML document shipped with TAXI :
editor/XML/XML/ex1.cd
.
Note : these examples make the use of DTD only.
For this first example, we will use the minimum required number of parameters.
Open a console and go to directory editor/XML/XML
. Type the following
command :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml_in ex1.cd -xsl CDtoGRP.xsl -grp_dtd ../grp.dtd -defs definitionsCD.def -svg_dtd ../svg.dtd
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
has been generated in directory
editor/XML/XML
. It looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp SYSTEM "../grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
has been generated in directory
editor/XML/XML
too. It looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="186.0" width="308.0" x="0.0" y="0.0"> ... </svg>
We will produce an absolute path for GRP DTD and a relative one for SVG DTD.
Open a console and go to directory editor/XML/XML
. Type the following
command (the absolute paths D:/editor/XML/grp.dtd
and
D:/editor/XML/svg.dtd
are the ones I have to use on my Windows machine) :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml_in ex1.cd -xsl CDtoGRP.xsl -grp_dtd D:/editor/XML/grp.dtd -grp_dtdoutput absolute -defs definitionsCD.def -svg_dtd D:/editor/XML/svg.dtd -svg_dtdoutput relative
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp SYSTEM "file:///D:/editor/XML/grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
has been generated in directory
editor/XML/XML
too. It looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="186.0" width="308.0" x="0.0" y="0.0"> ... </svg>
Note : if, on the command line, you specify a relative path like
../grp.dtd
for parameter -grp_dtd
then, inside GRP document,
the path to GRP DTD will automatically be relative.
We will use a URL as Doctype for both GRP and SVG documents.
Open a console and go to directory editor/XML/XML
. Type the following
command (URL file:///D:/editor/XML/grp.dtd
is the one I have to use on
my Windows machine) :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml_in ex1.cd -xsl CDtoGRP.xsl -grp_dtd file:///D:/editor/XML/grp.dtd -grp_dtdpublicID test -defs definitionsCD.def -svg_dtd http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd -svg_dtdpublicID -//W3C//DTD SVG 1.0//EN
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp PUBLIC "test" "file:///D:/editor/XML/grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
And document ex1.cd.svg
like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg height="186.0" width="308.0" x="0.0" y="0.0"> ... </svg>
We will specify the size of the resulting graphic.
Open a console and go to directory editor/XML/XML
. Type the following
command :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml_in ex1.cd -xsl CDtoGRP.xsl -grp_dtd ../grp.dtd -defs definitionsCD.def -svg_dtd ../svg.dtd -width 30 -height 30
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp SYSTEM "../grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
And document ex1.cd.svg
like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="30" preserveAspectRatio="xMidYMin" viewBox="0 0 308.0 186.0" width="30" x="0.0" y="0.0"> ... </svg>
The graphic is really smaller (you will see the graphic bigger if you use Batik since
attribute viewBox
is ignored by Batik on the root tag) :
We will use the debug mode.
Open a console and go to directory editor/XML/XML
. Type the following
command :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml_in ex1.cd -xsl CDtoGRP.xsl -grp_dtd ../grp.dtd -defs definitionsCD.def -svg_dtd ../svg.dtd -debug
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
The following windows appears, it displays information about the intermediary document (after resizing) :
Document ex1.cd.svg
looks like this under an SVG viewer (Batik may not
display it correctly) :
The class to instantiate is still transformer.TransformerXMLToSVG
.
The list of parameters is very short :
Attribute name | Description | Allowed values | Default value | Mandatory |
-xml |
Specifies the XML document containing all the parameters. | Relative or absolute path to the XML document. | - | Yes |
The idea is that the XML document referred by the -xml
parameter contains
all the parameters necessary to the process of transformation.
It is highly recommemded to use the provided DTD editor/XML/parameters.dtd
to rule the syntax of the XML parameter document, although it is not an obligation.
The XML parameter document must have parameters
as root tag, and must contain
the following tags, in that order :
Tag name | Description | Allowed values | Default value | Mandatory |
xml_in |
Specifies the XML document to transform. | Any XML document. | - | Yes |
xsl |
Specifies the XSLT stylesheet that contains the rules of transformation to get the GRP document. | Relative or absolute path to any XSLT stylesheet. | - | Yes |
defs |
Specifies the Definitions document that contains the background definitions. | Relative or absolute path to any Definitions document. | - | Yes |
graphic |
This tag contains no value. It is only used to specify some options that affect the resulting graphic through this attributes' tag. | None. | - | No |
grp_dtd |
Specifies the GRP DTD (file name or URL). | If a file, relative or absolute path, or a URL to GRP DTD. | - | No |
grp_schema |
Specifies the GRP Schema (file name or URL). If you don't specify a value for this
parameter, and if you don't use the parameter -grp_dtd , it will be assumed
that the file grp.xsd is present in the directory containing the XML document
you intend to transform. |
If a file, relative or absolute path, or a URL to GRP Schema. | - | No |
svg_dtd |
Specifies the SVG DTD (file name or URL). If you don't specify a value for this
parameter, it will be assumed that the file svg.dtd is present in the
directory containing the XML document you intend to transform. |
If a file, relative or absolute path, or a URL to SVG DTD. | - | No |
svg_schema |
Specifies the SVG Schema (file name or URL). | If a file, relative or absolute path, or a URL to SVG Schema. | - | No |
Some tags may have attributes :
Tag name | Attribute name | Description | Allowed values | Default value | Mandatory |
graphic |
height |
Specifies the height of the resulting graphic. | Any positive real. | - | Yes |
width |
Specifies the width of the resulting graphic. | Any positive real. | - | Yes | |
grp_dtd |
output |
In the case the GRP Doctype is a file, specifies whether, inside the GRP document, path to GRP DTD is absolute or relative. | absolute or relative . |
absolute |
No |
publicID |
In the case the GRP Doctype is a URL, specifies the public ID of the Doctype. | Any possible string for a public ID. | - | No | |
grp_schema |
namespace |
Specifies the GRP Schema namespace. It must be the same than the namespace specified by the Schema you use. | Any valid value for a namespace. | - | No |
output |
In the case the GRP Doctype is a file, specifies whether, inside the GRP document, path to GRP DTD is absolute or relative. | absolute or relative . |
absolute |
No | |
xsi |
Specifies the GRP document namespace. Generally http://www.w3.org/2001/XMLSchema-instance . |
Any valid value for a namespace. | http://www.w3.org/2001/XMLSchema-instance |
No | |
svg_dtd |
output |
In the case the SVG Doctype is a file, specifies whether, inside the SVG document, path to SVG DTD is absolute or relative. | absolute or relative . |
absolute |
No |
publicID |
In the case the SVG Doctype is a URL, specifies the public ID of the Doctype. | Any possible string for a public ID. | - | No | |
svg_schema |
namespace |
Specifies the SVG Schema namespace. It must be the same than the namespace specified by the Schema you use. | Any valid value for a namespace. | - | No |
output |
In the case the SVG Doctype is a file, specifies whether, inside the SVG document, path to SVG DTD is absolute or relative. | absolute or relative . |
absolute |
No | |
xsi |
Specifies the SVG document namespace. Generally http://www.w3.org/2001/XMLSchema-instance . |
Any valid value for a namespace. | http://www.w3.org/2001/XMLSchema-instance |
No |
Notes : if you specify the size of the resulting graphic with tag graphic
,
the proportion of the graphic will be kept. Batik will ignore
this size information, so TAXI will since it is based on Batik.
We will do the same things than previously (with the parameters typed directly in the console).
For this first example, we will use the minimum required number of parameters.
Save the following XML document as editor/XML/XML/parametersCD.xml
:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parameters SYSTEM "../parameters.dtd"> <parameters> <xml_in>ex1.cd</xml_in> <xsl>CDtoGRP.xsl</xsl> <defs>definitionsCD.def</defs> <grp_dtd>../grp.dtd</grp_dtd> <svg_dtd>../grp.dtd</svg_dtd> </parameters>
Open a console and go to directory editor/XML/XML
. Type the following
command :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml parametersCD.xml
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
has been generated in directory
editor/XML/XML
. It looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp SYSTEM "../grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
has been generated in directory
editor/XML/XML
too. It looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="186.0" width="308.0" x="0.0" y="0.0"> ... </svg>
We will produce an absolute path for GRP DTD and a relative one for SVG DTD.
Modify editor/XML/XML/parametersCD.xml
(changes are in bold, the
absolute paths D:/editor/XML/grp.dtd
and
D:/editor/XML/svg.dtd
are the ones I have to use on my Windows machine) :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parameters SYSTEM "../parameters.dtd"> <parameters> <xml_in>ex1.cd</xml_in> <xsl>CDtoGRP.xsl</xsl> <defs>definitionsCD.def</defs> <grp_dtd output="absolute">D:/editor/XML/grp.dtd</grp_dtd> <svg_dtd output="relative">D:/editor/XML/svg.dtd</svg_dtd> </parameters>
In the console, type the same command used for the previous example :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToGRP -xml parametersCD.xml
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp SYSTEM "file:///D:/editor/XML/grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
has been generated in directory
editor/XML/XML
too. It looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="186.0" width="308.0" x="0.0" y="0.0"> ... </svg>
Note : if you specify a relative path like ../grp.dtd
for tag
grp_dtd
, then, inside GRP document, the path to GRP DTD will automatically
be relative.
We will use a URL as Doctype for both GRP and SVG documents.
Modify editor/XML/XML/parametersCD.xml
(changes are in bold, the
absolute path D:/editor/XML/grp.dtd
is the one I have to use on my Windows
machine) :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parameters SYSTEM "../parameters.dtd"> <parameters> <xml_in>ex1.cd</xml_in> <xsl>CDtoGRP.xsl</xsl> <defs>definitionsCD.def</defs> <grp_dtd publicID="test">file:///D:/editor/XML/grp.dtd</grp_dtd> <svg_dtd publicID="-//W3C//DTD SVG 1.0//EN">http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd</svg_dtd> </parameters>
In the console, type the same command used for the previous example :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToGRP -xml parametersCD.xml
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp PUBLIC "test" "file:///D:/editor/XML/grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg height="186.0" width="308.0" x="0.0" y="0.0"> ... </svg>
We will specify the size of the resulting graphic.
Modify editor/XML/XML/parametersCD.xml
(changes are in bold) :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parameters SYSTEM "../parameters.dtd"> <parameters> <xml_in>ex1.cd</xml_in> <xsl>CDtoGRP.xsl</xsl> <defs>definitionsCD.def</defs> <graphic width="30" height="30"/> <grp_dtd>../grp.dtd</grp_dtd> <svg_dtd>../svg.dtd</svg_dtd> </parameters>
In the console, type the same command used for the previous example :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToGRP -xml parametersCD.xml
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE grp SYSTEM "../grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="30" preserveAspectRatio="xMidYMin" viewBox="0 0 308.0 186.0" width="30" x="0.0" y="0.0"> ... </svg>
The graphic is really smaller (you will see the graphic bigger if you use Batik since
attribute viewBox
is ignored by Batik on the root tag) :
When using an XML parameter document to pass parameters' value to the Transformer, you can override them on the command line, or even specify some on the command line that are not in the XML parameter document.
Let's have an example. Ensure that editor/XML/XML/parametersCD.xml
is like
this (the absolute path D:/editor/XML/svg.dtd
is the one I have to use on my
Windows machine) :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parameters SYSTEM "../parameters.dtd"> <parameters> <xml_in>ex1.cd</xml_in> <xsl>CDtoGRP.xsl</xsl> <defs>definitionsCD.def</defs> <graphic width="30" height="30"/> <grp_dtd output="relative">D:/editor/XML/grp.dtd</grp_dtd> <svg_dtd>../svg.dtd</svg_dtd> </parameters>
In the console, type the following command :
java -cp ../../lib/taxi.jar fr.loria.taxi.transformer.TransformerXMLToSVG -xml parametersCD.xml -grp_dtdoutput absolute -width 150
You should obtain the following output :
Applying XSL transformations to file ex1.cd Parsing file definitionsCD.def Generating GRP file ex1.cd.grp Creating SVG document Generating SVG file ex1.cd.svg
Document ex1.cd.grp
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "file:///D:/editor/XML/grp.dtd"> <grp xmlns:java="http://xml.apache.org/xslt/java"> ... </grp>
Document ex1.cd.svg
looks like this :
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE svg SYSTEM "../svg.dtd"> <svg height="30" preserveAspectRatio="xMidYMin" viewBox="0 0 308.0 186.0" width="150" x="0.0" y="0.0"> ... </svg>
In the XML parameter document, we specified a relative path for GRP DTD and a graphic 30 wide. We overrided these values on the command line. We can see that the path to GRP DTD is absolute and that the width of the graphic is 150.