xslt 通过springmvc、js转换的方式

阅读更多
--》待翻译的xml文件内容


	
		Z345T
		Cheryl
		Johnson
		Manager
		12000
	
	
		Z446T
		John
		Smith
		Employee
		1000
	
	
		Z335T
		Justin
		Claire
		Senior Manager
		14000
	
	
		Z389T
		Clark
		Rick
		Employee
		2000
	

--》xslt文件内容


	
	
		
			
				

--》springmvc controller代码
package net.codejava.spring.controller;

//参考http://www.codejava.net/frameworks/spring/spring-mvc-xstlview-and-xsltviewresolver-example
import java.io.File;
import java.io.IOException;
import java.io.StringReader;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HomeController {
	@RequestMapping(value = "/")
	public ModelAndView goHome(HttpServletResponse response) throws IOException {
		return new ModelAndView("home");
	}

	@RequestMapping(value = "/viewXSLT")
	public ModelAndView viewXSLT(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
/*		//从xml文件翻译
		String xmlFile = "resources/citizens.xml";
		String contextPath = request.getSession().getServletContext().getRealPath("");
		String xmlFilePath = contextPath + File.separator + "WEB-INF" + File.separator + xmlFile;
		Source source = new StreamSource(new File(xmlFilePath));*/
		//从xml字符串翻译
		String xmlStr = "			Z345T		Cheryl		Johnson		Manager		12000				Z446T		John		Smith		Employee		1000				Z335T		Justin		Claire		Senior Manager		14000				Z389T		Clark		Rick		Employee		2000	";
		Source source = new StreamSource(new StringReader(xmlStr));
		// adds the XML source file to the model so the XsltView can detect
		ModelAndView model = new ModelAndView("XSLTView");
		model.addObject("xmlSource", source);
		return model;
	}
}

--》spring mvc配置文件


	
	
	
	
	
	
		
		
		
		
			
				XSLTView
			
		
		
		
	
	
		
		
		
	

--》xslt配置文件
XSLTView.(class)=org.springframework.web.servlet.view.xslt.XsltView
XSLTView.sourceKey=xmlSource 
XSLTView.url=/WEB-INF/xsl/XSLTView.xsl


--->xslt_client2.jsp xslt_client.jsp 为客户端转换处理方法

---》参考
http://www.codejava.net/frameworks/spring/spring-mvc-xstlview-and-xsltviewresolver-example
http://tech.it168.com/KnowledgeBase/Articles/8/6/a/86a8266e3eeb9654020fbd3d03545c78.htm
  • springmvcXsltTest.rar (4 MB)
  • 下载次数: 9

你可能感兴趣的:(xsl,mvc,spring)