天生舞男

我喜欢谦虚的学习各种...,希望自己能坚持一辈子,因为即使一张卫生巾也是有它的作用.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

简单的XSLT与简单的xml

Posted on 2005-09-11 00:10  天生舞男  阅读(283)  评论(0编辑  收藏  举报
simple.xml:

<?xml version="1.0" encoding="gb2312" ?>
<?xml:stylesheet type="text/xsl" href="simple.xsl" ?>
<早餐菜单>
<食物>
<名称>Belgian Waffles</名称>
<价格>$5.95</价格>
<描述>two of our famous Belgian Waffles with plenty of real maple syrup</描述>
<卡路里>650</卡路里>
</食物>
<食物>
<名称>Strawberry Belgian Waffles</名称>
<价格>$7.95</价格>
<描述>light Belgian waffles coverred with strawberrys and whipped cream</描述>
<卡路里>900</卡路里>
</食物>
<食物>
<名称>Berry-Berry Belgian Waffles</名称>
<价格>$8.95</价格>
<描述>light Belgian waffles coverred with an assortment of fresh berries and whipped cream</描述>
<卡路里>900</卡路里>
</食物>
<食物>
<名称>French Toast</名称>
<价格>$4.50</价格>
<描述>thick slices made from our homemade sourdough bread</描述>
<卡路里>600</卡路里>
</食物>
<食物>
<名称>Homestyle Breakfast</名称>
<价格>$6.95</价格>
<描述>two eggs, bacon or sausage, toast, and our ever-popular hash browns</描述>
<卡路里>950</卡路里>
</食物>
</早餐菜单>

simple.xsl:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<BODY STYLE="font-family:宋体; font-size:12pt;
background-color:#EEEEEE">
<xsl:for-each select="早餐菜单/食物">
<DIV STYLE="background-color:teal; color:white; padding:4px">
<SPAN STYLE="font-weight:bold; color:white"><xsl:value-of select="名称"/></SPAN>
- <xsl:value-of select="价格"/>
</DIV>
<DIV STYLE="margin-left:20px; margin-bottom:1em; font-size:10pt">
<xsl:value-of select="描述"/>
<SPAN STYLE="font-style:italic">
(<xsl:value-of select="卡路里" />卡路里/份)
</SPAN>
</DIV>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>