On 2/20/2010 11:53 AM, bradley.peder...@gmail.com wrote:
To all-

Earlier this week, I was able to read a file in XSLT using Xalan-J
function extensions (XJ 2.7, BSF 2.4, Rhino 1.7). The mechanism is very
simple JavaScript with Java Class calls. It works very elegantly
(simple) as shown below. However, I learned that the vendor software
that will run the transformation uses Xalan C++ (v1.9 with Xerces 2.6)
and now I have to rewrite using function extensions in C++. I suppose
I’m ignorant for not checking up front.

However, proceeding with Xalan-C++, my primary question is: In order to
use custom function extensions in Xalan C++, do I have to rebuild the
Xalan C++ library or is there a way to install an extension function
without rebuild? As noted, I’m using a vendor instance of Xalan C++
which they themselves may have built, thus rebuilding may not be an
option since I don’t have their source. I guess I’m a little stuck on
how the installation of extension functions work and really could use a
step by step flow/example. If I have to rebuild, I'll be using VS2005.
You don't need to rebuild Xalan-C, but you need to make sure you're using the same version of Visual Studio (including service pack level) as the vendor.

Here is what I’m trying to convert from Xalan-J to Xalan-C++ in case
someone has a snippet for Xalan-C++ that they would like to offer, all
help would be greatly appreciated. It worked so beautifully in Xalan-J,
need to get the same functionality in Xalan-C++.

SCRIPT FOR XALAN-J TO READ FILE
<xalan:component prefix="javascript" elements="" functions="readFile">
<xalan:script lang="javascript">
function readFile ( filename ) {

var text = '';
var filechar;
var i=0;
var file = new java.io.File(filename);
var FileReader = new java.io.FileReader(file);
var BuffReader = new java.io.BufferedReader(FileReader);
fileline = BuffReader.readLine();
while (fileline != null) {
text = text + fileline + '\n';
fileline = BuffReader.readLine();
}
BuffReader.close();
return text;

}
</xalan:script>
</xalan:component >

CALLED
<xsl:value-of select="javascript:readFile(string($LongTextFile))"/>
This is easy to do with an extension function. Take a look at the ExtensionFunction sample application for more information on how to write and install extension functions.

You will also need to know the encoding of the input file you'll be reading, so you'll need to ask your vendor about that. Once you know that information, it should be very straightforward to read the data from the file using your favorite C/C++ library function, transcode the data from the source encoding to UTF-16 using a transcoder from Xerces-C, then append the data to a XalanDOMString instance. Take a look at the class FunctionAsctime in the ExternalFunction sample, for an example.

Dave

Reply via email to