原XML XMLFile.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>然后用XSLT解析上面的XML cdcatalog.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<h2>My CD Collection</h2>
<table border="0">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th 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>
</xsl:template>
</xsl:stylesheet>
然后在原XML中引用XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>然后在浏览器中浏览结果
My CD Collection
Title Artist
Empire Burlesque Bob Dylan现在我想把XML转换成HTML,然后可以插入到模板页HTML中,可编译不知道如何转换成HTML代码?<xsl:output method="html" />处理器输出HTML代码,不知道在哪输出的?哪位大虾帮帮忙!
<?xml version="1.0" encoding="iso-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>然后用XSLT解析上面的XML cdcatalog.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<h2>My CD Collection</h2>
<table border="0">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th 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>
</xsl:template>
</xsl:stylesheet>
然后在原XML中引用XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>然后在浏览器中浏览结果
My CD Collection
Title Artist
Empire Burlesque Bob Dylan现在我想把XML转换成HTML,然后可以插入到模板页HTML中,可编译不知道如何转换成HTML代码?<xsl:output method="html" />处理器输出HTML代码,不知道在哪输出的?哪位大虾帮帮忙!
解决方案 »
- 微软的ASP.NET中的MVC架构跟JAVA中的MVC架构有什么区别?
- 数据插入问题?????
- 谁能帮我解析下这段斐波那契代码,第一次输出为什么 fib=0?
- asp.net 2.0 如何在web.config里配置 ACCESS连接? 我是新手
- VS2010无法调试网站了,出现ASP.NET Development Server用法的对话框
- 为什么会提示ConnectionString尚未初始化?感觉代码没写错啊!!!
- dropdownlist 的点击事件
- 老大们如何在啊asp.net中实现时钟的动态显示?
- 菜鸟问: .net 技术是不是主要用来开发网站的?
- 自定义实体(强类型)将会贯穿整个业务层 不是最好的 --- 我的面试经历
- 求助Asp.net(基于c#)连接局域网内oracle数据库问题
- DataSet 转换问题
{
string rootPath = GetRootPath();
//取得xml路径
string xmlPath = "/xml/XMLFile.xml";
xmlPath = xmlPath.Replace("/", "\\");
xmlPath = rootPath.Trim() + xmlPath;
//取得xsl路径
string xslPath = "/xml/cdcatalog.xsl";
xslPath = xslPath.Replace("/", "\\");
xslPath = rootPath.Trim() + xslPath;
//设置html的保存路径
string htmlPath = "/xml/HTMLFile.html";
htmlPath = htmlPath.Replace("/", "\\");
htmlPath = rootPath.Trim() + htmlPath; //将XML转换成HTML
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xslPath);
transform.Transform(xmlPath, htmlPath);
//Response.Write(htmlPath);
}
{
string rootPath = GetRootPath();
//取得xml路径
string xmlPath = "/xml/XMLFile.xml";
xmlPath = xmlPath.Replace("/", "\\");
xmlPath = rootPath.Trim() + xmlPath;
//取得xsl路径
string xslPath = "/xml/cdcatalog.xsl";
xslPath = xslPath.Replace("/", "\\");
xslPath = rootPath.Trim() + xslPath;
//设置html的保存路径
string htmlPath = "/xml/HTMLFile.html";
htmlPath = htmlPath.Replace("/", "\\");
htmlPath = rootPath.Trim() + htmlPath; //将XML转换成HTML
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xslPath);
transform.Transform(xmlPath, htmlPath);
//Response.Write(htmlPath);
}