[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Closest matching value

Subject: Re: Closest matching value
From: "Stuart Robinson" <serob@xxxxxxxxxxx>
Date: Mon, 10 May 2004 22:29:26 +0100
stuart robinson
Thank you Jeni, I like your solution. I hadn't used starts-with() before,
handy function. Cheers.


----- Original Message ----- 
From: "Jeni Tennison" <jeni@xxxxxxxxxxxxxxxx>
To: "Stuart Robinson" <serob@xxxxxxxxxxx>
Cc: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, May 10, 2004 10:07 PM
Subject: Re:  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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.