XSL包含3部分内容:
1.XSLT:是一种把XML转换为HTML的语言。
2.XPath:是一种定义XML节点路径的语言。
3.XSL Formatting Objects(XSL格式化对象):定义XML显示的语言。
XSLT是通过把XML的每一个元素逐个的转换为HTML元素或代码片段的方法来显示XML文档的。
在转换的同时可以对XML文档添加和删除元素、添加和删除属性、对元素进行重新排列或排序、隐藏或显示某些元素、查找或选择特定元素的操作。
XSL文档本身也是一个XML文件,XSL的根元素:<xsl:stylesheet>或<xsl:transform>
booklist.xsl 如下:
<?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 xmlns="http://www.w3.org/1999/xhtml">
<meta http_equiv="Content-Type" content="text/html; charset=UTF-8"/>
<body>
<center>
<table border="1" width="500px">
<tr>
<td>name</td>
<td>price</td>
<td>description</td>
<td>publisher</td>
</tr>
<xsl:for-each select="booklist/book">
<tr>
<td><xsl:value-of select="name"></xsl:value-of></td>
<td><xsl:value-of select="price"></xsl:value-of></td>
<td><xsl:value-of select="description"></xsl:value-of></td>
<td><xsl:value-of select="publisher"></xsl:value-of></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
booklist.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE booklist [
<!ENTITY publisher "ABC company">
]>
<?xml-stylesheet type="text/xsl" href="booklist.xsl"?>
<booklist>
<book>
<name>Ajax</name>
<price>$5.95</price>
<description>Foundations of Ajax.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>Ajax Patterns</name>
<price>$7.95</price>
<description>Introduction of Ajax Patterns.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>Ajax Web App</name>
<price>$8.95</price>
<description>Edition 2.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>Core CSS</name>
<price>$4.50</price>
<description>A book for CSS.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>JSF and Ajax</name>
<price>$6.95</price>
<description>Apress.</description>
<publisher>&publisher;</publisher>
</book>
</booklist>
运行结果:
1.XSLT:是一种把XML转换为HTML的语言。
2.XPath:是一种定义XML节点路径的语言。
3.XSL Formatting Objects(XSL格式化对象):定义XML显示的语言。
XSLT是通过把XML的每一个元素逐个的转换为HTML元素或代码片段的方法来显示XML文档的。
在转换的同时可以对XML文档添加和删除元素、添加和删除属性、对元素进行重新排列或排序、隐藏或显示某些元素、查找或选择特定元素的操作。
XSL文档本身也是一个XML文件,XSL的根元素:<xsl:stylesheet>或<xsl:transform>
booklist.xsl 如下:
<?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 xmlns="http://www.w3.org/1999/xhtml">
<meta http_equiv="Content-Type" content="text/html; charset=UTF-8"/>
<body>
<center>
<table border="1" width="500px">
<tr>
<td>name</td>
<td>price</td>
<td>description</td>
<td>publisher</td>
</tr>
<xsl:for-each select="booklist/book">
<tr>
<td><xsl:value-of select="name"></xsl:value-of></td>
<td><xsl:value-of select="price"></xsl:value-of></td>
<td><xsl:value-of select="description"></xsl:value-of></td>
<td><xsl:value-of select="publisher"></xsl:value-of></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE booklist [
<!ENTITY publisher "ABC company">
]>
<?xml-stylesheet type="text/xsl" href="booklist.xsl"?>
<booklist>
<book>
<name>Ajax</name>
<price>$5.95</price>
<description>Foundations of Ajax.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>Ajax Patterns</name>
<price>$7.95</price>
<description>Introduction of Ajax Patterns.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>Ajax Web App</name>
<price>$8.95</price>
<description>Edition 2.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>Core CSS</name>
<price>$4.50</price>
<description>A book for CSS.</description>
<publisher>&publisher;</publisher>
</book>
<book>
<name>JSF and Ajax</name>
<price>$6.95</price>
<description>Apress.</description>
<publisher>&publisher;</publisher>
</book>
</booklist>| name | price | description | publisher |
| Ajax | $5.95 | Foundations of Ajax. | ABC company |
| Ajax Patterns | $7.95 | Introduction of Ajax Patterns. | ABC company |
| Ajax Web App | $8.95 | Edition 2. | ABC company |
| Core CSS | $4.50 | A book for CSS. | ABC company |
| JSF and Ajax | $6.95 | Apress. | ABC company |
2035

被折叠的 条评论
为什么被折叠?



