xsl-list
[Top] [All Lists]

Re: Closest matching value

2004-05-10 14:29:26
Thank you Jeni, I like your solution. I hadn't used starts-with() before,
handy function. Cheers.


----- Original Message ----- 
From: "Jeni Tennison" <jeni(_at_)jenitennison(_dot_)com>
To: "Stuart Robinson" <serob(_at_)hotmail(_dot_)com>
Cc: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Monday, May 10, 2004 10:07 PM
Subject: Re: [xsl] Closest matching value


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/



<Prev in Thread] Current Thread [Next in Thread>