xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anthony Ikeda <anthony.ik...@proxima-tech.com>
Subject RE: req for servlet example
Date Tue, 30 Jan 2001 23:25:02 GMT
I created the class outside of the servlet for flexiblity reasons, all you
need to do is pass it a PrintWriter and it does the rest:

public void transformText(PrintWriter out){
... //get xml and xsl data

      XSLTProcessor xsltprocessor = XSLTProcessorFactory.getProcessor();
      StringReader strrdXML = new StringReader(xmlStr);
      StringReader strrdXSL = new StringReader(xslStr);

      //Set up any parameters that may be declared.
      //Note, any string values must be set in single quotes otherwise the
      //value is recognised as a node identifier.
      String[] values = (String[])parameters.get("parms");
      if(values!=null&&values.length>0){
	for(int i=0;i<values.length;i++){
	  String paramVal = values[i];
	  System.out.println("ParamVal: "+paramVal);
	  String name = new String();
	  String value = new String();
	  java.util.StringTokenizer strnTkn = new
java.util.StringTokenizer(paramVal,"=");
	  while(strnTkn.hasMoreTokens()){
	    name = (String)strnTkn.nextToken();
	    value = (String)strnTkn.nextToken();
	  }
	  xsltprocessor.setStylesheetParam(name,value);
	}
      }
      xsltprocessor.process(new XSLTInputSource(strrdXML), new
XSLTInputSource(strrdXSL), new XSLTResultTarget(out));
...
}

Anthony Ikeda,
Web Application Developer,
Proxima Technology,

Level 13,
181 Miller Street,
North Sydney
Australia


PH: +612-9458-1718
Mob: 041 624 5143


> -----Original Message-----
> From: Heather Lloyd [mailto:lloydheat@yahoo.com]
> Sent: Tuesday, 30 January 2001 3:55 AM
> To: general@xml.apache.org
> Subject: req for servlet example
> 
> 
> can you point me to a really, really simple example of
> a java class that extends HttpServlet and uses an
> XSLTProcessor to transform a simple XML doc using a
> simple XSL Stylesheet to return an HTML doc to a
> browser?  thanks
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices. 
> http://auctions.yahoo.com/
> 
> ---------------------------------------------------------------------
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org
> 

Mime
View raw message