Skip to content

Instantly share code, notes, and snippets.

@chrissabato
Last active July 28, 2016 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrissabato/afcb350f707934aa909a470f5d242fef to your computer and use it in GitHub Desktop.
Save chrissabato/afcb350f707934aa909a470f5d242fef to your computer and use it in GitHub Desktop.
XSLT for importing StatCrew Football game XML's into InDesign
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<!-- directory where photos wil be placed -->
<xsl:variable name="photo_location" select="'file:///D:/Creative Cloud Files/CoSIDA/images/'"/>
<xsl:template match="/">
<football>
<!-- Game Information -->
<game_info>
<gameid><xsl:value-of select="/fbgame/venue/@gameid"/></gameid>
<date><xsl:value-of select="/fbgame/venue/@date" /></date>
<city><xsl:value-of select="/fbgame/venue/@location"/></city>
<stadium><xsl:value-of select="/fbgame/venue/@stadium"/></stadium>
<location><xsl:value-of select="/fbgame/venue/@stadium"/>, <xsl:value-of select="/fbgame/venue/@location"/></location>
<start><xsl:value-of select="/fbgame/venue/@start"/></start>
<attendance><xsl:value-of select="/fbgame/venue/@attend"/></attendance>
<temp><xsl:value-of select="/fbgame/venue/@temp"/></temp>
<wind><xsl:value-of select="/fbgame/venue/@wind"/></wind>
<weather><xsl:value-of select="/fbgame/venue/@weather"/></weather>
<!-- Format date from mm/dd/yyyy -->
<xsl:variable name="tempdate" select="/fbgame/venue/@date" />
<xsl:variable name="part1" select="substring-before($tempdate, '/')" />
<xsl:variable name="temp" select="substring-after($tempdate, '/')" />
<xsl:variable name="part2" select="substring-before($temp, '/')" />
<xsl:variable name="part3" select="substring-after($temp, '/')" />
<fdate>
<xsl:choose>
<xsl:when test="$part1 = '1'">January</xsl:when>
<xsl:when test="$part1 = '2'">February</xsl:when>
<xsl:when test="$part1 = '3'">March</xsl:when>
<xsl:when test="$part1 = '4'">April</xsl:when>
<xsl:when test="$part1 = '5'">May</xsl:when>
<xsl:when test="$part1 = '6'">June</xsl:when>
<xsl:when test="$part1 = '7'">July</xsl:when>
<xsl:when test="$part1 = '8'">August</xsl:when>
<xsl:when test="$part1 = '9'">September</xsl:when>
<xsl:when test="$part1 = '10'">October</xsl:when>
<xsl:when test="$part1 = '11'">November</xsl:when>
<xsl:when test="$part1 = '12'">December</xsl:when>
<xsl:when test="$part1 = '01'">January</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '02'">February</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '03'">March</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '04'">April</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '05'">May</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '06'">June</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '07'">July</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '08'">August</xsl:when> <!-- account for 2 digit month -->
<xsl:when test="$part1 = '09'">September</xsl:when> <!-- account for 2 digit month -->
</xsl:choose>&#160;<xsl:value-of select="$part2"/>,&#160;<xsl:value-of select="$part3"/>
</fdate>
</game_info>
<!-- Game Information -->
<!-- Teams -->
<xsl:for-each select="/fbgame/team">
<xsl:element name="{@vh}">
<info>
<code><xsl:value-of select="@code"/></code>
<id><xsl:value-of select="@id"/></id>
<name><xsl:value-of select="@name"/></name>
<record><xsl:value-of select="@record"/></record>
<conf_record><xsl:value-of select="@conf-record"/></conf_record>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />team/<xsl:value-of select="@id"/>.png</xsl:attribute></xsl:element>
</info>
<graphs>
<totoff_yards><xsl:attribute name="href"><xsl:value-of select="$photo_location" />graph/totoff_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/@totoff_yards div 700 *10)" />.png</xsl:attribute></totoff_yards>
<passing_yards><xsl:attribute name="href"><xsl:value-of select="$photo_location" />graph/totoff_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/pass/@yds div 700 *10)" />.png</xsl:attribute></passing_yards>
<rushing_yards><xsl:attribute name="href"><xsl:value-of select="$photo_location" />graph/totoff_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/rush/@yds div 700 *10)" />.png</xsl:attribute></rushing_yards>
<turnover><xsl:attribute name="href"><xsl:value-of select="$photo_location" />graph/turnovers_<xsl:value-of select="@vh"/>_<xsl:value-of select="totals/fumbles/@lost + totals/pass/@int" />.png</xsl:attribute></turnover>
<third_conv><xsl:attribute name="href"><xsl:value-of select="$photo_location" />graph/third_conv_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/conversions/@thirdconv div totals/conversions/@thirdatt *10)" />.png</xsl:attribute></third_conv>
<redzone><xsl:attribute name="href"><xsl:value-of select="$photo_location" />graph/third_conv_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/redzone/@scores div totals/redzone/@att *10)" />.png</xsl:attribute></redzone>
</graphs>
<!-- Scores -->
<scores>
<final><xsl:value-of select="linescore/@score"/></final>
<linescore>
<xsl:for-each select="linescore/lineprd">
<xsl:element name="prd">
<xsl:value-of select="@score"/>
</xsl:element>
<xsl:element name="image">
<xsl:attribute name="href"><xsl:copy-of select="$photo_location" />graph/quarter-scores_<xsl:value-of select="../../@vh"/>_<xsl:value-of select="round(@score div 30 *10)"/>.png</xsl:attribute>
</xsl:element>
</xsl:for-each>
</linescore>
</scores>
<!-- Scores -->
<!-- Totals -->
<totals>
<totoff_plays><xsl:value-of select="totals/@totoff_plays"/></totoff_plays>
<totoff_yards><xsl:value-of select="totals/@totoff_yards"/></totoff_yards>
<totoff_avg><xsl:value-of select="totals/@totoff_avg"/></totoff_avg>
<third_conv><xsl:value-of select="format-number(totals/conversions/@thirdconv div totals/conversions/@thirdatt *100, '#')" />%</third_conv>
<redzone><xsl:value-of select="format-number(totals/redzone/@scores div totals/redzone/@att *100, '#')" />%</redzone>
<turnover><xsl:value-of select="format-number(totals/fumbles/@lost + totals/pass/@int,'#')" /></turnover>
<xsl:for-each select="totals/*">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:element name="{name()}">
<xsl:value-of select="." />
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</totals>
<!-- Totals -->
<!-- Rushing Leaders -->
<rushing_leaders>
<xsl:for-each select="player">
<xsl:sort select="rush/@yds" data-type="number" order="descending"/>
<xsl:if test="not(position() > 5)">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
<rushing>
<att><xsl:value-of select="rush/@att"/></att>
<yds><xsl:value-of select="rush/@yds"/></yds>
<yds_avg><xsl:value-of select="format-number(rush/@yds div rush/@att, '#.#')"/></yds_avg>
<gain><xsl:value-of select="rush/@gain"/></gain>
<loss><xsl:value-of select="rush/@loss"/></loss>
<td><xsl:value-of select="rush/@td"/></td>
<long><xsl:value-of select="rush/@long"/></long>
</rushing>
</player>
</xsl:if>
</xsl:for-each>
</rushing_leaders>
<!-- Rushing Leaders -->
<!-- Passing Leaders -->
<passing_leaders>
<xsl:for-each select="player">
<xsl:sort select="pass/@yds" data-type="number" order="descending"/>
<xsl:if test="not(position() > 2)">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
<passing>
<att><xsl:value-of select="pass/@att"/></att>
<comp><xsl:value-of select="pass/@comp"/></comp>
<comp_pct><xsl:value-of select="format-number(pass/@comp div pass/@att *100, '#')"/>%</comp_pct>
<int><xsl:value-of select="pass/@int"/></int>
<yds><xsl:value-of select="pass/@yds"/></yds>
<yds_avg><xsl:value-of select="format-number(pass/@yds div pass/@comp, '#.#')"/></yds_avg>
<td><xsl:value-of select="pass/@td"/></td>
<long><xsl:value-of select="pass/@long"/></long>
<sacks><xsl:value-of select="pass/@sacks"/></sacks>
</passing>
</player>
</xsl:if>
</xsl:for-each>
</passing_leaders>
<!-- Passing Leaders -->
<!-- Receiving Leaders -->
<receiving_leaders>
<xsl:for-each select="player">
<xsl:sort select="rcv/@yds" data-type="number" order="descending"/>
<xsl:if test="not(position() > 5)">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
<receiving>
<no><xsl:value-of select="rcv/@no"/></no>
<yds><xsl:value-of select="rcv/@yds"/></yds>
<yds_avg><xsl:value-of select="format-number(rcv/@yds div rcv/@no, '#.#')"/></yds_avg>
<td><xsl:value-of select="rcv/@td"/></td>
<long><xsl:value-of select="rcv/@long"/></long>
</receiving>
</player>
</xsl:if>
</xsl:for-each>
</receiving_leaders>
<!-- Receiving Leaders -->
<!-- defensive leaders-->
<defense_leaders>
<xsl:for-each select="player">
<xsl:sort select="defense/@tot_tack" data-type="number" order="descending"/>
<xsl:if test="not(position() > 5)">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
<defense>
<tot_tack><xsl:value-of select="defense/@tot_tack"/></tot_tack>
<tackua><xsl:value-of select="defense/@tackua"/></tackua>
<tacka><xsl:value-of select="defense/@tacka"/></tacka>
<tflua><xsl:value-of select="defense/@tflua"/></tflua>
<tflyds><xsl:value-of select="defense/@tflyds"/></tflyds>
<sackua><xsl:value-of select="defense/@sackua"/></sackua>
<sacka><xsl:value-of select="defense/@sacka"/></sacka>
<sackyds><xsl:value-of select="defense/@sackyds"/></sackyds>
</defense>
</player>
</xsl:if>
</xsl:for-each>
</defense_leaders>
<!-- defensive leaders-->
<!-- Int leaders-->
<int_leaders>
<xsl:for-each select="player">
<xsl:sort select="defense/@int" data-type="number" order="descending"/>
<xsl:if test="not(position() > 1)">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
<defense>
<tot_tack><xsl:value-of select="defense/@tot_tack"/></tot_tack>
<tackua><xsl:value-of select="defense/@tackua"/></tackua>
<tacka><xsl:value-of select="defense/@tacka"/></tacka>
<tflua><xsl:value-of select="defense/@tflua"/></tflua>
<tflyds><xsl:value-of select="defense/@tflyds"/></tflyds>
<sackua><xsl:value-of select="defense/@sackua"/></sackua>
<sacka><xsl:value-of select="defense/@sacka"/></sacka>
<sackyds><xsl:value-of select="defense/@sackyds"/></sackyds>
<int><xsl:value-of select="defense/@int"/></int>
<intyds><xsl:value-of select="defense/@intyds"/></intyds>
</defense>
</player>
</xsl:if>
</xsl:for-each>
</int_leaders>
<!-- Int leaders-->
<!-- D Starters -->
<D_Starters>
<xsl:for-each select="player">
<xsl:if test="@dpos">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<pos><xsl:value-of select="@dpos"/></pos>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
</player>
</xsl:if>
</xsl:for-each>
</D_Starters>
<!-- D Starters -->
<!-- O Starters -->
<O_Starters>
<xsl:for-each select="player">
<xsl:if test="@opos">
<player>
<name><xsl:value-of select="@name"/></name>
<shortname><xsl:value-of select="@shortname"/></shortname>
<uni><xsl:value-of select="@uni"/></uni>
<class><xsl:value-of select="@class"/></class>
<pos><xsl:value-of select="@opos"/></pos>
<xsl:element name="image"><xsl:attribute name="href"><xsl:copy-of select="$photo_location" />player/<xsl:value-of select="@uni"/>.jpg</xsl:attribute></xsl:element>
</player>
</xsl:if>
</xsl:for-each>
</O_Starters>
<!-- O Starters -->
</xsl:element>
</xsl:for-each>
<!-- Teams -->
</football>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment