lookup.key

lookup.key — Retrieve the value associated with a particular key in a table

Description

Given a table of space-delimited key/value pairs, the lookup.key template extracts the value associated with a particular key.

<xsl:template name="lookup.key">
  <xsl:param name="key" select="''"></xsl:param>
  <xsl:param name="table" select="''"></xsl:param>

  <xsl:if test="contains($table, ' ')">
    <xsl:choose>
      <xsl:when test="substring-before($table, ' ') = $key">
        <xsl:variable name="rest" select="substring-after($table, ' ')"></xsl:variable>
        <xsl:choose>
          <xsl:when test="contains($rest, ' ')">
            <xsl:value-of select="substring-before($rest, ' ')"></xsl:value-of>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$rest"></xsl:value-of>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="lookup.key">
          <xsl:with-param name="key" select="$key"></xsl:with-param>
          <xsl:with-param name="table" select="substring-after(substring-after($table,' '), ' ')"></xsl:with-param>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:template>