以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XSL/XSLT/XSL-FO/CSS 』 (http://bbs.xml.org.cn/list.asp?boardid=8) ---- 基于XML网站的三层XSL架构(争做版主大放血) (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=50457) |
-- 作者:hexun831012 -- 发布时间:7/24/2007 4:25:00 PM -- 基于XML网站的三层XSL架构(争做版主大放血) 由于XSL可以在客户端浏览器进行转换,这就使数据与样式分离,胖客户端结构成为可能,未来的网站就是一个XML数据提供者(Web Service),而客户端是一个阅读工具,这种模式就是现在RSS的设计模式。 很多人发现通过XSL单独转换一个XML是很容易的,但是如果想通过XSL把XML有机的组合成一个网站就非常难,我现在来介绍一下我的网站的三层XSL架构: 表示层:Page(自定义表示层) 中间层:UI(CSS, Javascript...) 核心层:Sitemap(网站物理描述) 首先看核心层,Sitemap的功能主要是描述网站的物理结构和文件结构,他支持递归嵌套,这就为完整的描述网站的物理结构和文件结构提供了可能,Sitemap在网页上足要体现为菜单,他又一个树形目录表示。 中间层就是UI层,通过统一的UI层,网站的各个表示层将拥有统一的外观,就像ASP.NET中的MasterPage一样,甚至比他还要易用,有了统一的UI层,对于网站UI的维护将显得尤为简单,而且我们将CSS和Javascript嵌入其中,他将作用于整个网站。 表示层就是我们通常写的XSL转换,所不同的是我们将底下两层的XSL导入,你会发现原来的效果发生巨大的变化,它变成的网站的一个部分,其实只要导入底下两层的XSL,你可以任意扩张你的表示层,他的灵活和扩展性极佳。 以下是我的网站三层XSL架构的代码,攻大家参考: sitemap.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="http://www.hexsoft.org/sitemap.xsd"> <xsl:output method="html" indent="no" omit-xml-declaration="yes"/> <xsl:template match="map:sitemap"> <div class="map"> <xsl:apply-templates select="map:map | map:maps"/> </div> </xsl:template> <xsl:template match="map:map"> <img src="/image/rss.png"/> <a href="{@link}"> <xsl:value-of select="@title"/> </a> <br/> </xsl:template> <xsl:template match="map:maps"> <b> <xsl:value-of select="@title"/> </b> <div> <xsl:apply-templates select="map:map | map:maps"/> </div> </xsl:template> </xsl:stylesheet> html.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="http://www.hexsoft.org/sitemap.xsd"> <xsl:import href="sitemap.xsl"/> <xsl:param name="title"/> <xsl:template match="/"> <html version="1.0" xmlns="http://www.w3.org/1999/xhtml"> <head> <title> <xsl:value-of select="$title"/> </title> <link type="text/css" href="/style.css" rel="stylesheet"/> <script type="text/javascript" src="/script.js"></script> </head> <body> <table> <tr> <td> <a href="/"> <img src="logo.png"/> </a> </td> </tr> </table> <table> <tr> <td> <xsl:apply-templates select="document('sitemap.xml')/map:sitemap"/> </td> <td class="bodyRight"> <xsl:apply-templates/> </td> </tr> </table> <table> <tr> <td class="bodyBottom">Copyright</td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet> page.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:htm="http://www.hexsoft.org/page.xsd"> <xsl:import href="html.xsl"/> <xsl:param name="title" select="htm:page/htm:title[1]"/> <xsl:template match="htm:page"> <div class="page"> <xsl:apply-templates select="htm:image | htm:list | htm:paragraph | htm:subtitle | htm:table | htm:title"/> </div> </xsl:template> <xsl:template match="htm:cell"> <td> <xsl:value-of select="."/> </td> </xsl:template> <xsl:template match="htm:head"> <th> <xsl:value-of select="."/> </th> </xsl:template> <xsl:template match="htm:image"> <div class="pageP"> <img src="{.}"/> </div> </xsl:template> <xsl:template match="htm:item"> <li> <xsl:value-of select="."/> </li> </xsl:template> <xsl:template match="htm:list"> <ul> <xsl:apply-templates select="htm:item | htm:list"/> </ul> </xsl:template> <xsl:template match="htm:paragraph"> <p> <xsl:value-of select="." disable-output-escaping="yes"/> </p> </xsl:template> <xsl:template match="htm:row"> <tr> <xsl:apply-templates select="htm:cell | htm:head"/> </tr> </xsl:template> <xsl:template match="htm:subtitle"> <h4> <xsl:value-of select="."/> </h4> </xsl:template> <xsl:template match="htm:table"> <table> <xsl:apply-templates select="htm:row"/> </table> </xsl:template> <xsl:template match="htm:title"> <h2> <xsl:value-of select="."/> </h2> </xsl:template> </xsl:stylesheet>
|
-- 作者:hexun831012 -- 发布时间:7/24/2007 4:54:00 PM -- 申请精华,争做版主 |
-- 作者:luypmp -- 发布时间:7/24/2007 10:25:00 PM -- hexun831012 ,这些都是你的原创吗? |
-- 作者:hexun831012 -- 发布时间:7/25/2007 11:14:00 AM -- 是啊,有什么不对吗 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
62.500ms |