【发布时间】:2015-03-23 09:14:49
【问题描述】:
我正忙于一个大学项目,该项目有一个带有一堆乐队的 XML。我目前让我的 XSL 输出多个 HTML 页面,这些页面充当每个乐队的“个人资料页面”(因此每个乐队都在单独的 HTML 页面上),并带有相互链接的链接。现在,我想在相应的 html 页面上添加乐队的图像。这可能吗?
这是 XML 中一位艺术家的示例:
<lineup>
<artist id="101">
<name>Jeremey Loops</name>
<genres>
<genre>Acoustic</genre>
</genres>
<writeup>
Jeremy Loops aint no traditional 'band', creating music on the spot with that there loopdaloop pedal. Various artists also join him for free jam sessions & the music they create is all original. it'll definitely make ya dance like a hick!
</writeup>
<gig>
<day>FRIDAY</day>
<time>
<starts>12:00</starts>
<ends>14:00</ends>
</time>
</gig>
</artist>
</lineup>
这是我用 XSL 尝试过的,但发现图像显示在所有页面上,图像两侧都写有“真”和“假”。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" name="html"/>
<xsl:template match="/">
<xsl:apply-templates select="lineup"/>
</xsl:template>
<xsl:template match="lineup">
<xsl:apply-templates select="artist"/>
</xsl:template>
<xsl:template match="artist">
<xsl:variable name="filename" select="concat('bands/',name,'.html')" />
<xsl:value-of select="$filename" />
<xsl:result-document href="{$filename}" format="html">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../sass/test.css" />
<title>
<!-- TITLE OF PAGE -->
Band - <xsl:value-of select="name"/>
</title>
</head>
<body>
<!-- Adding Image -->
<div class="images">
<xsl:value-of select="name = 'Jeremey Loops'"/>
<img src="images/jeremey_loops.png" alt="Jeremey Loops standing with guitar" height="350px"/>
</div>
<!-- LINKS TO BAND PAGES -->
<div class="box links">
<xsl:variable name="current" select="@id" />
<xsl:for-each select="/lineup/artist" >
<a href="{name}.html">
<xsl:value-of select="name"/> |
</a>
</xsl:for-each>
</div>
</body>
</html>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
所以我只想在他的页面上而不是在其他艺术家的页面上显示“Jeremey Loops”图像,其余部分也是如此。我应该为每个艺术家添加一个过滤器吗?
【问题讨论】: