]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Modification of ExampleXML2PDF to show a Transformer.setParameter() call.
authorGlen Mazza <gmazza@apache.org>
Mon, 9 Feb 2004 22:04:23 +0000 (22:04 +0000)
committerGlen Mazza <gmazza@apache.org>
Mon, 9 Feb 2004 22:04:23 +0000 (22:04 +0000)
Fix to xsl stylesheet to show '1.0' instead of just '1' for the version number
(fix from Clay Leeds).

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197343 13f79535-47bb-0310-9956-ffa450edef68

examples/embedding/java/embedding/ExampleXML2PDF.java
examples/embedding/xml/xslt/projectteam2fo.xsl

index 9cabadc0c22d5f46b44f897cb49f1d1f6f581377..2c203fe9db3d7407b9e8353d9e4e3f8e55dd0776 100644 (file)
@@ -79,52 +79,6 @@ import org.apache.fop.apps.FOPException;
  */
 public class ExampleXML2PDF {
 
-    /**
-     * Converts an XML file to a PDF file using JAXP and FOP.
-     * @param xml the XML file
-     * @param xslt the stylesheet file
-     * @param pdf the target PDF file
-     * @throws IOException In case of an I/O problem
-     * @throws FOPException In case of a FOP problem
-     * @throws TransformerException In case of a XSL transformation problem
-     */
-    public void convertXML2PDF(File xml, File xslt, File pdf) 
-                throws IOException, FOPException, TransformerException {
-        //Construct driver
-        Driver driver = new Driver();
-        
-        //Setup logger
-        Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
-        driver.enableLogging(logger);
-        driver.initialize();
-
-        //Setup Renderer (output format)        
-        driver.setRenderer(Driver.RENDER_PDF);
-        
-        //Setup output
-        OutputStream out = new java.io.FileOutputStream(pdf);
-        out = new java.io.BufferedOutputStream(out);
-        try {
-            driver.setOutputStream(out);
-
-            //Setup XSLT
-            TransformerFactory factory = TransformerFactory.newInstance();
-            Transformer transformer = factory.newTransformer(new StreamSource(xslt));
-        
-            //Setup input for XSLT transformation
-            Source src = new StreamSource(xml);
-        
-            //Resulting SAX events (the generated FO) must be piped through to FOP
-            Result res = new SAXResult(driver.getContentHandler());
-
-            //Start XSLT transformation and FOP processing
-            transformer.transform(src, res);
-        } finally {
-            out.close();
-        }
-    }
-
-
     /**
      * Main method.
      * @param args command-line arguments
@@ -150,8 +104,41 @@ public class ExampleXML2PDF {
             System.out.println();
             System.out.println("Transforming...");
             
-            ExampleXML2PDF app = new ExampleXML2PDF();
-            app.convertXML2PDF(xmlfile, xsltfile, pdffile);
+            //Construct driver
+            Driver driver = new Driver();
+            
+            //Setup logger
+            Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
+            driver.enableLogging(logger);
+            driver.initialize();
+    
+            //Setup Renderer (output format)        
+            driver.setRenderer(Driver.RENDER_PDF);
+            
+            //Setup output
+            OutputStream out = new java.io.FileOutputStream(pdffile);
+            out = new java.io.BufferedOutputStream(out);
+            try {
+                driver.setOutputStream(out);
+    
+                //Setup XSLT
+                TransformerFactory factory = TransformerFactory.newInstance();
+                Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
+                
+                // set the value of a <param> in the stylesheet
+                transformer.setParameter("versionParam", "2.0");
+            
+                //Setup input for XSLT transformation
+                Source src = new StreamSource(xmlfile);
+            
+                //Resulting SAX events (the generated FO) must be piped through to FOP
+                Result res = new SAXResult(driver.getContentHandler());
+    
+                //Start XSLT transformation and FOP processing
+                transformer.transform(src, res);
+            } finally {
+                out.close();
+            }
             
             System.out.println("Success!");
         } catch (Exception e) {
index d10ae8551d2885ab3e6c203db9668d1b70d87cf9..7752b8aee72fb34d5d249565e672c59ec95509b6 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
   <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
-  <xsl:param name="versionParam" select="1.0"/> 
+  <xsl:param name="versionParam" select="'1.0'"/> 
   <!-- ========================= -->
   <!-- root element: projectteam -->
   <!-- ========================= -->