This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: include text file
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: include text file
- From: "Steve Muench" <Steve dot Muench at oracle dot com>
- Date: Wed, 15 Nov 2000 12:47:55 -0800
- References: <200011152033.NAA00827@skew.org>
- Reply-To: xsl-list at mulberrytech dot com
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.
import java.io.*;
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 = in.read(buffer)) != -1)
out.write(buffer, 0, numchars);
out.close();
}
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
http://www.oreilly.com/catalog/orxmlapp/
----- Original Message -----
From: "Mike Brown" <mike@skew.org>
To: <xsl-list@mulberrytech.com>
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:
| webb.net in Denver, Colorado, USA http://www.skew.org/xml/
|
|
| XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list