在模板中指定XSL样式表

模板文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:xsl="MyXsl.xsl">
<sql:query>
    Select FirstName,LastName from Employees For XML auto
</sql:query>
</root> 
  在这里将模板文件tempxsl.xml存储在与template类型的虚拟名称(template)关联的目录中.XSL文件(MyXsl.xsl)也存储在同一目录中.MyXsl.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="*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Employees">
<tr>
<td><xsl:value-of select="@FirstName"/></td>
<td><xsl:value-of select="@LastName"/></td>
</tr>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<style>th{background-color:#cccccc}</style>
</head>
<body>
<table border="2" style="width:300;">
<tr><th colspan="2">Employees</th></tr>
<tr><th>First Name</th><th>Last Name</th></tr>
<xsl:apply-templates select="root"/>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet> 
执行模板:http://localhost/template/tempxsl.
xml


 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 您可能对 [XML] 的这些文章也感兴趣:

C#中XML的基本操作
用XSL翻译Web服务应用程序
利用XSLT把ADO记录集转换成XML
亲密接触xml(2)---XML不做任何事情
XML介绍系列(2)
XHTML基础问答
XML入门精解之文件格式定义
XSL系列函数详解
XML介绍系列(3)
也谈JSP与XML的交互