Asa*_*saf 7 html javascript xslt
我想使用xml文件
<pics>
<pic no="1">c:\pic1.jpg</pic>
<pic no="2">c:\pic2.jpg</pic>
<pic no="3">c:\pic3.jpg</pic>
<pic no="4">c:\pic4.jpg</pic>
<pic no="5">c:\pic5.jpg</pic>
....
</pics>
Run Code Online (Sandbox Code Playgroud)
在html表中:
<table cellspacing="2" cellpadding="2" border="0">
<tr>
<td><img src="" width="150" height="120" /></td>
<td><img src="" width="150" height="120" /></td>
<td><img src="" width="150" height="120" /></td>
</tr>
<tr>
<td><img src="from xml" width="150" height="120" /></td>
<td><img src="from xml" width="150" height="120" /></td>
<td><img src="from xml" width="150" height="120" /></td>
</tr>
<tr>
<td><img src="from xml" width="150" height="120" /></td>
<td><img src="from xml" width="150" height="120" /></td>
<td><img src="from xml" width="150" height="120" /></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
什么是最好的方法呢?
XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="web_page.xsl"?>
<pics>
<pic>
<td>
<no src="http://farm1.static.flickr.com/160/387667598_ea86c93d81.jpg" width="150" height="120">1</no>
</td>
<td>
<no src="http://farm1.static.flickr.com/160/387667598_ea86c93d81.jpg" width="150" height="120">2</no>
</td>
<td>
<no src="http://farm1.static.flickr.com/160/387667598_ea86c93d81.jpg" width="150" height="120">3</no>
</td>
</pic>
<pic>
<td>
<no src="http://motherjones.com/files/legacy/mojoblog/funny-cats-a10.jpg" width="150" height="120">4</no>
</td>
<td>
<no src="http://motherjones.com/files/legacy/mojoblog/funny-cats-a10.jpg" width="150" height="120">5</no>
</td>
<td>
<no src="http://motherjones.com/files/legacy/mojoblog/funny-cats-a10.jpg" width="150" height="120">6</no>
</td>
</pic>
</pics>
Run Code Online (Sandbox Code Playgroud)
XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table>
<xsl:for-each select="pics/pic">
<tr>
<xsl:for-each select="td">
<td><img>
<xsl:attribute name="src">
<xsl:value-of select="no//@src"/>
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="no//@width"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="no//@height"/>
</xsl:attribute>
</img></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
在这里自己尝试一下(将我的代码复制并粘贴到相应的框中):
| 归档时间: |
|
| 查看次数: |
18291 次 |
| 最近记录: |