Frost.xsl

From Earth Science Information Partners (ESIP)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:os="http://a9.com/-/spec/opensearch/1.1/"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="/OpenSearchDescription/os:Url" />
</body>
</html>
</xsl:template>

<xsl:template match="os:Url">
<xsl:variable name="urlbase" select="substring-before(@template,'?')"/>
<form name="opensearch" method="get" action="{$urlbase}">
<xsl:variable name="params" select="substring-after(@template,'?')"/>
<xsl:call-template name="clip">
  <xsl:with-param name="text"><xsl:value-of select="$params"/></xsl:with-param>
</xsl:call-template>
<hr/>
<input type="submit" value="Submit"/>
</form>
</xsl:template>
<xsl:template name="clip">
  <xsl:param name="text"/>
  <xsl:variable name="piece" select="substring-before($text,'&')"/>
  <xsl:variable name="rest" select="substring-after($text,'&')"/>
  <xsl:if test="string-length($rest)>1">
    <xsl:call-template name="clip">
    <xsl:with-param name="text"><xsl:value-of select="$rest"/></xsl:with-param>
    </xsl:call-template>
  </xsl:if>

  <xsl:choose>
    <xsl:when test="string-length($piece)>0">
      <xsl:call-template name="field">
        <xsl:with-param name="ftext"><xsl:value-of select="$piece"/></xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="string-length($text)>0">
      <xsl:call-template name="field">
        <xsl:with-param name="ftext"><xsl:value-of select="$text"/></xsl:with-param>
      </xsl:call-template>
    </xsl:when>
  </xsl:choose>

</xsl:template>

<xsl:template name="field">
  <xsl:with-param name="ftext"/>
  <xsl:variable name="fname" select="substring-before($ftext,'=')"/>
  <xsl:variable name="ftype" select="substring-after($ftext,'=')"/>
  <xsl:choose>
    <xsl:when test="contains($ftype,'geo:box')">
      Spatial Box (west,south,east,north): <input name="{$fname}"/><br/>
    </xsl:when>
    <xsl:when test="contains($ftype,'time:start')">
      Start Time (yyyy-mm-ddThh:mm:ssZ): <input name="{$fname}"/><br/>
    </xsl:when>
    <xsl:when test="contains($ftype,'time:end')">
      End Time (yyyy-mm-ddThh:mm:ssZ): <input name="{$fname}"/><br/>
    </xsl:when>
    <xsl:when test="contains($ftype,'count')">
      Max results: <input name="{$fname}"/><br/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$fname"/>: <xsl:value-of select="$ftype"/>
      <input type="hidden" value="{$ftype}" name="{$fname}"/><br/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>