2014-02-10 145 views
-1

我有一些XML標記,看起來像以下:XSLT選擇屬性

<Conf_Standings League="Atlantic Coast"> 
    <Listing> 
     <Team>Syracuse</Team> 
     <TeamID>C76</TeamID> 
     <Record Type="Conference"> 
     <Wins>10</Wins> 
     <Loss>0</Loss> 
     <Win_Percentage>1.000</Win_Percentage> 
     </Record> 
     <Record Type="Overall"> 
     <Wins>23</Wins> 
     <Loss>0</Loss> 
     <Win_Percentage>1.000</Win_Percentage> 
     </Record> 
    </Listing> 
    <Listing> 
     <Team>Virginia</Team> 
     <TeamID>D05</TeamID> 
     <Record Type="Conference"> 
     <Wins>10</Wins> 
     <Loss>1</Loss> 
     <Win_Percentage>.909</Win_Percentage> 
     </Record> 
     <Record Type="Overall"> 
     <Wins>19</Wins> 
     <Loss>5</Loss> 
     <Win_Percentage>.792</Win_Percentage> 
     </Record> 
    </Listing> 
</Conf_Standings> 

當我通過使用XSLT 1.0的上市循環中,我使用類似以下內容:

<xsl:for-each select="Conf_Standings/Listing"> 

的我現在遇到的問題是,在這一點上,我目前在每個人的背景下Listing,並且不能再參考Conf_Standings中的League屬性。如果我嘗試做一些事情,如:

"standings": [<xsl:for-each select="Conf_Standings/Listing"> 
     { 
     "name": "<xsl:value-of select="normalize-space(@League)"/>" 
     } 
... 

聯賽的名字是空的。什麼是搶的@League在我的例子保持上述的正確方法,使「大西洋海岸」一旦我的Conf_Standings/Listing

回答

1

您可以使用父軸,並得到裏面的@Leage

<xsl:value-of select="normalize-space(../@League)"/> 
0
選擇

此外,你可以使用一個變量前,爲每個存儲的價值和使用它:

<xsl:template match="/"> 
<xsl:variable name="attribute-leage" select="Conf_Standings/@League"/> 
<xsl:for-each select="Conf_Standings/Listing"> 
... <xsl:value-of select="normalize-space($attribute-leage)"/> ... 
</xsl:for-each> 
</xsl:template>