passing java object to xsl file
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Praveen_Bakare
Posted On:   Thursday, March 18, 2004 06:09 AM

i have written a java class(first) in which i am instantiating another(second) java class object .the other(second) java class contains attributes which correspond to column data of a row fetched from the database.the other(second) java class has get and set methods in it. how do i pass the reference of the second class to the xsl file which will put it in some xml file? how do i access it in the xsl file? can you show some sample for both the questions. xsl code is called by first java class using xalan api class (transformer). FOLLOWING ARE THE JAVA CLASSES.(here i am not querying the database for simplicity) ----------------------------------------------- import j   More>>

i have written a java class(first) in which i am instantiating another(second) java class object .the other(second) java class contains attributes which correspond to column data of a row fetched from the database.the other(second) java class has get and set methods in it.

how do i pass the reference of the second class to the xsl file which will put it in some xml file? how do i access it in the xsl file?

can you show some sample for both the questions.
xsl code is called by first java class using xalan api class (transformer).

FOLLOWING ARE THE JAVA CLASSES.(here i am not querying the database for simplicity)

-----------------------------------------------


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

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;


public class SimpleTransform
{

public static void main(String[] args)
throws TransformerException, TransformerConfigurationException,
FileNotFoundException, IOException
{
XObj temp=new XObj();
TransformerFactory tfactory=TransformarFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("9.xsl"));
temp.setName("SID");
temp.setAge(23);
transformer.transform(new StreamSource("temp.xml"), new StreamResult(new FileOutputStream("new.xml")));

System.out.println("************* The result is in new.xml *************");
}
}


class XObj {
private String name;
private int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void setName(String nm) {
name=nm;
}
public void setAge(int age) {
this.age=age;
}
}

-----------------------------------------------

   <<Less
About | Sitemap | Contact