[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Transform object and pass in an InputStream of the sai
1) I'm trying to convert fixed width files to XML using the example given in http://www.devx.com/getHelpOn/10MinuteSolution/20362 2) The example is a success but I'm trying to change it such that I do not need to read from a local file and can instead read all imported style sheets and input files from an InputStream or an in-memory string object. like this: public String setFWDefinition(Reader fr) throws IOException { BufferedReader br = new BufferedReader(fr); String line; StringBuilder result = new StringBuilder(); result.append("<records>"); while ((line = br.readLine()) != null) { result.append("<record>"); result.append(line); result.append("</record>"); } result.append("</records>"); System.out.println("result : "+result.toString()); return result.toString(); } public void Translate(String xmlfile, String xsltfile) { try { Source xmlSource = new StreamSource(xmlfile); Source xsltSource = new StreamSource(xsltfile); // the factory pattern supports different XSLT processors TransformerFactory transFact =TransformerFactory.newInstance(); //// here i'm getting error Transformer trans = transFact.newTransformer(xsltSource); trans.transform(xmlSource, new StreamResult(System.out)); }catch(Exception e) { e.printStackTrace(); System.out.println("errour occured"); } 3) I'm using the javax.xml.transform API in J2SE. 4) Where an XSLT file has a statement like <xsl:import href="FixedLengthRoutines.xsl" />, am I able to programmatically instantiate a Transform object and pass in an InputStream of the said imported XSLT file as a parameter? If I can, I would be able to avoid writing the entire imported XSLT objects to the file system prior to invoking the Transform method as I want to call my fixed width to XML class remotely. xslt file like this: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msxml="urn:schemas-microsoft-com:xslt" version="1.0"> <xsl:import href="FixedLengthRoutines.xsl"/> <xsl:output method="xml" media-type="text/xml" indent="yes" encoding="UTF-8"/> <xsl:param name="fieldSource" select="'fields.xml'"/> <xsl:param name="matchTerm" select="''"/> <xsl:template match="/xml"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Schedule</title> </head> <body> <h2 align="center"> <xsl:value-of select="records/record"/> <xsl:text disable-output-escaping="yes">&nbsp;</xsl:text> <xsl:value-of select="records/record"/>'s Schedule</h2> </body> </html> </xsl:template> <xsl:template match="*" mode="format"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> Regards Murali
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|