xsl-list
[Top] [All Lists]

[xsl] Transform object and pass in an InputStream of the said imported XSLT file as a parameter?

2006-11-27 01:07:45
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">&amp;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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>