| xlst support | xlst support 2003-02-07 - By Sebastien BLANC
Hello ! looking at the ANT doc there is only a task for XML validation. would u happen to know where ANT does provide support for xlst (saw few emails going around it, is this a new task ?) ?
I'm roughly doing the following w/ java currently. is there a way to task w/ ant ?
thanx.
seb.
import java.io.*;
import javax.xml.transform.OutputKeys; import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document; import org.w3c.dom.Element;
//import org.apache.xerces.validators.schema.identity.XPath; import org.apache.xpath.*;
/** * Pass a parameter to a stylesheet using JAXP 1.1. * * @(protected) February 6, 2003 */ public class DAOGenerator {
public static void main(String[] args) throws javax.xml.transform.TransformerException, IOException { File xmlDir = new File(args[0]); File[] xmlFiles = xmlDir.listFiles();
for (int currentFileId = 0; currentFileId < xmlFiles.length; currentFileId++) {
File currentXMLFile = xmlFiles[currentFileId]; String currentXMLFileName = currentXMLFile.getName();
// Let's check the document first. So we do no use StreamSource // to read the file // javax.xml.transform.Source xmlSource = // new javax.xml.transform.stream.StreamSource(currentXMLFile); javax.xml.transform.Source xmlSource = null; String xsltFileName = null; try { DAOXMLDocument xmlDoc = new DAOXMLDocument(currentXMLFile.getAbsolutePath()); xmlSource = new javax.xml.transform.dom.DOMSource(xmlDoc.getRawDocument());
// Let's extract the style sheet to apply String styleSheetName = XPathAPI.eval(xmlDoc.getRawDocument(),"/dao/tl1Entity/@(protected)").toString( );
File xsltFile = new File("xslt/" + styleSheetName + ".xslt"); javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(xsltFile);
// send the result to a file File resultFile = new File(args[1], currentXMLFileName.substring(0, currentXMLFileName.indexOf('.')) + "DAO.java");
resultFile.createNewFile();
javax.xml.transform.Result result = new javax.xml.transform.stream.StreamResult(resultFile);
System.out.println("Results will go to: " + resultFile.getAbsolutePath());
// create an instance of TransformerFactory javax.xml.transform.TransformerFactory transFact = javax.xml.transform.TransformerFactory.newInstance();
javax.xml.transform.Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, result);
} catch (org.xml.sax.SAXException foo) { System.out.println("Parsing error for: " + foo.getMessage()); }
} // resultFile.close(); } }
|
|
 |