2013-05-04 2 views
0

각 노드에 <ifb-regular-stats> 노드가있는 데이터 집합이 있습니다. 어떤 플레이어는 추가 노드가 <ifb-goalie-stats>입니다. 내가하고 싶은 일은이 추가 노드가 데이터 내에있는 플레이어를 제외하는 것입니다. (내 예와 같이하지만 난 그냥 골키퍼 통계를 표시합니다 추가 테이블이 없습니다.)XSLT XML 노드 기반 항목 제외

예 XML 데이터를

<sports-statistics> 
    <sports-player-stats> 
    <date year="2013" month="4" date="30" day="2"/> 
    <soccer-ifb-player-stats> 
     <ifb-player-stats> 
     <player-name last-name="Test" first-name="Guy" shirt-name="" full-first="Guy" full-last="Test"/> 
     <player-code global-id="537247" id="135523"/> 
     <ifb-regular-stats type="team"> 
     <team-info global-id="26580" id="3340" location="Tulsa" name="TBears" alias="TUL" display-name="Tulsa"/> 
     <games-played games="3"/> 
     <games-started games="3"/> 
     <goals goals="0" game-winning="0" own-goal="0" headers="0"/> 
     </ifb-regular-stats> 
     </ifb-player-stats> 
     <ifb-player-stats> 
     <player-name last-name="Abele" first-name="Kurt" shirt-name="" full-first="Kurt" full-last="Abele"/> 
     <player-code global-id="537263" id="135524"/> 
     <ifb-regular-stats type="team"> 
     <team-info global-id="26580" id="3340" location="Tulsa" name="TBears" alias="TUL" display-name="Tulsa"//> 
     <games-played games="3"/> 
     <games-started games="3"/> 
     <goals goals="0" game-winning="0" own-goal="0" headers="0"/> 
     </ifb-regular-stats> 
     <ifb-goalie-stats type="team"> 
     <team-info global-id="26580" id="3340" location="Tulsa" name="TBears" alias="TUL" display-name="Tulsa"//> 
     <games-played games="3"/> 
     <games-started games="3"/> 
     <record wins="0" losses="1" ties="2" percentage=".333"/> 
     </ifb-goalie-stats> 
    </sports-player-stats> 
</sports-statistics> 

(I 길이의 위해이 예에서는 일부 자식 노드를 제거했다) 내 코드는 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> 
    <xsl:output method="html" indent="yes" encoding = "utf-8" standalone = "yes"/> 

    <xsl:variable name="fcPlayers"> 
    <map team="team" /> 
    </xsl:variable> 
    <xsl:variable name="fcPlayersMap" select="msxsl:node-set($fcPlayers)/*" /> 

    <xsl:template match="/"> 
    <html> 
     <head > 
     <meta charset="utf-8" /> 
     <title> Player Stats</title> 
     </head> 

     <body> 
     <table id="fcPlayers" > 
      <tr > 
      <th>Last</th> 
      <th>First</th> 
      <th align="center">GP</th> 
      <th align="center">GS</th> 
      <th align="center">MP </th> 
      <th align="center">G</th> 
      <th align="center">GWG</th> 
      <th align="center">S</th> 
      <th align="center">SOG</th> 
      <Th align="center" >F</Th> 
      </tr> 

      <xsl:apply-templates select="//ifb-player-stats/ifb-regular-stats[@type = 'team']" > 
      <xsl:sort select="../player-name/@last-name" /> 
      </xsl:apply-templates> 

     </table> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="ifb-player-stats/ifb-regular-stats[starts-with(team-info/@global-id, '26583')]"> 
    <xsl:variable name="ti" select="../player-name" /> 

    <tr> 
     <td> 
     <xsl:value-of select="$ti/@last-name" /> 
     </td> 
     <td> 
     <xsl:value-of select="$ti/@first-name" /> 
     </td> 
     <td align="center"> 
     <xsl:value-of select="games-played/@games"/> 
     </td> 
     <td align="center"> 
     <xsl:value-of select="games-started/@games"/> 
     </td> 
    </tr> 

    </xsl:template> 
</xsl:stylesheet> 

미리 도움을 청하십시오!

답변

0

그래서 당신은 그것의 ifb-goalie-stats이있는 ifb-player-stats을 건너 뛰려면? 그렇다면 apply-templates의 경로를 수정할 수 있습니다.

<xsl:apply-templates 
    select="//ifb-player-stats[not(ifb-goalie-stats)] 
       /ifb-regular-stats[@type = 'team']" > 
    <xsl:sort select="../player-name/@last-name" /> 
</xsl:apply-templates> 
+0

Perfect !!! 고맙습니다! –

0

<xsl:if>not()을 조합하여 사용할 수 있습니다.

<xsl:template match="/"> 
    <xsl:if test="not(/sports-statistics/sports-player-stats/soccer-ifb-player-stats/ifb-goalie-stats)"> 
    // The ifb-goalie-stats node does not exist for this match, so render the template 
    // Put everything else which is currently inside <xsl:template match="/"> here.. 
    </xsl:if> 
</xsl:template>