0
這裏是我的XSLT文件中的foreach:XSL的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>
有兩條路線有一架空客330飛機,運行這個每個時,它會創建兩個表格行和鏈接,但是使用第一個routename而不是每個routename。這是爲什麼發生?
下面是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>
感謝那些工作,鏈接現在是兩個不同的路線名稱,但傳遞的參數仍然是第一套,你能告訴我如何遍歷到下一組的參數,我試過,但沒有奏效:map.php一個=的 ? –
deucalion0
2013-02-16 13:14:13
當你處理'routename'作爲上下文節點,則需要'的 ',然後到達父路由,然後到'from/latitude'子孫,或者你可以訪問兄弟' '。作爲第三種選擇,你可以改變'for-each'來處理'route'元素,然後你可以使用select <= routename「/>'和'。 –
2013-02-16 14:18:11
非常感謝您的幫助,我也對此更加了解。謝謝!! – deucalion0 2013-02-16 14:30:41