0

我有一组数据,每个玩家都有一个<ifb-regular-stats>节点。一些玩家有一个额外的节点<ifb-goalie-stats>。我想要做的是排除任何在数据中具有此附加节点的玩家。(在我的示例中未显示,但我有一个仅显示守门员统计数据的附加表。)

示例 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>

这是我的代码:

<?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>

在此先感谢您的帮助!

4

2 回答 2

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>
于 2013-05-04T01:05:54.287 回答
0

因此,您想跳过ifb-player-stats其中包含的任何ifb-goalie-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>
于 2013-05-04T01:55:18.150 回答