Stock Quote Web Part
Adding a Stock Quote Web Part to a SharePoint master page is relatively easy. The only things you need are a WSDL location, SharePoint Designer, and a little XSLT transformation. For this example I used a free web service provided by webserviceX (http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=19). Follow the steps below to add the Stock Quote Web Service to your SharePoint master page.
1) Open your site in SharePoint Designer.
2) Open your master page.
3) Find a place in the master page where you think you want to drop a Data View web part for the stock quote. I typically store the web part somewhere in the Global Navigation Place Holder.
4) Click on Data View -> Insert Data View.
- Now that the data view web part is in place you need to add a web service.
5) Click on Task Panes -> Data Source Library.
6) In the Data Source Library under XML Web Services click "Connect to a web service."
7) Enter the WSDL location (http://www.webservicex.net/stockquote.asmx?wsdl
for this example), and click the button "Connect Now"
- For the Port I use StockQuoteSoap and for the operation I use GetQuote.
8) In the parameters section double click the name "symbol" and enter a valid ticker symbol for the value (such as GE). Click OK. Click OK again to complete the web service.
9) In the Data Source Library Task Pane you will notice your web service under XML Web Services. Hover over this newly created web service and from the drop down click "Show Data."
10) In the Data Source Details Task Pane drag the data source field over to the Data View Web Part that you created in Step 4. You should now see some XML displayed as text in your data view web part. This is the response string from the WSDL location.
11) To format the XML you can use my XSLT code provided below. My code simply pulls out the Ticker Symbol, Date, Time, Current Price, Change, and appends NYSE to the front of it. My code will also format the Change number to be green if it's an up tick and red if it's a down tick.
You're all set. Enjoy.
Here's the code:
<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="StockQuote on
www.webservicex.net" __markuptype="vsattributemarkup" __WebPartId="{B322ED63-C87B-40BE-B261-D4DC0E613B94}" id="g_b322ed63_c87b_40be_b261_d4dc0e613b94" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
<DataSources><SharePoint:SoapDataSource runat="server" id="SoapDataSource2" AuthType="None" WsdlPath="
http://www.webservicex.net/stockquote.asmx?WSDL" SelectUrl="
http://www.webservicex.net/stockquote.asmx" SelectAction="
http://www.webserviceX.NET/GetQuote" SelectPort="StockQuoteSoap" SelectServiceName="StockQuote"><SelectCommand><soap:Envelope xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetQuote xmlns="
http://www.webserviceX.NET/"><symbol>GE</symbol></GetQuote></soap:Body></soap:Envelope></SelectCommand></SharePoint:SoapDataSource></DataSources>
<datafields>ddw1:GetQuoteResult,GetQuoteResult;</datafields>
<XSL><xsl:stylesheet xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:ddw1="
http://www.webserviceX.NET/" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="
http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="
http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="
http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">RepForm3</xsl:variable>
<xsl:variable name="Rows" select="/soap:Envelope/soap:Body/ddw1:GetQuoteResponse"/>
<table border="0" width="100%">
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<td>
<table align="right" border="0" cellspacing="0" width="320px">
<tr>
<xsl:variable name="StockChange" select="substring-after(substring-before(ddw1:GetQuoteResult, '</Change'),'Change>')"></xsl:variable>
<td width="40px" style="text-align:center"><span class="Ticker">NYSE:</span></td>
<td width="30px" style="text-align:center">
<span class="Ticker"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Symbol'),'Symbol>')" /></span></td>
<td width="80px" style="text-align:center">
<span class="Ticker"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Date'),'Date>')" /></span></td>
<td width="60px" style="text-align:center">
<span class="Ticker"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Time'),'Time>')" /></span></td>
<td width="50px" style="text-align:center">
<span class="Ticker"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Last'),'Last>')" /></span></td>
<xsl:choose>
<xsl:when test="contains($StockChange,'+')">
<td width="50px" style="text-align:center">
<span class="UpTick"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Change'),'Change>')" /></span>
</td>
</xsl:when>
<xsl:when test="contains($StockChange,'-')">
<td width="50px" style="text-align:center">
<span class="DownTick"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Change'),'Change>')" /></span>
</td>
</xsl:when>
<xsl:otherwise>
<td width="50px" style="text-align:center">
<span class="Ticker"><xsl:value-of select="substring-after(substring-before(ddw1:GetQuoteResult, '</Change'),'Change>')" /></span>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<tr>
<td colspan="99" class="ms-vb">
<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>
</td>
</tr>
</xsl:if>
</table>
</td>
</tr>
</xsl:template>
</xsl:stylesheet></XSL>
<parameterbindings>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</parameterbindings></We