請增加紅色的文字, 到你的 xsl 裡.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:user-namespace-here" version="1.0">
xsl 呼叫範例:
<xsl:value-of select="user:distance(concat($lat1,''),concat($lon1,''),concat($lat2,''),concat($lon2,''))"/> 公尺
xsl 的 javascript function:
<msxsl:script language="JScript" implements-prefix="user"> <![CDATA[ function distance(lat1,lon1,lat2,lon2) { var R = 6371; var dLat = (lat2-lat1) * Math.PI / 180; var dLon = (lon2-lon1) * Math.PI / 180; var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) * Math.sin(dLon/2) * Math.sin(dLon/2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c; return Math.round(d*1000); } ]]> </msxsl:script>
資料來源:
Calculate distance between two points with latitude and longitude coordinates
http://snipplr.com/view/25479/
+
How to include javaScript file in xslt
http://stackoverflow.com/questions/7444317/how-to-include-javascript-file-in-xslt
沒有留言:
張貼留言