我有一个用 XML 和 XLST 制作的“博客”。
这是博客的格式:
<post id="1" category="Miscellaneous">
<ptitle>MiG-21</ptitle>
<psubtitle>Mikoyan-Gurevich MiG-21</psubtitle>
<image></image>
<author> Brian Livori </author>
<date> 11/10/2012 </date>
<par> The Mikoyan-Gurevich MiG-21 (Russian: Микоян и Гуревич МиГ-21; NATO reporting name: Fishbed) is a supersonic jet fighter aircraft, designed by the Mikoyan-Gurevich Design Bureau in the Soviet Union. It was popularly nicknamed "balalaika", from the aircraft's planform-view resemblance to the Russian stringed musical instrument or ołówek (English: pencil) by Polish pilots due to the shape of its fuselage.[2]
Early versions are considered second-generation jet fighters, while later versions are considered to be third-generation jet fighters. Some 50 countries over four continents have flown the MiG-21, and it still serves many nations a half-century after its maiden flight. The fighter made aviation records. At least by name, it is the most-produced supersonic jet aircraft in aviation history and the most-produced combat aircraft since the Korean War, and it had the longest production run of a combat aircraft (1959 to 1985 over all variants).
</par>
<source>http://en.wikipedia.org/wiki/Mikoyan-Gurevich_MiG-21</source>
<comments>dsgsdg</comments>
</post>
<post id="2" category="Miscellaneous">
<ptitle>MiG-21</ptitle>
<psubtitle>Mikoyan-Gurevich MiG-21</psubtitle>
<image></image>
<author> Brian Livori </author>
<date> 11/10/2012 </date>
<par> The Mikoyan-Gurevich MiG-21 (Russian: Микоян и Гуревич МиГ-21; NATO reporting name: Fishbed) is a supersonic jet fighter aircraft, designed by the Mikoyan-Gurevich Design Bureau in the Soviet Union. It was popularly nicknamed "balalaika", from the aircraft's planform-view resemblance to the Russian stringed musical instrument or ołówek (English: pencil) by Polish pilots due to the shape of its fuselage.[2]
Early versions are considered second-generation jet fighters, while later versions are considered to be third-generation jet fighters. Some 50 countries over four continents have flown the MiG-21, and it still serves many nations a half-century after its maiden flight. The fighter made aviation records. At least by name, it is the most-produced supersonic jet aircraft in aviation history and the most-produced combat aircraft since the Korean War, and it had the longest production run of a combat aircraft (1959 to 1985 over all variants).
</par>
<source>http://en.wikipedia.org/wiki/Mikoyan-Gurevich_MiG-21</source>
<comments>dsgsdg</comments>
</post>
我想为每篇博文插入一张图片。
我怎样才能做到这一点?
这是我的 .xls 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match ="/">
<html>
<body>
<table align="center" >
<tr bgcolor="C77838">
<th>Brian's Blog </th>
<th>About</th>
<th>Contact</th>
</tr>
</table>
<table align="center" bgcolor="1D6135">
<tr align="center">
<xsl:element name="img" >
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="src">images/banner.jpg</xsl:attribute>
<xsl:attribute name="alt">Banner</xsl:attribute>
</xsl:element>
</tr>
<tr align="center">
<h1>JET FIGHTERS</h1>
</tr>
</table>
<br></br><br></br>
<table >
<td width="10%" bgcolor="white"></td>
<td bgcolor="CC9933">
<xsl:for-each select="blog/post">
<tr bgcolor="FFFF99" ><td><xsl:value-of select="ptitle"/></td></tr>
<tr bgcolor="FFFFCC"><td><xsl:value-of select="psubtitle"/></td></tr><br></br><br></br>
<tr bgcolor="FFFFCC"><td><xsl:value-of select="image"/></td></tr>
<tr><td><xsl:value-of select="par"/></td></tr><br></br><br></br>
<tr bgcolor="D6D6B2"><td>Source: <xsl:value-of select="source"/></td></tr>
<br></br><tr bgcolor="FFFFCC">Posted on: <xsl:value-of select="date"/> by <xsl:value-of select="author"/></tr>
<br></br><tr bgcolor="FFFFCD">Comments: <xsl:value-of select="comments"/> by <xsl:value-of select="comments"/></tr>
<hr color="white"></hr>
</xsl:for-each>
</td>
<td width="10%" bgcolor="white"></td>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="list">
Images are element contents, apply a template to all image elements:
<xsl:apply-templates select="image"/>
Images are attribute values of an element, we do it differently:
<xsl:apply-templates select="image3"/>
</xsl:template>
<xsl:template match="image1">
<p> <img src="{@source}"/><br/><xsl:value-of select="."/> </p>
</xsl:template>
</xsl:stylesheet>