xslt extended method
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   TPZ_Stamp
Posted On:   Tuesday, April 8, 2003 12:31 AM

java code: import javax.xml.parsers.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import java.io.File; import java.util.Date; import org.w3c.dom.*; public class XSLOBJ { public static String getDate() { Date d = new Date(); return d.toString(); } public XSLOBJ(){} public static void main(String[] args){ try{ DocumentBuilderFactory bdf = DocumentBuilderFactory.newInstance(); DocumentBuilder bd = bdf.newDocumentBuilder(); Document doc = bd.newDocument(); Element root = doc.createElement("Root"   More>>
			
java code:
import javax.xml.parsers.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import java.io.File;
import java.util.Date;
import org.w3c.dom.*;

public class XSLOBJ {
public static String getDate() {
Date d = new Date();
return d.toString();
}
public XSLOBJ(){}
public static void main(String[] args){
try{
DocumentBuilderFactory bdf = DocumentBuilderFactory.newInstance();
DocumentBuilder bd = bdf.newDocumentBuilder();
Document doc = bd.newDocument();
Element root = doc.createElement("Root");
Element date = doc.createElement("Date");

root.appendChild(date);
doc.appendChild(root);
DOMSource source = new DOMSource(doc);

StreamSource xslSource = new StreamSource("date.xsl");
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer(xslSource);

StreamResult target = new StreamResult("result.xml");
t.transform(source,target);
}catch(Exception e){System.out.println(e);}
}
}

=====================================================


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














=======================================

runtime exception:
			
file:/E:/working/XML/classes/date.xsl; Line 3; Column -1;
javax.xml.transform.TransformerException: Instance
method call to method new requires an Object instance
as first argument

============================================================


Please help me to resolve this problem.Thanks.    <<Less

Re: xslt extended method

Posted By:   Roseanne_Zhang  
Posted On:   Saturday, April 12, 2003 01:39 PM

What you want to do does not even require a customized java extention. Simply using java.util.Date is enough. However, if you want to format you date string properly, then you do need to write your own class.


I found some time, and wrote 2 examples. One does what you wanted to do. The other does more.


  • A simple Java extension example
  • A customized Java extension example


The link is XSLT Extension, advanced topics


Enjoy!!!

About | Sitemap | Contact