这被称为数据和显示式分离,这非常好,当我们想要改变风,主要换一个XSL就行了,并不需要重新添加一份数据。 但是有的时候也是有特例的,比如我们就有这个奇怪的需求—将XML/XSL写到一个文件。百度后,没有结果;忽然灵机一动,不是有一个很热门的问答网站
这被称为数据和显示格式分离,这非常好,当我们想要改变风格,主要换一个XSL就行了,并不需要重新添加一份数据。
但是有的时候也是有特例的,比如我们就有这个奇怪的需求—将XML/XSL写到一个文件。百度后,没有结果;忽然灵机一动,不是有一个很热门的问答网站(stackoverflow)吗!
我就去搜索了一下,果然有个仁兄给出了一个很NICE的答案。我先列出来,后面有时间写个自己修改后的版本。
地址:http://stackoverflow.com/questions/9523174/embed-xsl-in-xml-for-display-in-web-browser-what-am-i-doing-wrong/9530410
<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="#stylesheet"?><!DOCTYPE doc []> <!---ecms -ecms Start XSL--> <!---ecms -ecms Variables--> <!---ecms -ecms End Variables--> <style> h2{ font-family: Courier, Courier New, monospace; font-size: 32px; text-decoration: underline; } body{ font-family: Courier New, monospace; } p{ font-size: 16px; } table{ font-size: 14px; } .title{ text-align:left; } .release{ text-align:center; } .seen{ text-align:center; } .rating{ text-align:right; } .length{ text-align:center; } </style> <body> <h2>My Movie List</h2> <p>Movies seen so far: / = <br /> Movies yet to see: / = <br /> Movies seen prior to making list: / = <br /> Total time watched: days, hours, minutes<br /> Average rating: stars out of 5</p> <br /> <table border="1"> <tr> <th>#</th> <th>Title</th> <th>Release Date</th> <th>Length</th> <th>Seen</th> <th>Rating</th> </tr> <tr style="background-color:#666;color:#fff"> <td> </td> <td class="title"></td> <td class="release"></td> <td class="length"> minutes</td> <td class="seen"></td> <td class="rating"></td> </tr> <tr style="background-color:#999;color:#000"> <td> </td> <td class="title"></td> <td class="release"></td> <td class="length"> minutes<mark style="color:transparent">来4源gaodaimacom搞#代%码*网</mark></td> <td class="seen"></td> <td class="rating"></td> </tr> <tr style="background-color:#fff"> <td> </td> <td class="title"></td> <td class="release"></td> <td class="length"> minutes</td> <td class="seen"></td> <td class="rating"></td> </tr> </table> <!---ecms -ecms Start XML--> <title>2001: A Space Odyssey</title> 1968 No N/A 141 <title>28 Days Later</title> 2002 No N/A 113 <title>28 Weeks Later</title> 2007 No N/A 100 <title>A Clockwork Orange</title> 1971 Yes ☆☆☆★★ 136 <!---ecms -ecms Rest of XML-->