Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
XSLT for importing StatCrew Basketball 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="/">
<basketball>
<!-- Game Information -->
<game_info>
<gameid><xsl:value-of select="/bbgame/venue/@gameid"/></gameid>
<date><xsl:value-of select="/bbgame/venue/@date"/></date>
<city><xsl:value-of select="/bbgame/venue/@location"/></city>
<stadium><xsl:value-of select="/bbgame/venue/@stadium"/></stadium>
<location><xsl:value-of select="/bbgame/venue/@stadium"/>, <xsl:value-of select="/bbgame/venue/@location"/></location>
<start><xsl:value-of select="/bbgame/venue/@start"/></start>
<attendance><xsl:value-of select="/bbgame/venue/@attend"/></attendance>
<temp><xsl:value-of select="/bbgame/venue/@temp"/></temp>
<wind><xsl:value-of select="/bbgame/venue/@wind"/></wind>
<weather><xsl:value-of select="/bbgame/venue/@weather"/></weather>
<!-- Format date from mm/dd/yyyy -->
<xsl:variable name="tempdate" select="/bbgame/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> <xsl:value-of select="$part2"/>, <xsl:value-of select="$part3"/>
</fdate>
</game_info>
<!-- Game Information -->
<!-- Teams -->
<xsl:for-each select="/bbgame/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>
<ftpct><xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/totoff_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/@ftpct div 700 *10)"/>.png</xsl:attribute></ftpct>
<ast><xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/totoff_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/@ast div 700 *10)"/>.png</xsl:attribute></ast>
<treb><xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/totoff_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/@treb div 700 *10)"/>.png</xsl:attribute></treb>
<to><xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/turnovers_<xsl:value-of select="@vh"/>_<xsl:value-of select="totals/to"/>.png</xsl:attribute></to>
<fgpct><xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/fgpct_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/@fgpct *10)"/>.png</xsl:attribute></fgpct>
<fg3pct><xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/fgpct_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/@fg3pct *10)"/>.png</xsl:attribute></fg3pct>
</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>
<ftpct><xsl:value-of select="totals/@ftpct"/></ftpct>
<treb><xsl:value-of select="totals/@treb"/></treb>
<ast><xsl:value-of select="totals/@ast"/></ast>
<fgpct><xsl:value-of select="totals/@fgpct"/>%</fgpct>
<fg3pct><xsl:value-of select="totals/@fg3pct"/>%</fg3pct>
<to><xsl:value-of select="totals/@to"/></to>
<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 -->
<!-- Scoring Leaders -->
<scoring_leaders>
<xsl:for-each select="player">
<xsl:sort select="stats/@tp" data-type="number" order="descending"/>
<xsl:if test="not(position() &gt; 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"/>.png</xsl:attribute></xsl:element>
<stats>
<tp><xsl:value-of select="stats/@tp"/></tp>
<fgpct><xsl:value-of select="format-number(stats/@fgm div stats/@fga *100, '#')"/></fgpct>
<treb><xsl:value-of select="stats/@treb"/></treb>
<ast><xsl:value-of select="stats/@ast"/></ast>
<min><xsl:value-of select="stats/@min"/></min>
<fg3pct><xsl:value-of select="format-number(stats/@fgm3 div stats/@fga3 *100, '#')"/></fg3pct>
<stl><xsl:value-of select="stats/@stl"/></stl>
<ftpct><xsl:value-of select="format-number(stats/@ftm div stats/@fta *100, '#')"/></ftpct>
<blk><xsl:value-of select="stats/@blk"/></blk>
</stats>
</player>
</xsl:if>
</xsl:for-each>
</scoring_leaders>
<!-- Scoring Leaders -->
</xsl:element>
</xsl:for-each>
<!-- Teams -->
</basketball>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment