FileOutputStream fos = new FileOutputStream("D:\\MyCodes\\student.html");
Result result = new StreamResult(); Result result = new StreamResult(fos);
Result result = new StreamResult(); Result result = new StreamResult(fos);
解决方案 »
- 无任何网络提供程序接受指定的网络路径的问题
- 问大家个问题,java swing 下拉列表如何绑定数据库表的ID啊~!
- 有关static的问题
- IBM Rational Developer中关于maven管理的jar不能发布到web应用
- 数据源问题
- spring aop代理类如何获取代理对象传进来的参数,并返回一个结果
- 急!!!!!!!在线等...在struts的html:select标签中嵌套logic:iterate
- 有谁要国外的一套开源搜索引擎项目(Java)?
- httpservletrequest中的对象能使用getparameterName()方法吗?
- J2EE初级问题,关于Weblogic7.0 和 jbuilder9.0 的问题,在线等,解决马上结贴 !
- 基于SSH架构的 电子商务网站 需求分析书
- 一个Javascript和struts传值的问题.很简单.请大家帮我看看.谢谢.
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(test.class.getResourceAsStream("/customer_dtd.xml"));
// Get Template
FileInputStream fis1 = new FileInputStream("D:/customer.xsl");
Source template = new StreamSource(fis1);
FileOutputStream fos = new FileOutputStream("D:/student.html");
Result result = new StreamResult(fos);
Transformer transformer = TransformerFactory.newInstance().newTransformer(template);
transformer.transform(new DOMSource(doc), result);
fos.close();
fis1.close();
}
}
<?xml version="1.0" encoding="UTF-8"?><customers>
<customer>
<customerID>a1</customerID>
<customerName>张三</customerName>
<sex>男</sex>
<buySet customerID="a1">
<buy>
<buyName>香蕉</buyName>
<amount>100</amount>
<price>100 </price>
</buy>
</buySet>
</customer>
<customer>
<customerID>a2</customerID>
<customerName>李四</customerName>
<sex>男</sex>
<buySet customerID="a2">
<buy>
<buyName>苹果</buyName>
<amount>100</amount>
<price>100</price>
</buy>
</buySet>
</customer></customers>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"><xsl:template match="/">
<html>
<head>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<th>编号</th>
<th>姓名</th>
<th>性别</th>
</tr>
<xsl:apply-templates select="customers/customer"></xsl:apply-templates>
</tbody>
</table>
</body>
</html></xsl:template>
<xsl:template match="customers/customer">
<tr>
<td><xsl:value-of select="customerID"></xsl:value-of></td>
<td><xsl:value-of select="customerName"></xsl:value-of></td>
<td><xsl:value-of select="sex"></xsl:value-of></td>
</tr></xsl:template>
</xsl:stylesheet>
FileInputStream fis = new FileInputStream("D:\\MyCodes\\student.xml");
Source source = new StreamSource(fis);
// Get Template
FileInputStream fis1 = new FileInputStream("D:\\MyCodes\\TestTemplate.xsl");
Source template = new StreamSource(fis1);
FileOutputStream fos = new FileOutputStream("D:\\MyCodes\\student.html");
Result result = new StreamResult(fos);
Transformer transformer = TransformerFactory.newInstance().newTransformer(source);
transformer.transform(template, result);
fos.close();
fis1.close();
fis.close();<xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="D:/MyCodes/TestTemplate.xsl"?>
<customers>
<customer>
<customerID>a1</customerID>
<customerName>张三</customerName>
<sex>男</sex>
<buySet customerID="a1">
<buy>
<buyName>香蕉</buyName>
<amount>100</amount>
<price>100 </price>
</buy>
</buySet>
</customer>
<customer>
<customerID>a2</customerID>
<customerName>李四</customerName>
<sex>男</sex>
<buySet customerID="a2">
<buy>
<buyName>苹果</buyName>
<amount>100</amount>
<price>100</price>
</buy>
</buySet>
</customer></customers>
Source source = new StreamSource(fis);
// Get Template
FileInputStream fis1 = new FileInputStream("E:/temp.xsl");
Source template = new StreamSource(fis1);
Result result = new StreamResult(System.out);//注意 xslt 和 xml的该放的地方
Transformer transformer = TransformerFactory.newInstance().newTransformer(template);
transformer.transform(source, result);fis1.close();
fis.close();<?xml version="1.0" encoding="GB2312" standalone="no"?>
<!--注意这一行-->
<?xml-stylesheet type="text/xsl" href="E:/temp.xsl"?>
<root>
<student-list>
<student>
<id>1</id>
<name>张三</name>
<address>东莞市育兴路2号</address>
</student>
<student>
<id>2</id>
<name>李四</name>
<address>桂阳县欧阳海路4号</address>
</student>
</student-list>
</root>
JDK的文档中只说要传入什么类型的参数,也没提到哪个参数是模板,哪个参数是xml输入,害得我好苦