Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: XSLT
Expertise: Advanced
Sep 13, 2006

Read the First Line of a Text File

This code shows you how to use the instance methods from the FileReader and BufferedReader classes with a Xalan 2 processor to read the first line from a text file.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"  
xmlns:FR="xalan://java.io.FileReader"
xmlns:BR="xalan://java.io.BufferedReader">
	                          
<xsl:output method="html" version="4.01" encoding="ISO-8859-1" indent="yes" media-
type="text/html" />	          
 
<xsl:variable name="file_reader" select=
"FR:new(string('C://Data_Local//XML//XSLT//in.txt'))" />
<xsl:variable name="buffered_reader" select="BR:new($file_reader)" />
<xsl:variable name="read" select="BR:readLine($buffered_reader)" />

<xsl:template  match="/">	
  <html>
  <body> 			
     <h3><xsl:value-of select="$read" /></h3>	
...
Note: This tip was tested on Xalan, version 2.7.0.

Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap