Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XSLT with large file size

843834Nov 10 2004 — edited Nov 12 2004
Hello all,

I am very new to XSL. I have been reading a lot on it. I have a small transformation program which takes an xml file, an xsl file and performs the transformation. Everything works fine when the file size is in terms of KB. When I tried the same program with the file size of around 118MB, it is giving me out of memory exception. I would appreciate any comments to make my program work for bigger file size. I am posting my java code and xsl file


public static void xsl(String inFilename, String outFilename, String xslFilename) {
try {
// Create transformer factory
TransformerFactory factory = TransformerFactory.newInstance();

// Use the factory to create a template containing the xsl file
Templates template = factory.newTemplates(new StreamSource(
new FileInputStream(xslFilename)));


// Use the template to create a transformer
Transformer xformer = template.newTransformer();

// Prepare the input and output files
Source source = new StreamSource(new FileInputStream(inFilename));
Result result = new StreamResult(new FileOutputStream(outFilename));

// Apply the xsl file to the source file and write the result to the output file
xformer.transform(source, result);
} catch (FileNotFoundException e) {
System.out.println("Exception " + e);
} catch (TransformerConfigurationException e) {
// An error occurred in the XSL file
System.out.println("Exception " + e);
} catch (TransformerException e) {
// An error occurred while applying the XSL file
// Get location of error in input file
SourceLocator locator = e.getLocator();
int col = locator.getColumnNumber();
int line = locator.getLineNumber();
String publicId = locator.getPublicId();
String systemId = locator.getSystemId();
System.out.println("Exception " + e);
System.out.println("locator " + locator.toString());
System.out.println("line : " + line);
System.out.println("col : " + col);
}
System.out.println("No Exception");
}

xsl file :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:element name="Hosts">
<xsl:apply-templates select="//maps/map/hosts"/>
</xsl:element>
</xsl:template>


<xsl:template match="//maps/map/hosts">

<xsl:for-each select="*">
<xsl:element name="host">
<xsl:element name="ip"><xsl:value-of select="./@ip"/></xsl:element>
<xsl:element name="known"><xsl:value-of select="./known/@v"/></xsl:element>
<xsl:element name="targeted"><xsl:value-of select="./targeted/@v"/></xsl:element>
<xsl:element name="asn"><xsl:value-of select="./asn/@v"/></xsl:element>
<xsl:element name="reverse_dns"><xsl:value-of select="./reverse_dns/@v"/></xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>

Thanks,
Namrata


</xsl:stylesheet>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2004
Added on Nov 10 2004
1 comment
777 views