Specifying Client Side Formatting For Template Queries
 
In the article titled Understanding Query Templates, we saw the basics of template queries and how to customize the output of these queries by using an XSL stylesheet. In the examples shown, the XSL was applied on the server. But, if the client is XML enabled, we can "shift" the processing of the XSL to the client, thus freeing some resources on the server. To specify client-side processing, the XML template file has to be modified as follows:
 

<?xml-stylesheet type='text/xsl' href='GetAllTitles.xsl'?>
<Titles xmlns:sql='urn:schemas-microsoft-com:xml-sql'>
	<sql:header>
		<sql:param name='title_id'>%</sql:param>
	</sql:header>
	<sql:query>
		SELECT title_id, title, type FROM titles
			WHERE title_id LIKE @title_id
			FOR XML AUTO
	</sql:query>
</Titles>

Note the specification of the "xml-stylesheet" processing instruction. This specifies that the XSL is applied on the client. One caveat to note is that the specification of the stylesheet requires one "extra hit" to the server to download the stylesheet to the client.

Note that if the client is not XML enabled, the stylesheet is ignored.

Home