Re: [xsl] Closest matching value

Subject: Re: [xsl] Closest matching value
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 10 May 2004 22:07:27 +0100
Hi Stuart,

> My xsl doc contains a variable holding the Request URI. I want to
> select the controller in the domain which contains the closest
> matching url value (url values are unique) for the Request URI.

Your definition of "closest matching" seems to be "the longest url
that matches the start of RequestURI". Assuming the request URI is
held in a variable called $RequestURI, you can get this by selecting
the <domain> elements where $RequestURI starts with the value of their
<url> child, sorting them in descending order by the string length of
the url, selecting the first one, and getting its <controller>:

  <xsl:for-each select="/root/domain[starts-with($RequestURI, url)]">
    <xsl:sort select="string-length(url)" data-type="number"
              order="descending" />
    <xsl:if test="position() = 1">
      <xsl:value-of select="controller" />
    </xsl:if>
  </xsl:for-each>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread