请问高手们一个关于Servlet和xml的一个问题!!!~~~~~

hao1242 2007-04-11 11:53:25
现在我有一个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,请高手们多多指点!!!~~~~
...全文
200 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
nihao1242 2007-04-12
  • 打赏
  • 举报
回复
加油吧!!!~
PaulDeng198212 2007-04-11
  • 打赏
  • 举报
回复
???
HH 2007-04-11
  • 打赏
  • 举报
回复
相当复杂了
很难理解
刚学习的 所以无能为力

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧