Export (0) Print
Expand All

Using HTML Forms to Post Templates

SQL Server 2000

HTML forms can be used to post templates. The input mechanism of HTML forms can be used to obtain user input for the values of the parameters that can be passed to an SQL statement. In the TEXTAREA element of the HTML form, template is used as the variable name for the NAME attribute. The body of the TEXTAREA is then sent as a value for template.


In the following examples, nwind is a virtual directory created using the IIS Virtual Directory Management for SQL Server utility (any name can be given to a virtual name when it is created). For more information, see Using IIS Virtual Directory Management for SQL Server Utility.

A. Post a simple template in a form

The HTML form in this example prompts the user to enter an employee ID. The ID value is used as an input parameter to the SELECT statement in the template. The query returns the first and last name of employees from the Employees table in the Northwind database. This form can be saved in an .htm file and opened in the browser.

<TITLE>Sample Form </TITLE>
For a given employee ID, employee first and last name is retrieved.
<form action="http://IISServer/nwind" method="POST">
<B>Employee ID Number</B>
<input type=text name=EmployeeID value='1'>
<input type=hidden name=contenttype value=text/xml>
<input type=hidden name=template value='
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
    <sql:param name="EmployeeID">1</sql:param>
  SELECT FirstName, LastName 
  FROM    Employees 
  WHERE    EmployeeID=@EmployeeID 
<p><input type="submit">
B. Post a template in an HTML form and provide an XSL file to process the output

In this example, a simple HTML form is used to post a template. The template contains a SELECT statement that returns first and last names from the Employees table in the Northwind database.

When this HTML document is opened in the browser, the user can specify the content-type and the Extensible Stylesheet Language (XSL) file to process the result set. If the content-type is specified as text/html, the XSL file processes the result set and produces a two-column table as output.

If the content-type is specified as text/xml, the result is displayed in form of an XML document.

Note  The XSL file must reside in the physical directory (or one of its subdirectories) associated with the virtual directory. If the file is stored in the physical directory, only the file name has to be specified. If the file is stored in one of the subdirectories of the physical directory, the directory path relative to the physical directory is specified.


Hi there

<form action="http://IISServer/nwind" method="POST">


<input name=contenttype value="text/html">



<input name=xsl value="emp.xsl"><br>

<input type=hidden name=template value='


<sql:query xmlns:sql="urn:schemas-microsoft-com:xml-sql">

Select FirstName, LastName from Employees for xml auto</sql:query>



<p><input type="submit">




The XSL file is given below. The XSL transformation is applied to the result set.

<?xml version="1.0"  encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "Employees">
   <TD><xsl:value-of select = "@FirstName" /></TD>
   <TD><B><xsl:value-of select = "@LastName" /></B></TD>

<xsl:template match = "/">
    <STYLE>th { background-color: #CCCCCC }</STYLE>
   <TABLE border="1" style="width:300;">
   <TR><TH colspan="2">Employees</TH></TR>
   <TR><TH >FirstName</TH><TH>LastName</TH></TR>
   <xsl:apply-templates select = "ROOT" />

See Also

Using IIS Virtual Directory Management for SQL Server Utility

Accessing SQL Server Using HTTP

Retrieving XML Documents Using FOR XML

Using XPath Queries

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft