怎样把xml显示出来?用xsl来规定显示格式。(25分)

  • 主题发起人 主题发起人 zlmark
  • 开始时间 开始时间
Z

zlmark

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样把xml显示出来?用xsl来规定显示格式。请举出一个具体的例子,比如应该写什么代码?
 
本论坛就是, ASP + xslt
 
其实,例子是很多的,最重要的是看书了,书上有很多这方面的例子
 
i have a simple use php
//create a xml file
<?php require('../dbconnect.php');
if(empty($page))
{$page=1;
}
if(empty($order))
{$order='hot';
}
if(empty($sortid))
{$order='1';
}
$startrecord=($page-1)*12;
switch($order)
{
case 'hot':
$querystring="select * from urlstable order by click desc LIMIT $startrecord,12";
break;
case 'new':
$querystring="select * from urlstable order by getday desc LIMIT $startrecord,12";
break;
case 'sort':
$querystring="select * from urlstable where sort=$sortid order by click desc LIMIT $startrecord,12";
break;
default :
$querystring="select * from urlstable order by click desc LIMIT $startrecord,12";
break;
}
$result=mysql_query($querystring,$db);

echo '<?xml version="1.0" encoding="gb2312"?>';
echo '<?xml-stylesheet type="text/xsl" href="sitelist.xsl"?>';
echo '<URL>';
while ($data=mysql_fetch_array($result))
{ echo '<WEBSITE ID="'.$data["id"].'">';
echo '<NAME>'.$data["name"].'</NAME>';
echo '<LINK>'.$data["link"].'</LINK>';
echo '<CLICK>'.$data["click"].'</CLICK>';
echo '<DATE>'.$data["getday"].'</DATE>';
echo '<BRIEF>'.$data["brief"].'</BRIEF>';
echo '</WEBSITE>';
}
echo '</URL>';
?>
//create xsl file
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title>&amp;#65421;?&amp;#65406;&amp;#65431;&amp;#65418;&amp;#65409;&amp;#65423;</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312" />
<link rel="stylesheet" href="../1292.css" type="text/css" />
</head>
<body>
<p align="center"><font size="3">&amp;#65421;?&amp;#65406;&amp;#65431;&amp;#65418;&amp;#65409;&amp;#65423;</font></p>
<table width="90%" border="0" cellspacing="1" bgcolor="#000000" align="center">
<tr>
<td bgcolor="#FFFFFF" valign="top" >
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr bgcolor="#CCCCCC">
<td height="20" align="right">
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="30%">&amp;#65411;﨤&amp;#65414;</td>
<td width="16%">&amp;#65397;羹?&amp;#65418;</td>
<td width="54%">&amp;#65404;?&amp;#12539;/td>
</tr>
<xsl:for-each select="URL/*">
<tr>
<td width="30%">
<a><xsl:attribute name="href">go.php?id=<xsl:value-of select="@ID"/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute><xsl:value-of select="NAME"/></a>
</td>
<td width="16%"><xsl:value-of select="CLICK"/></td>
<td width="54%"><xsl:value-of select="BRIEF"/></td>
</tr>
</xsl:for-each>
</table>
</td>
</tr>
</table>
<p align="center"> <a href="#" onclick="window.close()">&amp;#65401;&amp;#65432;&amp;#65393;&amp;#65429;&amp;#65393;&amp;#65406;&amp;#65396;&amp;#65392;&amp;#65407;&amp;#65434;</a> </p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
xml:<name>cjbjb</name>
xls:
<?xml version='1.0' encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
</head>
<body bgcolor="white">
<xsl: select="name">
<h4><xsl:value-of select="@name"/></h4>
</xsl>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
大概是这样,找本书看看吧。
 
see
http://202.98.64.85/~just/url/sitelist.xml.php
 
mywrong.xml
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/css" href="mywrong.txt"?>
<mywrong>
<reason>有人说我的文章废话连篇</reason>
<question>我真的是废话连篇,罗里罗唆么?</question>
<think>我是不是应该考虑以严谨的,充满学究味道的写作风格继续进行创作?</think>
<request>如果你对我的教程有意见,请一定写信给我Jsper@371.net</request>
</mywrong>
myrong.txt
mywrong
{
background-color: #ffffff;
width: 100%;
}
reason
{
font-family : "宋体";
font-size : 22pt;
display: block;
margin-bottom: 10pt;
margin-left: 20;
}
question
{
font-family : "宋体";
font-size : 9pt;
color: red;
}
think
{
font-family : "宋体";
font-size : 9pt;
Display: block;
margin-bottom: 10pt;
color: green;
}
request
{
font-family : "宋体";
font-size :9pt;
Display: block;
color: yellow;
margin-left: 20pt;
}
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
744
DelphiTeacher的专栏
D
D
回复
0
查看
718
DelphiTeacher的专栏
D
D
回复
0
查看
672
DelphiTeacher的专栏
D
后退
顶部