XQuery has been known as a language for querying XML, but it even can be a server-side scripting language for dynamic web application. This paper proposes an approach based on XQuery language for implementing web searching. It describes how to create XQuery application and perform web queries. XQuery scripts can be compiled into server-side executable Servlets that can access web requests, query XML, afterwards generate HTML pages including the result, and finally respond to the users. By means of an actual example of web searching within an on-line library, it describes and analyses the process that includes building XQuery application environment, implementing online searching and session tracking. As a result, the approach using XQuery can successfully attain efficient searching on the web.