Custom Web Publishing Guide

Table Of Contents
78 FileMaker Server Advanced Custom Web Publishing Guide
The example below shows a JavaScript XSLT extension function that retrieves a current stock price from
Yahoo and makes it available via an XPath function:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
exclude-result-prefixes="xsl fmxslt fmrs xalan fmp-ex"
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fmrs="http://www.filemaker.com/xml/fmresultset"
xmlns:fmxslt="xalan://com.fmi.xslt.ExtensionFunctions"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:fmp-ex="ext1"
>
<?xslt-cwp-query params="-grammar=fmresultset&-process" ?>
<xsl:output method="html"/>
<xalan:component prefix="fmp-ex" functions="include get_quote" >
<xalan:script lang="javascript">
function include(url) {
var dest = new java.net.URL(url);
var dis = new java.io.DataInputStream(dest.openStream());
var res = "";
while ((line = dis.readLine()) != null)
{
res += line + java.lang.System.getProperty("line.separator");
}
dis.close();
return res;
}
function get_quote(ticker) {
url = "http://quote.yahoo.com/d/quotes.csv?s=”+
"+ticker+"&amp;f=l1gh&amp;e=.csv";
csv_file = include(url);
var str_tokenizer = new java.util.StringTokenizer(csv_file, ',');
// the first token is the last trade price
var last = str_tokenizer.nextToken();
return last;
}
</xalan:script>
</xalan:component>