J
jose.jeria
XML file:
http://www.jeria.net/XSLT/xml/airports_new.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<airports>
<airport>
<Input_String>BER</Input_String>
<string_priority>39</string_priority>
<code>BER</code>
<City_Interface>Berlin</City_Interface>
<Airport>(Alle Flughäfen)</Airport>
<country_int>Deutschland</country_int>
<Display_Type>2</Display_Type>
<Language>de</Language>
</airport>
<airport>
<Input_String>BUH</Input_String>
<string_priority>26</string_priority>
<code>BUH</code>
<City_Interface>Bukarest</City_Interface>
<Airport>(Alle Flughäfen)</Airport>
<country_int>Rumänien</country_int>
<Display_Type>2</Display_Type>
<Language>de</Language>
</airport>
<!-- and so on, up to 8000 entries -->
</airports>
XSL file to search (works fine) the element "Input_String":
http://www.jeria.net/XSLT/xml/airports.xsl
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput
media-type="text/xml"
method="html"
encoding="UTF-8"/>
<xslaram name="queryString"/>
<xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lowerCase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="query" select="translate($queryString, $upperCase,
$lowerCase)"/>
<xsl:template match="/">
<html>
<head>
<title>Search results</title>
</head>
<body>
<xsl:apply-templates select="airports/airport">
<xsl:sort data-type="number" select="string_priority"
order="descending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="airport">
<xsl:if test="Input_String[starts-with(translate(., $upperCase,
$lowerCase),$query)]">
<p>
<strong>Input String:</strong> <xsl:value-of
select="Input_String"/><br/>
<strong>Priority:</strong> <xsl:value-of
select="string_priority"/><br/>
<strong>Airport:</strong> <xsl:value-of select="Airport"/><br/>
<strong>Country:</strong> <xsl:value-of select="country_int"/><br/>
<strong>City:</strong> <xsl:value-of select="City_Interface"/><br/>
<strong>Code:</strong> <xsl:value-of select="code"/><br/>
</p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The result can be seen here:
http://www.jeria.net/XSLT/
When I search for example for "ala" (can be tested live on the link
above), the results are sorted by the "string_priority".
What I would like to do is to show the direct matches on top. This
would be the highest priority. So when i search for "ala", it should be
the nr one hit, not the second one like in this case.
How can I solved this? By having a xsl:choose in the airport template?
http://www.jeria.net/XSLT/xml/airports_new.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<airports>
<airport>
<Input_String>BER</Input_String>
<string_priority>39</string_priority>
<code>BER</code>
<City_Interface>Berlin</City_Interface>
<Airport>(Alle Flughäfen)</Airport>
<country_int>Deutschland</country_int>
<Display_Type>2</Display_Type>
<Language>de</Language>
</airport>
<airport>
<Input_String>BUH</Input_String>
<string_priority>26</string_priority>
<code>BUH</code>
<City_Interface>Bukarest</City_Interface>
<Airport>(Alle Flughäfen)</Airport>
<country_int>Rumänien</country_int>
<Display_Type>2</Display_Type>
<Language>de</Language>
</airport>
<!-- and so on, up to 8000 entries -->
</airports>
XSL file to search (works fine) the element "Input_String":
http://www.jeria.net/XSLT/xml/airports.xsl
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput
media-type="text/xml"
method="html"
encoding="UTF-8"/>
<xslaram name="queryString"/>
<xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lowerCase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="query" select="translate($queryString, $upperCase,
$lowerCase)"/>
<xsl:template match="/">
<html>
<head>
<title>Search results</title>
</head>
<body>
<xsl:apply-templates select="airports/airport">
<xsl:sort data-type="number" select="string_priority"
order="descending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="airport">
<xsl:if test="Input_String[starts-with(translate(., $upperCase,
$lowerCase),$query)]">
<p>
<strong>Input String:</strong> <xsl:value-of
select="Input_String"/><br/>
<strong>Priority:</strong> <xsl:value-of
select="string_priority"/><br/>
<strong>Airport:</strong> <xsl:value-of select="Airport"/><br/>
<strong>Country:</strong> <xsl:value-of select="country_int"/><br/>
<strong>City:</strong> <xsl:value-of select="City_Interface"/><br/>
<strong>Code:</strong> <xsl:value-of select="code"/><br/>
</p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The result can be seen here:
http://www.jeria.net/XSLT/
When I search for example for "ala" (can be tested live on the link
above), the results are sorted by the "string_priority".
What I would like to do is to show the direct matches on top. This
would be the highest priority. So when i search for "ala", it should be
the nr one hit, not the second one like in this case.
How can I solved this? By having a xsl:choose in the airport template?