XSLT transform
来源:互联网 发布:为什么老是80端口占用 编辑:程序博客网 时间:2024/06/07 01:40
转自:http://www.abc188.com/info/html/chengxusheji/Javajishu/20080226/49904_2.html
public static void main(String[] args) throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
Source xmlSource = new StreamSource(new File(args[0]));
Source xlsSource = new StreamSource(new File(args[1]));
Transformer transformer = factory.newTransformer(xlsSource);
transformer.transform(xmlSource, new StreamResult(new File(args[3])));
}
}
sample xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html" version="1.0" encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent="yes"/>
<xsl:template match="/Element">
<xsl:variable name="briefDescription" select="attribute[@name='briefDescription']"/>
<html>
<head>
<title>test</title>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<xsl:value-of disable-output-escaping="no" select="$briefDescription"/>
</td>
</tr>
<tr>
<td valign="top">
<xsl:value-of disable-output-escaping="yes" select="$briefDescription"/>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
sample xml:
<?xml version="1.0" encoding="UTF-8"?>
<Element testChar="extensionBextensionB