静态网页调用XML解决办法
静态网页调用XML
topNews.xml文件代码如下:
<?xml version= "1.0 " encoding= "gb2312 " ?>
- <topnews>
- <news>
<newsid> 1273 </newsid>
<title> 新闻一 </title>
<time> 2007-5-28 9:43:00 </time>
</news>
- <news>
<newsid> 1272 </newsid>
<title> 新闻二 </title>
<time> 2007-5-28 9:38:00 </time>
</news>
- <news>
<newsid> 1271 </newsid>
<title> 新闻三 </title>
<time> 2007-5-17 19:50:00 </time>
</news>
</topnews>
请问如何在 index.html 中调用这些数据,显示的时候是这样的格式:
2007-5-17
新闻一 <标题有链接,地址为: shownews.asp?id=newsid>
2007-5-28
新闻二 <标题有链接,地址为: shownews.asp?id=newsid>
2007-5-28
新闻三 <标题有链接,地址为: shownews.asp?id=newsid>
求index.html代码.最好是Javascript写的.谢谢!
------解决方案--------------------
tino.xml
<?xml version= "1.0 " encoding= "UTF-8 "?>
<?xml-stylesheet type= "text/xsl " href= "tino.xsl "?>
<topnews>
<news>
<newsid> 1273 </newsid>
<title> 新闻一 </title>
<time> 2007-5-28 9:43:00 </time>
</news>
<news>
<newsid> 1272 </newsid>
<title> 新闻二 </title>
<time> 2007-5-28 9:38:00 </time>
</news>
<news>
<newsid> 1271 </newsid>
<title> 新闻三 </title>
<time> 2007-5-17 19:50:00 </time>
</news>
</topnews>
tino.xsl
<?xml version= "1.0 " encoding= "utf-8 "?>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " xmlns:fo= "http://www.w3.org/1999/XSL/Format " >
<xsl:output method= "html " encoding= "UTF-8 "/>
<xsl:template match= "topnews ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 "/>
<title> yangzi </title>
</head>
<body>
<xsl:for-each select= "./news ">
<xsl:value-of select= "time "/> <br />
<xsl:value-of select= "title "/> <br />
<label> 标题有链接,地址为: shownews.asp?id= <xsl:value-of select= "newsid "/> </label>
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
topNews.xml文件代码如下:
<?xml version= "1.0 " encoding= "gb2312 " ?>
- <topnews>
- <news>
<newsid> 1273 </newsid>
<title> 新闻一 </title>
<time> 2007-5-28 9:43:00 </time>
</news>
- <news>
<newsid> 1272 </newsid>
<title> 新闻二 </title>
<time> 2007-5-28 9:38:00 </time>
</news>
- <news>
<newsid> 1271 </newsid>
<title> 新闻三 </title>
<time> 2007-5-17 19:50:00 </time>
</news>
</topnews>
请问如何在 index.html 中调用这些数据,显示的时候是这样的格式:
2007-5-17
新闻一 <标题有链接,地址为: shownews.asp?id=newsid>
2007-5-28
新闻二 <标题有链接,地址为: shownews.asp?id=newsid>
2007-5-28
新闻三 <标题有链接,地址为: shownews.asp?id=newsid>
求index.html代码.最好是Javascript写的.谢谢!
------解决方案--------------------
tino.xml
<?xml version= "1.0 " encoding= "UTF-8 "?>
<?xml-stylesheet type= "text/xsl " href= "tino.xsl "?>
<topnews>
<news>
<newsid> 1273 </newsid>
<title> 新闻一 </title>
<time> 2007-5-28 9:43:00 </time>
</news>
<news>
<newsid> 1272 </newsid>
<title> 新闻二 </title>
<time> 2007-5-28 9:38:00 </time>
</news>
<news>
<newsid> 1271 </newsid>
<title> 新闻三 </title>
<time> 2007-5-17 19:50:00 </time>
</news>
</topnews>
tino.xsl
<?xml version= "1.0 " encoding= "utf-8 "?>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " xmlns:fo= "http://www.w3.org/1999/XSL/Format " >
<xsl:output method= "html " encoding= "UTF-8 "/>
<xsl:template match= "topnews ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 "/>
<title> yangzi </title>
</head>
<body>
<xsl:for-each select= "./news ">
<xsl:value-of select= "time "/> <br />
<xsl:value-of select= "title "/> <br />
<label> 标题有链接,地址为: shownews.asp?id= <xsl:value-of select= "newsid "/> </label>
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>