You are here: Home » Tutorials » Software Development » Java » How to produce SVG code that will be rendered in graphic form by an SV..

How to produce SVG code that will be rendered in graphic form by an SVG-compatible browser in JAVA using an XSLT file

Added July 02, 2008, read 47 times

How to produce SVG files using XSLT in JAVA

This tutorial contains an sample Java code to produce a SVG file that will be rendered in graphic form by an SVG-compatible browser using XSLT (XSL transformation), using the Transformer Java class.

Java Code
 public void GetSVG(String XmlFileName,String XslFileName,String OutputFileSvg)
     {
          try {
              
                TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer =tFactory.newTransformer (new javax.xml.transform.stream.StreamSource(XslFileName));
                transformer.transform(new javax.xml.transform.stream.StreamSource(XmlFileName),new javax.xml.transform.stream.StreamResult ( new FileOutputStream(OutputFileSvg)));
            }
            catch (TransformerException ex) {
              System.out.println("Transformer exception ");
            }           
             catch (IOException ex) {
                System.out.println("Exceptie I/O");
            }  
     } 
Select all

Explaining the code

The XmlFileName parameter of the method "GetSvg" is the XML file path that needs to be graphically transformed in svg file format.

The XslFileName parameter is the XSLT file path that generates the SVG code.

The OutputFileSvg parameter  is the svg file that will be created on the disk, after the transformation.

Discuss

  • Your name
  • Your email (we'll keep this to ourselves)
  • What's it about?
  • Security check

Nobody posted any comments regarding this story. Be the first!