请问高手们一个关于Servlet和xml的一个问题!!!~~~~~
现在我有一个xml
aaa.xml
<?xml version= "1.0 " encoding= "UTF-8 "?>
<?xml-stylesheet type= "text/xsl " href= "DeviceGroup.xsl "?>
<languages>
<language> zh_CN.xml </language>
</languages>
zh_CN.xml
<?xml version= "1.0 " encoding= "UTF-8 "?>
<root>
<table> 你好 </table>
</root>
en_US.xml
<?xml version= "1.0 " encoding= "UTF-8 "?>
<root>
<table> hello </table>
</root>
bbb.xsl
<?xml version= "1.0 " encoding= "UTF-8 "?>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:output method= "xml " version= "1.0 " encoding= "UTF-8 " indent= "yes "/>
<xsl:template match= "/ ">
<groups>
<xsl:apply-templates select= "/root/table "/>
</groups>
</xsl:template>
<xsl:template match= "root/table ">
<table border= "2 ">
<tr>
<td> <xsl:copy-of select= "document(.)//table "/> </td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
还有一个Servlet当中的doGet方法
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException,
java.net.MalformedURLException {
try {
response.setContentType( "text/html; charset=UTF-8 ");
PrintWriter out = response.getWriter();
Locale clocale = request.getLocale();
StringWriter resultStringWriter = new StringWriter();
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
processor.setStylesheetParam( "lpfile ", "clocale ");
String xml_doc = "E:/test/aaa.xml ";
String stylesheet = "E:/test/bbb.xsl "; processor.process(new XSLTInputSource(xml_doc),new XSLTInputSource(stylesheet), new XSLTResultTarget(resultStringWriter));
out.write(resultStringWriter.toString());
out.close();
} catch (SAXException e) {
e.printStackTrace();
}
}
我想把aaa.xml当中的zh_CN.xml在Servlet当中定义成一个变量,通过Servlet转换aaa.xml和bbb.xsl来显示不同的页面,如果用户本机语言为中文那么aaa.xml中的
<table> 节点中的值为zh_CN.xml,如果用户本机语言为英文的话,aaa.xml中的 <table> 节点中的值为en_US.xml,那么在aaa.xml中的 <table> 节点中的这个变量在Servlet就如何定义????初学xml,请高手们多多指点!!!~~~~
------解决方案--------------------
上面说的很对!!!~~~