Converts an XML schema duration value or XML schema string representation of a duration into a number of seconds. Returns the equivalent number of seconds and fractions of a second, resolving the duration against the current datetime and timezone.
pipeline:duration-to-seconds [duration]
Name | Description | Type | Use |
---|---|---|---|
duration | An xs:duration value, a string or an empty sequence | xs:string |
The following example shows how to use the function to set the timeToLive value to 1 day, 2 hours, 30 minutes and 10 seconds without having to manually convert that value to seconds. xs:duration() is an XPath function. Refer to XQuery 1.0 and XPath 2.0 Functions and Operators to learn more about it.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
xmlns:pipeline="http://www.volantis.com/xmlns/marlin-pipeline"
xmlns:webd="http://www.volantis.com/xmlns/marlin-web-driver"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<title>Pipeline cache</title>
</head>
<body>
<div>
<pipeline:cache name="jiveCache">
<pipeline:cacheInfo>
<pipeline:cacheKey value="weatherConditions"/>
<pipeline:cacheControl timeToLive="%{pipeline:duration-to-seconds(xs:duration('P1DT2H30M10S'))}"/>
</pipeline:cacheInfo>
<pipeline:cacheBody>
<pipeline:transform href="test.xsl" cache="true" compilable="false">
<webd:get url="http://weather.yahooapis.com/forecastrss">
<webd:parameters>
<webd:parameter name="p" value="USWA0395"/>
<webd:parameter name="u" value="c"/>
</webd:parameters>
</webd:get>
</pipeline:transform>
</pipeline:cacheBody>
</pipeline:cache>
</div>
</body>
</html>
Where, the test.xsl XSL transformation must contain the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
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="/">
<div class="company_item" xmlns="http://www.w3.org/2002/06/xhtml2">
<h3 class="company_header">
<xsl:value-of select="/rss/channel/item/title"/>
</h3>
<div>
<h4>Current Conditions:</h4>
<p><xsl:value-of select="/rss/channel/item/yweather:condition/@text"/>,
<xsl:value-of
select="/rss/channel/item/yweather:condition/@temp"/>
<xsl:value-of select="/rss/channel/yweather:units/@temperature"/></p>
<h4>Forecast:</h4>
<xsl:for-each select="/rss/channel/item/yweather:forecast">
<p>
<xsl:value-of select="current()/@day"/> - <xsl:value-of
select="current()/@text"/>.
High: <xsl:value-of select="current()/@high"/>
<xsl:value-of select="/rss/channel/yweather:units/@temperature"/> Low:
<xsl:value-of select="current()/@low"/>
<xsl:value-of select="/rss/channel/yweather:units/@temperature"/>
</p>
</xsl:for-each>
</div>
</div>
</xsl:template>
</xsl:stylesheet>