dleslie 01/05/18 08:28:55
Modified: java/samples/translets
JAXPTransletMultipleTransformations.java
JAXPTransletOneTransformation.java
Log:
Moved XSLt stylesheet to working directory
Revision Changes Path
1.5 +28 -18
xml-xalan/java/samples/translets/JAXPTransletMultipleTransformations.java
Index: JAXPTransletMultipleTransformations.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/samples/translets/JAXPTransletMultipleTransformations.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JAXPTransletMultipleTransformations.java 2001/05/17 16:41:59 1.4
+++ JAXPTransletMultipleTransformations.java 2001/05/18 15:28:47 1.5
@@ -58,6 +58,7 @@
*
*/
import java.util.Properties;
+import java.io.FileOutputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Templates;
@@ -83,37 +84,46 @@
public class JAXPTransletMultipleTransformations
{
static void doTransform(Templates translet, String xmlInURI, String
htmlOutURI)
- throws TransformerException
- {
+ throws TransformerException, FileNotFoundException
+ {
// For each transformation, instantiate a new Transformer, and perform
// the transformation from a StreamSource to a StreamResult;
Transformer transformer = translet.newTransformer();
transformer.transform( new StreamSource(xmlInURI),
- new StreamResult(htmlOutURI) );
+ new StreamResult(new
FileOutputStream(htmlOutURI)));
}
- public static void main(String argv[])
- throws TransformerException, TransformerConfigurationException,
IOException, SAXException,
- ParserConfigurationException, FileNotFoundException
- {
-
+ public static void main(String argv[])
+ {
// Set the TransformerFactory system property to generate and use
translets.
+ // Note: To make this sample more flexible, load properties from a
properties file.
+ // The setting for the Xalan Transformer is
"org.apache.xalan.processor.TransformerFactoryImpl"
String key = "javax.xml.transform.TransformerFactory";
String value = "org.apache.xalan.xsltc.runtime.TransformerFactoryImpl";
Properties props = System.getProperties();
props.put(key, value);
+
System.setProperties(props);
- String xslInURI = "../../todo.xsl";
- // Instantiate the TransformerFactory, and use it along with a
SteamSource
- // XSL stylesheet to create a translet as a Templates object.
- TransformerFactory tFactory = TransformerFactory.newInstance();
- Templates translet = tFactory.newTemplates(new StreamSource(xslInURI));
+ String xslInURI = "todo.xsl";
+
+ try
+ {
+ // Instantiate the TransformerFactory, and use it along with a
SteamSource
+ // XSL stylesheet to create a translet as a Templates object.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Templates translet = tFactory.newTemplates(new StreamSource(xslInURI));
+
+ // Perform each transformation
+ doTransform(translet, "../../xsltc_todo.xml", "todo-xsltc.html");
+ System.out.println("Produced todo-xsltc.html");
- // Perform each transformation
- doTransform(translet, "../../xsltc_todo.xml", "todo-xsltc.html");
- System.out.println("Produced todo-xsltc.html");
- doTransform(translet, "../../todo.xml", "todo-xalan.html");
- System.out.println("Produced todo-xalan.html");
+ doTransform(translet, "../../todo.xml", "todo-xalan.html");
+ System.out.println("Produced todo-xalan.html");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
}
1.6 +21 -12
xml-xalan/java/samples/translets/JAXPTransletOneTransformation.java
Index: JAXPTransletOneTransformation.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/samples/translets/JAXPTransletOneTransformation.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JAXPTransletOneTransformation.java 2001/05/17 16:46:38 1.5
+++ JAXPTransletOneTransformation.java 2001/05/18 15:28:50 1.6
@@ -58,6 +58,7 @@
*
*/
import java.util.Properties;
+import java.io.FileOutputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Templates;
@@ -84,26 +85,34 @@
public static void main(String argv[])
throws TransformerException, TransformerConfigurationException,
IOException, SAXException,
ParserConfigurationException, FileNotFoundException
- {
-
+ {
// Set the TransformerFactory system property to generate and use a
translet.
+ // Note: To make this sample more flexible, load properties from a
properties file.
+ // The setting for the Xalan Transformer is
"org.apache.xalan.processor.TransformerFactoryImpl"
String key = "javax.xml.transform.TransformerFactory";
String value = "org.apache.xalan.xsltc.runtime.TransformerFactoryImpl";
Properties props = System.getProperties();
props.put(key, value);
System.setProperties(props);
- String xslInURI = "../../todo.xsl";
+ String xslInURI = "todo.xsl";
String xmlInURI = "../../xsltc_todo.xml";
String htmlOutURI = "todo-xsltc.html";
- // Instantiate the TransformerFactory, and use it along with a
SteamSource
- // XSL stylesheet to create a Transformer.
- TransformerFactory tFactory = TransformerFactory.newInstance();
- Transformer transformer = tFactory.newTransformer(new
StreamSource(xslInURI));
- // Perform the transformation from a StreamSource to a StreamResult;
- transformer.transform(new StreamSource(xmlInURI),
- new StreamResult(htmlOutURI));
- System.out.println("Produced todo-xsltc.html");
+ try
+ {
+ // Instantiate the TransformerFactory, and use it along with a
SteamSource
+ // XSL stylesheet to create a Transformer.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer(new
StreamSource(xslInURI));
+ // Perform the transformation from a StreamSource to a StreamResult;
+ transformer.transform(new StreamSource(xmlInURI),
+ new StreamResult(new
FileOutputStream(htmlOutURI)));
+ System.out.println("Produced todo-xsltc.html");
+ }
+ catch (Exception e)
+ {
+ System.out.println(e.toString());
+ e.printStackTrace();
+ }
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]