xslt 和一个demo
https://www.w3.org/1999/XSL/Transform
Specifications
The XSLT language has three versions which are distinguished by content of the version attribute:
XSL Transformations (XSLT) Version 1.0
XSL Transformations (XSLT) Version 2.0
XSL Transformations (XSLT) Version 3.0.
XSL (eXtensible Stylesheet Language) is a styling language for XML.
XSLT stands for XSL Transformations.
https://www.w3schools.com/xml/xsl_intro.asp
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource; public class Demo { public static void main(String[] args) { try { StreamSource xsltSource = new StreamSource(new FileInputStream(new File("E://my_cd_collection.xslt")));
StreamSource xmlSource = new StreamSource(new FileInputStream(new File("E://my_cd_collection.xml")));
StreamResult outputTarget = new StreamResult(new FileOutputStream(new File("E://outputtarget.html"))); TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xsltSource); transformer.transform(xmlSource, outputTarget); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>Jorn Hoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midt om natten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<COMPANY>Stax Records</COMPANY>
<PRICE>7.90</PRICE>
<YEAR>1968</YEAR>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>
my_cd_collection.xml
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
my_cd_collection.xslt
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th><th style="text-align:left">Artist</th>
</tr>
<tr>
<td>Empire Burlesque</td><td>Bob Dylan</td>
</tr>
<tr>
<td>Hide your heart</td><td>Bonnie Tyler</td>
</tr>
<tr>
<td>Greatest Hits</td><td>Dolly Parton</td>
</tr>
<tr>
<td>Still got the blues</td><td>Gary Moore</td>
</tr>
<tr>
<td>Eros</td><td>Eros Ramazzotti</td>
</tr>
<tr>
<td>One night only</td><td>Bee Gees</td>
</tr>
<tr>
<td>Sylvias Mother</td><td>Dr.Hook</td>
</tr>
<tr>
<td>Maggie May</td><td>Rod Stewart</td>
</tr>
<tr>
<td>Romanza</td><td>Andrea Bocelli</td>
</tr>
<tr>
<td>When a man loves a woman</td><td>Percy Sledge</td>
</tr>
<tr>
<td>Black angel</td><td>Savage Rose</td>
</tr>
<tr>
<td>1999 Grammy Nominees</td><td>Many</td>
</tr>
<tr>
<td>For the good times</td><td>Kenny Rogers</td>
</tr>
<tr>
<td>Big Willie style</td><td>Will Smith</td>
</tr>
<tr>
<td>Tupelo Honey</td><td>Van Morrison</td>
</tr>
<tr>
<td>Soulsville</td><td>Jorn Hoel</td>
</tr>
<tr>
<td>The very best of</td><td>Cat Stevens</td>
</tr>
<tr>
<td>Stop</td><td>Sam Brown</td>
</tr>
<tr>
<td>Bridge of Spies</td><td>T`Pau</td>
</tr>
<tr>
<td>Private Dancer</td><td>Tina Turner</td>
</tr>
<tr>
<td>Midt om natten</td><td>Kim Larsen</td>
</tr>
<tr>
<td>Pavarotti Gala Concert</td><td>Luciano Pavarotti</td>
</tr>
<tr>
<td>The dock of the bay</td><td>Otis Redding</td>
</tr>
<tr>
<td>Picture book</td><td>Simply Red</td>
</tr>
<tr>
<td>Red</td><td>The Communards</td>
</tr>
<tr>
<td>Unchain my heart</td><td>Joe Cocker</td>
</tr>
</table>
</body>
</html>
outputtarget.htlm

xslt 和一个demo的更多相关文章
- angular开发者吐槽react+redux的复杂:“一个demo证明你的开发效率低下”
曾经看到一篇文章,写的是jquery开发者吐槽angular的复杂.作为一个angular开发者,我来吐槽一下react+redux的复杂. 例子 为了让大家看得舒服,我用最简单的一个demo来展示r ...
- 初识nginx之第一个demo
商城项目做了一个多月了,想到必须用到负载均衡,简单了解了一下nginx,首先分享第一个demo,五月份上线后,会继续分享一系列相关知识. 在nginx根目录下,用了一个园友的批处理文件nginx.ba ...
- springMvc的第一个demo
1.下载jar包 http://repo.spring.io/libs-release-local/org/springframework/spring/4.2.3.RELEASE/ 2.下载源码 j ...
- Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)
在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...
- 如何在WTL和MFC中使用duilib及如何静态使用duilib库!(初级讲解 附带一个Demo)
关于duilib的历史,我也就不多说了,能看到这篇文章的人都是有一定了解才能找到这个的. 我直接说下对这个库的基本使用吧. 我个人对一些好技术都是比较感兴趣的. 因为个人原因 喜欢接触一个好技术. 所 ...
- 白盒测试之gtest第一个demo
认识gtest工具后,关于它的使用,下面将用一个demo程序演示一下gtest的用法以及成果展示. 一.需要测试的C++代码: #include "myfunction.h" // ...
- 在VS中实现webService的一个demo(图解)
在VS中实现webService的一个demo(图解) 先创建一个web项目,创建好web项目后,添加新建项——web服务 在新建好的web服务文件中写如下代码: 生成当前解决方案. 新建一个winf ...
- Cocos2d-x 学习(1)—— 通过Cocos Studio创建第一个Demo
近期在工作上有了比較大的转变,自学情绪也慢慢高涨,本来一直在研究unity的技术.由于换了工作会開始接触cocos2d-x.但并不意味着停止研究unity,以后有时间还是会继续的. 公司的cocos2 ...
- 使用android的mediaplayer做成 一个demo,欢迎测试使用
附件是为一个定制视频产品而简单的写了一个demo,用来说明android的mediaplayer是如何使用的. http://files.cnblogs.com/guobaPlayer/palyerD ...
随机推荐
- materia官网地址
https://materializecss.com/autocomplete.html
- DirectX中坐标系问题
自己属于笨类型,以前总是记不住directx坐标系是怎样的,今天在网上看到一篇文章,借鉴过来. 1. 明确DirectX是左手坐标系. 描述如下:1. 伸出左手,手面朝上,手背朝下,握住z轴,大拇指方 ...
- js函数定义和调用
由于JavaScript的函数也是一个对象,上述定义的abs()函数实际上是一个函数对象,而函数名abs可以视为指向该函数的变量. var abs = function (x) { if (x > ...
- C#编译时,提示缺少NuGet包
A--还原Nuget包前,一定要确保你配置了该项目的包源:如果你没有那就找别人要吧. 工具-选项-Nuget包管理器-程序包源 B--配置编译时自动还原缺少的nuget包: 工具-选项-Nuget包管 ...
- poj_1979(dfs)
Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either re ...
- Android.PublishApplication
发布应用 3. 为App签名 Android 要求App在安装前,需要使用证书(certificate)来进行数字签名(be digitally signed). Android 用证书来标识一个Ap ...
- 洛谷4054 [JSOI2009]计数问题
原题链接 二维树状数组模板题. 对每一种颜色开一棵二维树状数组统计即可. #include<cstdio> using namespace std; const int N = 310; ...
- 20172306 《Java程序设计与数据结构》第七周学习总结
20172306<Java程序设计>第七周学习总结 教材学习内容总结 这一章的标题是继承.主要学习了有关继承的相关知识.其中在这五节中,我学到了以下几点: 1.继承主要表达的是" ...
- 01. pt-align
01. pt-align pt-align xxx.txt =========================================== pt-align对齐输出格式 name city a ...
- python httplib2应用get post
import httplib2,time #装饰器方法,用于记录方法消耗时间 #推荐将print 改成log def timer(func): def _warpper(self,*argv) ...