图书信息xml文件:
book.xml
XSL文件:
book.xsl
可以在IE,FF等下查看book.xml
火狐下那个<?xsl:output method="html" />不能少
< th >作者: </ th > < td > < xsl:value-of select ="author" /> </ td >
</ tr >
< tr >
< th >定价: </ th > < td > < xsl:value-of select ="price" /> </ td >
</ tr >
</ table >
</ xsl:for-each >
</ xsl:template >
</ xsl:transform >
结果
book.xml
<?
xml
version
="1.0"
encoding
="UTF-8"
?>
<? xml-stylesheet type ="text/xsl" href ="book.xsl" ?>
< books bookstore ="威海新华书店" >
< book >
< author >张三 </ author >
< title >草原上的牛羊 </ title >
< price >18.9 </ price >
</ book >
< book >
< author >李四 </ author >
< title >大清王朝 </ title >
< price >41.0 </ price >
</ book >
< book >
< author >王五 </ author >
< title >比窦娥还冤 </ title >
< price >38.9 </ price >
</ book >
< book >
< author >赵六 </ author >
< title >戊戌变法 </ title >
< price >17.8 </ price >
</ book >
< book >
< author >王麻子 </ author >
< title >磨刀不误砍柴 </ title >
< price >36.5 </ price >
</ book >
< book >
< author >海大少 </ author >
< title >古人 </ title >
< price >27 </ price >
</ book >
</ books >
<? xml-stylesheet type ="text/xsl" href ="book.xsl" ?>
< books bookstore ="威海新华书店" >
< book >
< author >张三 </ author >
< title >草原上的牛羊 </ title >
< price >18.9 </ price >
</ book >
< book >
< author >李四 </ author >
< title >大清王朝 </ title >
< price >41.0 </ price >
</ book >
< book >
< author >王五 </ author >
< title >比窦娥还冤 </ title >
< price >38.9 </ price >
</ book >
< book >
< author >赵六 </ author >
< title >戊戌变法 </ title >
< price >17.8 </ price >
</ book >
< book >
< author >王麻子 </ author >
< title >磨刀不误砍柴 </ title >
< price >36.5 </ price >
</ book >
< book >
< author >海大少 </ author >
< title >古人 </ title >
< price >27 </ price >
</ book >
</ books >
XSL文件:
book.xsl
<?
xml
version
="1.0"
encoding
="utf-8"
?>
< xsl:transform version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:template match ="/books" >
< html >
< head >
< title >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ title >
</ head >
< body >
< h1 >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ h1 >
< xsl:apply-templates />
</ body >
</ html >
</ xsl:template >
< xsl:template match ="/books" >
< xsl:for-each select ="book" >
< table border ="1" >
< tr >
< th >书名: </ th > < td > < xsl:value-of select ="title" /> </ td >
</ tr >
< tr >
< th >作者: </ th > < td > < xsl:value-of select ="author" /> </ td >
</ tr >
< tr >
< th >定价: </ th > < td > < xsl:value-of select ="price" /> </ td >
</ tr >
</ table >
</ xsl:for-each >
</ xsl:template >
</ xsl:transform >
< xsl:transform version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:template match ="/books" >
< html >
< head >
< title >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ title >
</ head >
< body >
< h1 >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ h1 >
< xsl:apply-templates />
</ body >
</ html >
</ xsl:template >
< xsl:template match ="/books" >
< xsl:for-each select ="book" >
< table border ="1" >
< tr >
< th >书名: </ th > < td > < xsl:value-of select ="title" /> </ td >
</ tr >
< tr >
< th >作者: </ th > < td > < xsl:value-of select ="author" /> </ td >
</ tr >
< tr >
< th >定价: </ th > < td > < xsl:value-of select ="price" /> </ td >
</ tr >
</ table >
</ xsl:for-each >
</ xsl:template >
</ xsl:transform >
可以在IE,FF等下查看book.xml
火狐下那个<?xsl:output method="html" />不能少
<?
xml
version
="1.0"
encoding
="utf-8"
?>
< xsl:transform version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:output method ="html" />
< xsl:template match ="/books" >
< html >
< head >
< title >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ title >
</ head >
< body >
< h1 >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ h1 >
< xsl:apply-templates />
</ body >
</ html >
</ xsl:template >
< xsl:template match ="/books" >
< xsl:for-each select ="book" >
< table border ="1" >
< tr >
< th >书名: </ th > < td > < xsl:value-of select ="title" /> </ td >
</ tr >
< tr >
< xsl:transform version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:output method ="html" />
< xsl:template match ="/books" >
< html >
< head >
< title >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ title >
</ head >
< body >
< h1 >
< xsl:value-of select ="@bookstore" />的最新图书相关信息
</ h1 >
< xsl:apply-templates />
</ body >
</ html >
</ xsl:template >
< xsl:template match ="/books" >
< xsl:for-each select ="book" >
< table border ="1" >
< tr >
< th >书名: </ th > < td > < xsl:value-of select ="title" /> </ td >
</ tr >
< tr >
< th >作者: </ th > < td > < xsl:value-of select ="author" /> </ td >
</ tr >
< tr >
< th >定价: </ th > < td > < xsl:value-of select ="price" /> </ td >
</ tr >
</ table >
</ xsl:for-each >
</ xsl:template >
</ xsl:transform >
结果
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/121663,如需转载请自行联系原作者