Hi,
As you now now days xlst is very useful in mobile and telecome do1mains . Since mobile screen size is less which doesnot have all the features to disp1lay . Hence XSLT is much powerful in this case . which will solve all the business logic and also sophisticated tools are available with netbeans and eclipse pulgins are also available . So The use of xslt in real time business scenario is essential . I am tryig to give basic idea of the XSLT .
xml is file one which xsl will work and parse the nodes based on the condition and displays the html nodes .
- which will prase through entire xml start from root node
- this will refere attribute value .
- gives the value of particular attribute
Sample program which I wrote :
*******************************
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mydbcp;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
*
* @author root
*/
public class XslToXhtml {
public static void main(String args[]) throws TransformerException {
ByteArrayInputStream isXmlFile = null;
System.out.println("Starting... ");
try {
isXmlFile = new ByteArrayInputStream(getXmlString().getBytes("UTF-8"));
File isXslFile = new File("/src/mydbcp/myxsl.xsl");
if (isXslFile != null && isXmlFile != null) {
try {
Source xmlSource = new StreamSource(isXmlFile);
Source xsltSource = new StreamSource(isXslFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = (Transformer) transFact.newTransformer(xsltSource);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(baos);
trans.transform(xmlSource, streamResult);
String str = baos.toString();
System.out.println(str);
} catch (TransformerConfigurationException ex) {
Logger.getLogger(XslToXhtml.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
Logger.getLogger(XslToXhtml.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
isXmlFile.close();
} catch (IOException ex) {
Logger.getLogger(XslToXhtml.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public static String getXmlString() {
String str="";
return str;
}
}
|
Comments