У меня есть файл XML, в котором есть информация о футбольной игре и ее играх с подсчетом. Я хотел бы выбрать только определенные узлы, которые меня интересуют, и сохранить их в CSV.XSLT по XML в CSV с заголовками столбцов только на определенных узлах
Я действительно заинтересован только в этих узлах:
- /гам: игра/гам: дата
- /гам: игра/гам: awayTeam/гам: Аббревиатура
- /гам: игра/гам: homeTeam/гам: Аббревиатура
- /гам: quarterSummary/гам: квартал/гам: скоринг/гам: scoringPlay/гам: teamAbbreviation
- /гам: quarterSummary/гам: квартал/гам: скоринг/гам: scoringPlay/gam: playDescription
Мое ожидание было бы что-то подобное в CSV (запятыми)
GameDate, AwayTeam, HomeTeam, ScoringTeam, PlayDescription
2017-01-07, DET, SEA, SEA, (7:14) R.Wilson pass short right to P.Richardson for 2 yards, TOUCHDOWN. Penalty on DET-T.Wilson, Defensive Pass Interference, declined.
2017-01-07, DET, SEA, SEA, S.Hauschka extra point is GOOD, Center-T.Ott, Holder-J.Ryan.
2017-01-07, DET, SEA, SEA, (2:00) S.Hauschka 43 yard field goal is GOOD, Center-T.Ott, Holder-J.Ryan.
2017-01-07, DET, SEA, DET, (:25) M.Prater 51 yard field goal is GOOD, Center-D.Muhlbach, Holder-S.Martin.
2017-01-07, DET, SEA, DET, (4:08) M.Prater 53 yard field goal is GOOD, Center-D.Muhlbach, Holder-S.Martin.
2017-01-07, DET, SEA, SEA, (14:15) S.Hauschka 27 yard field goal is GOOD, Center-T.Ott, Holder-J.Ryan.
2017-01-07, DET, SEA, SEA, (8:53) (Shotgun) T.Rawls right guard for 4 yards, TOUCHDOWN.
2017-01-07, DET, SEA, SEA, (3:43) (Shotgun) R.Wilson pass short middle to D.Baldwin for 13 yards, TOUCHDOWN.
2017-01-07, DET, SEA, SEA, S.Hauschka extra point is GOOD, Center-T.Ott, Holder-J.Ryan.
Входной XML:
<?xml version="1.0"?>
<gam:gameboxscore xmlns:gam="http://leaguemanager.beacontender.com/plugin/feed/sport/usftbl/gameboxscore">
<gam:lastUpdatedOn>2017-01-08 12:22:22 AM</gam:lastUpdatedOn>
<gam:game>
<gam:date>2017-01-07</gam:date>
<gam:time>8:15PM</gam:time>
<gam:awayTeam>
<gam:ID>61</gam:ID>
<gam:City>Detroit</gam:City>
<gam:Name>Lions</gam:Name>
<gam:Abbreviation>DET</gam:Abbreviation>
</gam:awayTeam>
<gam:homeTeam>
<gam:ID>79</gam:ID>
<gam:City>Seattle</gam:City>
<gam:Name>Seahawks</gam:Name>
<gam:Abbreviation>SEA</gam:Abbreviation>
</gam:homeTeam>
<gam:location>CenturyLink Field</gam:location>
</gam:game>
<gam:quarterSummary>
<gam:quarter number="1">
<gam:awayScore>0</gam:awayScore>
<gam:homeScore>0</gam:homeScore>
<gam:scoring/>
</gam:quarter>
<gam:quarter number="2">
<gam:awayScore>3</gam:awayScore>
<gam:homeScore>10</gam:homeScore>
<gam:scoring>
<gam:scoringPlay>
<gam:time>7:46</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>(7:14) R.Wilson pass short right to P.Richardson for 2 yards, TOUCHDOWN. Penalty on DET-T.Wilson, Defensive Pass Interference, declined.</gam:playDescription>
</gam:scoringPlay>
<gam:scoringPlay>
<gam:time>7:53</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>S.Hauschka extra point is GOOD, Center-T.Ott, Holder-J.Ryan.</gam:playDescription>
</gam:scoringPlay>
<gam:scoringPlay>
<gam:time>13:00</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>(2:00) S.Hauschka 43 yard field goal is GOOD, Center-T.Ott, Holder-J.Ryan.</gam:playDescription>
</gam:scoringPlay>
<gam:scoringPlay>
<gam:time>14:35</gam:time>
<gam:teamAbbreviation>DET</gam:teamAbbreviation>
<gam:playDescription>(:25) M.Prater 51 yard field goal is GOOD, Center-D.Muhlbach, Holder-S.Martin.</gam:playDescription>
</gam:scoringPlay>
</gam:scoring>
</gam:quarter>
<gam:quarter number="3">
<gam:awayScore>3</gam:awayScore>
<gam:homeScore>0</gam:homeScore>
<gam:scoring>
<gam:scoringPlay>
<gam:time>10:52</gam:time>
<gam:teamAbbreviation>DET</gam:teamAbbreviation>
<gam:playDescription>(4:08) M.Prater 53 yard field goal is GOOD, Center-D.Muhlbach, Holder-S.Martin.</gam:playDescription>
</gam:scoringPlay>
</gam:scoring>
</gam:quarter>
<gam:quarter number="4">
<gam:awayScore>0</gam:awayScore>
<gam:homeScore>16</gam:homeScore>
<gam:scoring>
<gam:scoringPlay>
<gam:time>0:45</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>(14:15) S.Hauschka 27 yard field goal is GOOD, Center-T.Ott, Holder-J.Ryan.</gam:playDescription>
</gam:scoringPlay>
<gam:scoringPlay>
<gam:time>6:07</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>(8:53) (Shotgun) T.Rawls right guard for 4 yards, TOUCHDOWN.</gam:playDescription>
</gam:scoringPlay>
<gam:scoringPlay>
<gam:time>11:17</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>(3:43) (Shotgun) R.Wilson pass short middle to D.Baldwin for 13 yards, TOUCHDOWN.</gam:playDescription>
</gam:scoringPlay>
<gam:scoringPlay>
<gam:time>11:24</gam:time>
<gam:teamAbbreviation>SEA</gam:teamAbbreviation>
<gam:playDescription>S.Hauschka extra point is GOOD, Center-T.Ott, Holder-J.Ryan.</gam:playDescription>
</gam:scoringPlay>
</gam:scoring>
</gam:quarter>
<gam:quarterTotals>
<gam:awayScore>6</gam:awayScore>
<gam:homeScore>26</gam:homeScore>
</gam:quarterTotals>
</gam:quarterSummary>
</gam:gameboxscore>
Вот самая последняя версия XSLT, которую я использую , В настоящее время это дает мне только одну запись, возвращенную для первой забивной игры.
<xsl:stylesheet version="2.0" xmlns:gam="http://leaguemanager.beacontender.com/plugin/feed/sport/usftbl/gameboxscore"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="gam:gameboxscore">
<xsl:text>GameDate,AwayTeam,HomeTeam,ScoringTeam,playDescription "</xsl:text>
<xsl:value-of select="gam:game/gam:date"/>
<xsl:text>","</xsl:text>
<xsl:value-of select="gam:game/gam:awayTeam/gam:Abbreviation"/>
<xsl:text>","</xsl:text>
<xsl:value-of select="gam:game/gam:homeTeam/gam:Abbreviation"/>
<xsl:text>","</xsl:text>
<xsl:value-of select="gam:quarterSummary/gam:quarter/gam:scoring/gam:scoringPlay/gam:teamAbbreviation"/>
<xsl:text>","</xsl:text>
<xsl:value-of select="gam:quarterSummary/gam:quarter/gam:scoring/gam:scoringPlay/gam:playDescription"/>
<xsl:text>"</xsl:text>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
Заранее благодарен!
Пожалуйста, покажите нам свой текущий XSLT. Или вы просите нас написать его для вас? –