Blog
RSS feed

Using the API Version 2.0 Beta with ASP+XSL

Here's an example of good ole ASP+XSL.

It should run on Internet Information Server 4 or any more recent version, and Windows NT4 or any more recent version of Windows (with ASP on, of course).

--Alessandro

 

<%@ Language=VBScript %>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Untitled Page</title>

</head>

<body>

<%query = request("query") %>

<%AppID = "YourAppID" %>

<form name="xmlForm" action="filename.asp" method="post">

<input type="text" name="query" value="<%= query %>"/>

<input type="submit" name="searchBtn" value="Search"/>

<%

If query<>"" Then

xslt = "webLS.xslt"

Set xsldoc = Server.CreateObject("MSXML2.DOMDocument")

fullurl = "http://api.search.live.net/xml.aspx?sources=web&appid=" & AppID & "&query=" & query

Set webreq = Server.CreateObject("MSXML2.XMLHTTP.3.0")

webreq.Open "GET", fullurl, False 'synchronous request

webreq.send

If webreq.status = 200 Then

xsldoc.async = false

boolXSLLoad = xsldoc.load(server.mappath(xslt))

If boolXSLLoad = False Then

response.write "Cannot load XSL sheet"

Else

response.write webreq.responseXML.transformNode(xsldoc)

End If

End If

End If

%>

</form>

</body>

</html>

webLS.xslt:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"

xmlns:web="http://schemas.microsoft.com/LiveSearch/2008/04/XML/web"

xmlns:srch="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element"

>

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">

<xsl:apply-templates select="srch:SearchResponse/web:Web"/>

</xsl:template>

<xsl:template match="web:Web">

<p>displaying result <xsl:value-of select="web:Offset+1"/> to <xsl:value-of select="count(//web:WebResult)+web:Offset"/> out of <xsl:value-of select="web:Total"/>

</p>

<xsl:apply-templates select="web:Results"/>

</xsl:template>

<xsl:template match="web:Results">

<ul>

<xsl:apply-templates select="web:WebResult"/>

</ul>

</xsl:template>

<xsl:template match="web:WebResult">

<li>

<a>

<xsl:attribute name="href">

<xsl:value-of select="web:Url"/>

</xsl:attribute>

<xsl:value-of select="web:Title"/>

</a>

<br/>

<xsl:value-of select="web:Description"/>

</li>

</xsl:template>

</xsl:stylesheet>

Published Thursday, January 22, 2009 5:41 PM by ianwh