1
我的XML麻煩通過XML節點循環
<INSPECTION_AREAS>
<AREA id="1" name="NorthWest Region">
<INSPECTION_SECTORS>
<SECTOR id = "654" name = "Angola">
</SECTOR>
<SECTOR id = "852" name = "Lafouche">
</SECTOR>
<SECTOR id = "419" name = "Lake Borgne">
</SECTOR>
</INSPECTION_SECTORS>
</AREA>
<AREA id="2" name="SouthWest Region">
<INSPECTION_SECTORS>
<SECTOR id = "106" name = "Orleans">
</SECTOR>
<SECTOR id = "968" name = "Plaquemines">
</SECTOR>
<SECTOR id = "455" name = "Forty Arpent">
</SECTOR>
</INSPECTION_SECTORS>
</AREA>
<AREA id="3" name="MidWest Region">
<INSPECTION_SECTORS>
<SECTOR id = "698" name = "West End">
</SECTOR>
<SECTOR id = "232" name = "St. Bernard">
</SECTOR>
<SECTOR id = "768" name = "Grand Isle">
</SECTOR>
</INSPECTION_SECTORS>
我想列出每個部門的每個區域。當我嘗試以下方法:
<xsl:for-each select="//INSPECTION_AREAS/AREA">
----<xsl:value-of select="@name"></xsl:value-of>----<xsl:text>
</xsl:text>
我得到的只是我的領域
----NorthWest Region----
----SouthWest Region----
----MidWest Region----
這很好的列表。當我嘗試列出部門爲每個區域,使用下面的代碼
<xsl:for-each select="//INSPECTION_AREAS/AREA">
----<xsl:value-of select="@name"></xsl:value-of>----<xsl:text>
</xsl:text>
<xsl:for-each select=".//INSPECTION_AREAS/AREA/INSPECTION_SECTORS/SECTOR">
<xsl:value-of select="@id"></xsl:value-of><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
我得到不同的區域,但每個區域都有部門的同一列表。 I.e ...
----NorthWest Region----
Angola
Lafouche
Lake Borgne
----SouthWest Region----
Angola
Lafouche
Lake Borgne
----MidWest Region----
Angola
Lafouche
Lake Borgne
我沒有得到每個不同區域的不同部門。我不確定我在這裏做錯了什麼。任何幫助都會很棒。提前致謝。
OhEmGee ...非常感謝。我現在感覺很慢。但改變這種方式就像魅力一樣 – user1898629