The Hollywood Stock Exchange (HSX) is a popular online game, allowing players to trade stock in movies and actors. Stock and "Hollywood Dollars" have no real-world value, but HSX sells the resulting data to industry analysts and studios. As a part of their services to players, HSX provide stock data as an XML feed. This XML is used by a number of fan sites that provide movie information, profit calculators, etc. This includes some example XSLT scripts that process the XML feed.
These scripts were originally written to create and monitor a series of HSX Stock Indices. These are similar to real-world stock indices, and are simply the average value of a particular type of stock. The scripts are called each morning, and the indices are saved to a large XML database of daily index data. A second script converts this database into a HTML table fragment. This was displayed on a webpage using Server Side Includes (SSI). A third script summarizes the index data as all-time min/max/average values, also in a HTML table fragment.
The XSLT scripts are included in a download link at the bottom of this page. They include a controlling CSH script,
and an auxiliary PERL script to grab today's date. The actual processing of the HSX XML feed is performed by the
hsx.xsl script. Here it is:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
hsx.xsl - Create Stock Indices from the HSX XML Feed
This XSLT script calculates stock indices from the HSX XML feed, and appends them
(with today's date) to an existing list of index values. See the CSH script
update_stock for an example of its use.
# Copyright and License Notice
# ----------------------------
# Copyright (C) 2006 by Winwaed Software Technology LLC. All rights reserved.
# Some individual files may be covered by other copyrights.
#
# This material was originally written and compiled by Richard Marsden
# of Winwaed Software Technology LLC 2004-6.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that this entire copyright notice
# is duplicated in all such copies.
#
# This software is provided "as is" and without any expressed or implied
# warranties, including, without limitation, the implied warranties of
# merchantibility and fitness for any particular purpose.
* * * Winwaed Software Technology LLC
* * * http://www.winwaed.com
-->
<xsl:template match="/values">
<xsl:text>
</xsl:text>
<xsl:element name="values">
<xsl:text>
</xsl:text>
<xsl:for-each select="value">
<xsl:copy-of select="." />
</xsl:for-each>
<xsl:text>
</xsl:text>
<value>
<xsl:for-each select="document('today.xml')">
<xsl:value-of select="id('today')" />
<xsl:variable name="date" select="today/date" />
<xsl:variable name="day" select="today/day" />
<date><xsl:value-of select="$date" /> </date> <xsl:text>
</xsl:text>
<day><xsl:value-of select="$day" /> </day> <xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:for-each select="document('http://www.hsx.com/xml/export/hsx_mst_list?display_type=xml_download')">
<xsl:value-of select="id('hsx_mst')" />
<xsl:variable name="m_num" select="count( hsx_mst/sec ) " />
<xsl:variable name="m_total" select="sum( hsx_mst/sec/yc) "/>
<movies>
<xsl:attribute name="num"> <xsl:value-of select="$m_num"/> </xsl:attribute>
<xsl:value-of select="round(100* $m_total div $m_num) div 100"/>
</movies>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:for-each select="document('http://www.hsx.com/xml/export/hsx_sbo_list?display_type=xml_download')">
<xsl:value-of select="id('hsx_sbo')" />
<xsl:variable name="s_num" select="count( hsx_sbo/sec ) " />
<xsl:variable name="s_total" select="sum( hsx_sbo/sec/yc) "/>
<bonds>
<xsl:attribute name="num"> <xsl:value-of select="$s_num"/> </xsl:attribute>
<xsl:value-of select="round(100.0* $s_total div $s_num) div 100"/>
</bonds>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:for-each select="document('http://www.hsx.com/xml/export/hsx_fnd_list?display_type=xml_download')">
<xsl:value-of select="id('hsx_fnd')" />
<xsl:variable name="f_num" select="count( hsx_fnd/sec ) " />
<xsl:variable name="f_total" select="sum( hsx_fnd/sec/yc) "/>
<funds>
<xsl:attribute name="num"> <xsl:value-of select="$f_num"/> </xsl:attribute>
<xsl:value-of select="round(100* $f_total div $f_num) div 100"/>
</funds>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:for-each select="document('http://www.hsx.com/xml/export/hsx_opt_list?display_type=xml_download')">
<xsl:value-of select="id('hsx_opt')" />
<xsl:variable name="o_num" select="count( hsx_opt/sec ) " />
<xsl:variable name="o_total" select="sum( hsx_opt/sec/yc) "/>
<options>
<xsl:attribute name="num"> <xsl:value-of select="$o_num"/> </xsl:attribute>
<xsl:value-of select="round(100* $o_total div $o_num) div 100 "/>
</options>
</xsl:for-each>
<xsl:text>
</xsl:text>
</value>
<xsl:text>
</xsl:text>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Download XSLT Scripts and Data (ZIP archive, 26KB)
This archive contains a file entitled readme.txt which describes the files included in it.
All of the XSL scripts were developed against Xalan-C, but should work with most
XSLT processors. The archive also includes XML index data from January 2004 to July 2006.
All of the code in the archive is distributed in an open source BSD-like license, as listed in the above source code.
The Hollywood Stock Exchange site includes lots of information for beginningers, including links to fan sites. Join now - it is free!
The Xalan-C XML Processor was used during the development, testing, and operation of these scripts.