2014-02-10 147 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>