XSL是指XML的表现形式,相当于html的css
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="company_stylesheet_xsl.xsl"?>
<company>
<companyname>公司名称</companyname>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
<deparment>
<name>张三</name>
<age>10</age>
<rank>暂时</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">more</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>天天</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>一星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment><deparment>
<name>张三</name>
<age>10</age>
<rank>二星</rank>
<salary>10000</salary>
<description href="http://www.gogole.com">知道更多...</description>
</deparment>
</company>
<?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>
<head>
<title>使用xsl对xml进行样式格式化</title>
</head>
<body>
<xsl:apply-templates select="company"/> <!--从根目录标签-->
</body>
</html>
</xsl:template>
<xsl:template match="company">
<table>
<tr>
<td>姓名</td>
<td>年龄</td>
<td>等级</td>
<td>工资</td>
<td>描述</td>
</tr>
<xsl:for-each select="deparment">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="rank"/></td>
<td><xsl:value-of select="salary"/></td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="description/@href"/>
</xsl:attribute>
<xsl:value-of select="description"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
<?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> <head> <title>使用xsl对xml进行样式格式化</title> </head> <body> <xsl:apply-templates select="company"/> <!--从根目录标签--> </body> </html> </xsl:template> <xsl:template match="company"> <table> <tr> <td>姓名</td> <td>年龄</td> <td>等级</td> <td>工资</td> <td>描述</td> </tr> <xsl:for-each select="deparment"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="age"/></td> <td><xsl:value-of select="rank"/></td> <td><xsl:value-of select="salary"/></td> <td> <a> <xsl:attribute name="href"> <xsl:value-of select="description/@href"/> </xsl:attribute> <xsl:value-of select="description"/> </a> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>