Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Read a plain file from XSLT 1.0

Reply
Thread Tools

Read a plain file from XSLT 1.0

 
 
psaffrey@googlemail.com
Guest
Posts: n/a
 
      04-30-2008
I'd like to read a one-line text file using an XSLT transformation.
I'm using libxslt, so I have to use XSLT 1.0.

This post:

http://www.stylusstudio.com/xsllist/...post50080.html

is promising, but I'm afraid I can't decipher it. Can anybody help?

Thanks,

Peter
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      04-30-2008
In article <f269b904-3e53-42a8-a0c9->,
<> wrote:

>I'd like to read a one-line text file using an XSLT transformation.
>I'm using libxslt, so I have to use XSLT 1.0.
>
>This post:
>
>http://www.stylusstudio.com/xsllist/...post50080.html
>
>is promising, but I'm afraid I can't decipher it. Can anybody help?


Mike is suggesting that you create another, XML, file that includes
your text file as an entity.

Suppose hello.txt contains your text - "hello world" for example.
Create hello.xml containing

<!DOCTYPE foo [
<!ENTITY ent SYSTEM "hello.txt">
]>
<foo>&ent;</foo>

Then when you read foo.xml with the document function it will be as
if you had a file containing <foo>hello world</foo>. Of course,
you'll be in trouble if the file contains text that is ill-formed
XML.

As an extension to this idea, to save creating a separate file, you
could put an entity reference to the text file *in the xslt stylesheet
itself*, and use document("") to refer to the stylesheet. To do this
the name of the text file would have to be fixed.

-- Richard
--
:wq
 
Reply With Quote
 
 
 
 
Joseph J. Kesselman
Guest
Posts: n/a
 
      04-30-2008
The other solution is to find or create an extension function which will
read and return the text file's contents. The advantage of this approach
is that, since you're returning it as data, it doesn't have to be a
well-formed XML Document Fragment; it can contain unbalanced <, >, -,
and & characters.

Depending on the details of your processor -- and what your stylesheet
actually does with the data -- it might still have to respect XML 1.0's
limitations on the legal character set. Unless the extension also
implements some custom escaping solution like <my:char ucode="3095"/>.

But this involves carving a large path into dubiously-portable
solutions. A better answer might be to write a separate preprocessor
tool which reads that file and writes out a safely XMLified version,
dealing with all of these issues in some appropriate manner... and then
have your stylesheet read and process that XML.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File.read(fname) vs. File.read(fname,File.size(fname)) Alex Dowad Ruby 4 05-01-2010 08:20 AM
Plain text file to xml file convert mahesh Java 2 02-17-2007 01:48 PM
How to read file attribute "last accessed" with plain java Hannes Heckner Java 4 06-17-2004 07:02 PM
XSLT TRANSFORMATION FROM XML TO plain Text pradeep gummi XML 3 08-13-2003 03:59 AM
Re: Unchecking 'Read all messages in plain text' in Outlook Express Lawrence DčOliveiro Computer Security 0 06-24-2003 09:30 AM



Advertisments