Building a Stock Ticker Web Part
For publicly traded companies it is also desirable to display the current stock quote information. Like the Weather Web Part previously configured, there are many publicly available services that can provide this information. For this example, we will query a REST based service provided by Yahoo having the following address:
Approach
The stock quote information can be shown in a number of different ways. In cases where the information needs to be on every page, it should be added to a container on the Master Page with the s4-notdlg
style reference previously included in the Building an Appropriate Use and Incident dialog section. For this example though, we will include it as an XML Web Part configured in a similar way to the Weather Web Part previously reviewed.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result- prefixes="msxsl"> <xsl:output method="html" indent="yes"/> <xsl:template name="main"> <xsl:variable name="symbol" select="results/quote/Symbol"/> <xsl:variable name="price" select="results/quote/LastTradePriceOnly"/> <xsl:variable name="change" select="results/quote/Change_PercentChange"/> <div id="stockInfo" style="font-size:10pt"> <xsl:value-of select="$symbol" /> <xsl:text> $</xsl:text> <xsl:value-of select="$price" /> <xsl:text> </xsl:text> <xsl:value-of select="$change" /> <xsl:text> </xsl:text> <xsl:choose> <xsl:when test="contains($change,'+')" > <img src="http://intranet/Style%20Library/Images/stock_up.png" border="0" alt="Trending Up"></img> </xsl:when> <xsl:otherwise> <img src="http://intranet/Style%20Library/Images/stock_down.png" border="0" alt="Trending Down"></img> </xsl:otherwise> </xsl:choose> </div> </xsl:template> <xsl:template match="/*"> <xsl:call-template name="main"/> </xsl:template> </xsl:stylesheet>
Stock Quote Web Part displayed
A rendered version of the current Stock Ticker Web Part can be displayed in the following screenshot: