Author:
phoque
Version:
1.0
Release Date:
31 Jan 2010
Category:
Output

Description

This utility allows you to convert any of the supported currencies in the XML feed of the European Central Bank into each other.

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01"
	xmlns:eurofxref="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">

<!-- Example Call

	<xsl:call-template name="currency-converter">
		<xsl:with-param name="value" select="'1'" />
		<xsl:with-param name="from" select="'EUR'" />
		<xsl:with-param name="to" select="'USD'" />
	</xsl:call-template>

-->

<xsl:template name="currency-converter">
	<xsl:param name="value" />
	<xsl:param name="from" />
	<xsl:param name="to" />
	<xsl:variable name="nodeset" select="document('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml')/gesmes:Envelope/eurofxref:Cube/*" />

	<xsl:variable name="rate-from">
		<xsl:choose>
			<xsl:when test="$from='EUR'">1</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$nodeset/eurofxref:Cube[@currency=$from]/@rate" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="rate-to">
		<xsl:choose>
			<xsl:when test="$to='EUR'">1</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$nodeset/eurofxref:Cube[@currency=$to]/@rate" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:value-of select="$value div $rate-from * $rate-to" />
</xsl:template>

</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details