这是我的 XSLT 文件中的 foreach:
<xsl:for-each select="/flights/flight/route[../plane/name/. ='Airbus 330']/routename">
<tr>
<td>
<xsl:attribute name="colspan" >2</xsl:attribute><xsl:attribute name="style" >text-align:center</xsl:attribute><a><xsl:attribute name="href">map.php?a=<xsl:value-of select="/flights/flight/route[../plane/name/. =$a]/from/latitude" />&b=<xsl:value-of select="/flights/flight/route[../plane/name/. =$a]/from/longitude" />&c=<xsl:value-of select="/flights/flight/route[../plane/name/. =$a]/to/latitude" />&d=<xsl:value-of select="/flights/flight/route[../plane/name/. =$a]/to/longitude" />&e=<xsl:value-of select="/flights/flight/route[../plane/name/. =$a]/routename" /></xsl:attribute>
<xsl:value-of select="/flights/flight/route[../plane/name/. ='Airbus 330']/routename"/></a>
</td>
</tr>
</xsl:for-each>
有两条航线有一架 Airbus 330 飞机,在为每条航线运行时,它会根据需要创建两个表行和链接,但使用第一个航线名称两次,而不是每个航线名称。为什么会这样?
这是 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<flights
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="flights.xsd">
<flight flightid="1">
<flightno>EK98</flightno>
<callsign>UAE98</callsign>
<airline>Emirates Airline</airline>
<plane planeid="1">
<name>Airbus 330</name>
<speed>567</speed>
<registereddate>07-06-10</registereddate>
</plane>
<registration>3A6-EDJ</registration>
<altitude height="feet">41000 feet</altitude>
<speed ratio="mph">564 mph</speed>
<route>
<routename>Fiumicino-Dubai</routename>
<course bearing="degrees">154 degrees</course>
<distance type="miles">2697 miles</distance>
<duration>PT5H30M</duration>
<from>
<iatacode>FCO</iatacode>
<airport>Fiumicino</airport>
<country>Italy</country>
<city>Rome</city>
<latitude>41.8044</latitude>
<longitude>12.2508</longitude>
</from>
<to>
<iatacode>DXB</iatacode>
<airport>Dubai Intl</airport>
<country>UAE</country>
<city>Dubai</city>
<latitude>25.2528</latitude>
<longitude>55.3644</longitude>
</to>
</route>
</flight>
<flight flightid="2">
<flightno>BA283</flightno>
<callsign>BAW283</callsign>
<airline>British Airways</airline>
<plane planeid="2">
<name>Airbus 330</name>
<speed>567</speed>
<registereddate>06-12-97</registereddate>
</plane>
<registration>3A6-EDJ</registration>
<altitude height="feet">41000 feet</altitude>
<speed ratio="mph">564 mph</speed>
<route>
<routename>London-L.A</routename>
<course bearing="degrees">154 degrees</course>
<distance type="miles">5441 miles</distance>
<time>PT11H5M</time>
<from>
<iatacode>LHR</iatacode>
<airport>Heathrow</airport>
<country>England</country>
<city>London</city>
<latitude>51.4775</latitude>
<longitude>0.4614</longitude>
</from>
<to>
<iatacode>LAX</iatacode>
<airport>Los Angeles Intl</airport>
<country>USA</country>
<city>L.A</city>
<latitude>33.9471</latitude>
<longitude>-118.4082</longitude>
</to>
</route>
</flight>
</flights>