Subject: [xsl] Transform object and pass in an InputStream of the said imported XSLT file as a parameter? From: "Murali P" <p.muralii@xxxxxxxxx> Date: Mon, 27 Nov 2006 16:07:18 +0800 |
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.
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"); }
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.
<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>
Regards Murali
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] I'm trying to convert fix, Michael Kay | Thread | Re: [xsl] Transform object and pass, Andrew Welch |
Re: [xsl] Standards checkers for XS, Rashmi Rubdi | Date | [xsl] transform from flat to hierar, Ken Tam |
Month |