Encapsulates information necessary to access a server-side data source. Refer to the topic entitled cf2:DataSource for more information.
Only the id and href attributes are supported.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
xmlns:ui="http://www.volantis.com/xmlns/2009/07/cf2/ui"
xmlns:cf2="http://www.volantis.com/xmlns/2009/07/cf2"
xmlns:mcs="http://www.volantis.com/xmlns/2006/01/xdime/mcs"
xmlns:cst="http://www.volantis.com/xmlns/2009/07/cf2/template">
<head>
<title>cf2:data-source</title>
</head>
<body>
<div>
<cf2:data-source id="data-source" href="template.xdtpl">
<cf2:param name="location" type="string"/>
<cf2:param name="units" type="string"/>
</cf2:data-source>
<div>
<ui:button>
<cf2:on event="cf2:activate">
<cf2:param name="source" component="data-source"/>
<cf2:param name="template" property="template#data"/>
source.fetch({
parameters: {
location: 'USWA0395',
units: 'c'
},
onSuccess: function(e) {
template.set({ok: true, data: e.data});
},
onFailure: function(e) {
template.set({ok: false, status: e.status, message: e.message});
}
});
</cf2:on>
Update
</ui:button>
</div>
<cst:template id="template">
<cst:switch path="ok">
<cst:case boolean="true">
<div>
<cst:value path="data.location"/>
</div>
<div>
<cst:value path="data.conditions"/>, Temperature: <cst:value path="data.temperature"/><cst:value path="data.units"/>
</div>
</cst:case>
<cst:case boolean="false">
<div>
<cst:value path="status"/>
</div>
<div>
<cst:value path="message"/>
</div>
</cst:case>
</cst:switch>
</cst:template>
</div>
</body>
</html>
The template.xdtpl template must have the following form.
<?xml version="1.0" encoding="UTF-8"?>
<template:definition xmlns="http://www.w3.org/2002/06/xhtml2"
xmlns:template="http://www.volantis.com/xmlns/marlin-template"
xmlns:json="http://www.volantis.com/xmlns/2009/07/json"
xmlns:pipeline="http://www.volantis.com/xmlns/marlin-pipeline"
xmlns:webd="http://www.volantis.com/xmlns/marlin-web-driver">
<template:documentation> </template:documentation>
<template:declarations>
<template:parameter name="location" type="simple" expressionVariable="location"/>
<template:parameter name="units" type="simple" expressionVariable="units"/>
</template:declarations>
<template:body>
<pipeline:transform href="test.xsl">
<webd:get url="http://weather.yahooapis.com/forecastrss">
<webd:parameters>
<webd:parameter name="p" value="%{$location}"/>
<webd:parameter name="u" value="%{$units}"/>
</webd:parameters>
</webd:get>
</pipeline:transform>
</template:body>
</template:definition>
The test.xsl transform must have the following form.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:json="http://www.volantis.com/xmlns/2009/07/json"
xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<xsl:output method="xml"/>
<xsl:template match="/">
<json:response>
<json:object>
<json:property name="location">
<json:string>
<xsl:value-of select="/rss/channel/item/title"/>
</json:string>
</json:property>
<json:property name="conditions">
<json:string>
<xsl:value-of select="/rss/channel/item/yweather:condition/@text"/>
</json:string>
</json:property>
<json:property name="temperature">
<json:string>
<xsl:value-of select="/rss/channel/item/yweather:condition/@temp"/>
</json:string>
</json:property>
<json:property name="units">
<json:string>
<xsl:value-of select="/rss/channel/yweather:units/@temperature"/>
</json:string>
</json:property>
</json:object>
</json:response>
</xsl:template>
</xsl:stylesheet>