XSLT for importing StatCrew Volleyball 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:///user/gilm6123/desktop/StatCrewXML/images/'"/> | |
<xsl:template match="/"> | |
<volleyball> | |
<!-- Format date from mm/dd/yyyy --> | |
<xsl:variable name="tempdate" select="/vbgame/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 Information --> | |
<game_info> | |
<gameid> | |
<xsl:value-of select="/vbgame/venue/@gameid"/> | |
</gameid> | |
<date> | |
<xsl:value-of select="@fdate"/> | |
</date> | |
<city> | |
<xsl:value-of select="/vbgame/venue/@location"/> | |
</city> | |
<arena> | |
<xsl:value-of select="/vbgame/venue/@arena"/> | |
</arena> | |
<location><xsl:value-of select="/vbgame/venue/@arena"/>, <xsl:value-of select="/vbgame/venue/@location"/></location> | |
<start> | |
<xsl:value-of select="/vbgame/venue/@start"/> | |
</start> | |
<attendance> | |
<xsl:value-of select="/vbgame/venue/@attend"/> | |
</attendance> | |
</game_info> | |
<!-- Game Information --> | |
<!-- Teams --> | |
<xsl:for-each select="/vbgame/team"> | |
<xsl:element name="{@vh}"> | |
<info> | |
<id> | |
<xsl:value-of select="@id"/> | |
</id> | |
<name> | |
<xsl:value-of select="@name"/> | |
</name> | |
<code> | |
<xsl:value-of select="@code"/> | |
</code> | |
<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> | |
<kills> | |
<xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/kills_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/attack/@k div 10)"/>.png</xsl:attribute> | |
</kills> | |
<blocks> | |
<xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/kills_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/block/@tb)"/>.png</xsl:attribute> | |
</blocks> | |
<aces> | |
<xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/aces_<xsl:value-of select="@vh"/>_<xsl:value-of select="totals/serve/@sa"/>.png</xsl:attribute> | |
</aces> | |
<attack_pct> | |
<xsl:attribute name="href"><xsl:value-of select="$photo_location"/>graph/third_conv_<xsl:value-of select="@vh"/>_<xsl:value-of select="round(totals/attack/@pct *10)"/>.png</xsl:attribute> | |
</attack_pct> | |
</graphs> | |
<!-- Scores --> | |
<scores> | |
<final> | |
<xsl:value-of select="linescore/@score"/> | |
</final> | |
<linescore> | |
<xsl:for-each select="linescore/linegame"> | |
<game> | |
<xsl:element name="points"> | |
<xsl:value-of select="@points"/> | |
</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="@points"/>.png</xsl:attribute> | |
</xsl:element> | |
</game> | |
</xsl:for-each> | |
</linescore> | |
</scores> | |
<!-- Scores --> | |
<!-- Totals --> | |
<totals> | |
<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 --> | |
<!-- Kill Leaders --> | |
<kill_leaders> | |
<xsl:for-each select="player"> | |
<xsl:sort select="attack/@k" data-type="number" order="descending"/> | |
<xsl:if test="not(position() > 5)"> | |
<player> | |
<name> | |
<xsl:value-of select="@name"/> | |
</name> | |
<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> | |
<total_kills> | |
<kills> | |
<xsl:value-of select="attack/@k"/> | |
</kills> | |
<errors> | |
<xsl:value-of select="attack/@e"/> | |
</errors> | |
<attempts> | |
<xsl:value-of select="attack/@ta"/> | |
</attempts> | |
<pct> | |
<xsl:value-of select="attack/@pct"/> | |
</pct> | |
</total_kills> | |
</player> | |
</xsl:if> | |
</xsl:for-each> | |
</kill_leaders> | |
<!-- Kill Leaders --> | |
<!-- Blocking Leaders --> | |
<blocking_leaders> | |
<xsl:for-each select="player"> | |
<xsl:sort select="block/@tb" data-type="number" order="descending"/> | |
<xsl:if test="not(position() > 5)"> | |
<player> | |
<name> | |
<xsl:value-of select="@name"/> | |
</name> | |
<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> | |
<blocking> | |
<solos> | |
<xsl:value-of select="block/@bs"/> | |
</solos> | |
<assists> | |
<xsl:value-of select="block/@ba"/> | |
</assists> | |
<total> | |
<xsl:value-of select="block/@tb"/> | |
</total> | |
</blocking> | |
</player> | |
</xsl:if> | |
</xsl:for-each> | |
</blocking_leaders> | |
<!-- Blocking Leaders --> | |
<!-- Points Leaders --> | |
<points_leaders> | |
<xsl:for-each select="player"> | |
<xsl:sort select="misc/@pts" data-type="number" order="descending"/> | |
<xsl:if test="not(position() > 5)"> | |
<player> | |
<name> | |
<xsl:value-of select="@name"/> | |
</name> | |
<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> | |
<total_points> | |
<kills> | |
<xsl:value-of select="attack/@k"/> | |
</kills> | |
<aces> | |
<xsl:value-of select="serve/@sa"/> | |
</aces> | |
<total_blocks> | |
<xsl:value-of select="block/@tb"/> | |
</total_blocks> | |
</total_points> | |
</player> | |
</xsl:if> | |
</xsl:for-each> | |
</points_leaders> | |
<!-- Points Leaders --> | |
</xsl:element> | |
</xsl:for-each> | |
</volleyball> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment