Re: include text file

Subject: Re: include text file
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Wed, 15 Nov 2000 12:47:55 -0800
Here's a Java extension function I used while
formatting examples for my book (that I kept
in separate files so I could work on them, 
compile them, and test them from within
my Java IDE). This function reads in an
external text file and returns a single 
String representing its content.

I use it from within a stylesheet to read in
a filename like this:

   <xsl:value-of select="ext:contents(@fileref)"/>

where the "fileref" attribute is an attribute
in my source that holds the filename of the
external text file.


public class TextUtils {

  public static  String contents(String actualFileName) {

   FileReader in = null;
   try {
     in = new FileReader(actualFileName);
   catch (FileNotFoundException e) {
     return "File '"+actualFileName+"' not found.\n";
   StringWriter out = new StringWriter();

   char[] buffer = new char[4096];
   int numchars;
   try {
     while((numchars = != -1)
            out.write(buffer, 0, numchars);
   catch (IOException e) {
     return "IO Error reading file '"+actualFileName+"'.\n";
   String returnContents = out.toString();
   return returnContents.trim();



Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly

----- Original Message ----- 
From: "Mike Brown" <mike@xxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxx>
Sent: Wednesday, November 15, 2000 12:33 PM
Subject: Re: include text file

| Eric van der Vlist wrote:
| > You can't include a text document like this.
| > But you can write a simple parser to parse a text document and return
| > SAX events corresponding, for instance, to
| > <document>
| > <line>....</line>
| > .../...
| > </document>
| > 
| > I am using such a simple parser (~ 20 java lines) that I can post if it
| > helps.
| Yes, post it, if it's that short.
| Has anyone done this kind of thing with non-well-formed HTML? I mean, if
| even non-well-formed HTML can be parsed into a DOM, and a DOM can be used
| as input to an XSLT processor, it seems to follow that an extension
| function like foo:html-document() would be feasible as an analog to the
| explicitly XML-specific document() function. You wouldn't even need a DOM
| to do it. Having such an extension function would alleviate a very common
| source of frustration among people trying to generate composite HTML
| documents.
|    - Mike
| ____________________________________________________________________
| Mike J. Brown, software engineer at         My XML/XSL resources:
| in Denver, Colorado, USA 
|  XSL-List info and archive:

 XSL-List info and archive:

Current Thread