Pass parameters to XSLT document
XSLTParameter.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
string xmlPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
string xsltPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xslt";
XPathDocument xPathDoc = new XPathDocument(xmlPath);
XslCompiledTransform transform = new XslCompiledTransform();
XsltArgumentList xsltArgsList = new XsltArgumentList();
xsltArgsList.AddParam("discount", "", ".50");
transform.Load(xsltPath);
transform.Transform(xPathDoc, xsltArgsList, Response.Output);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>asp.net and XSLT - How to pass parameters to an XSLT document</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
ITBookList.xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name="discount" select=".25"/>
<xsl:template match="/">
<html>
<head>
<title>XSLT xsl:param - How to use parameter in xslt</title>
</head>
<body>
<h2 style="color:Crimson; font-style:italic;">asp.net and XSLT Example: Passing Parameters to XSLT File</h2>
<hr width="700" align="left" color="Orange" />
<br />
<table border="1" cellpadding="5" cellspacing="0" bordercolor="Salmon">
<tr bgcolor="DarkSalmon" style="color:White; font-weight:bold">
<td>Book ID</td>
<td>Name of Book</td>
<td>Name of Author</td>
<td>Price</td>
<td>Discount</td>
</tr>
<xsl:for-each select="books/book">
<tr bgcolor="Snow" style="color:DeepPink; font-weight:normal">
<td height="10">
<xsl:value-of select="id"/>
</td>
<td height="10">
<xsl:value-of select="name"/>
</td>
<td height="10">
<xsl:value-of select="author"/>
</td>
<td height="10">
<xsl:value-of select="price"/>
</td>
<td height="10" style="font-weight:bold;">
<xsl:value-of select="price * ($discount)"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ITBookList.xml
<?xml version="1.0" ?>
<!-- Sample XML file for various XML, XSLT, XPath example-->
<books>
<book Category="XML and XSLT">
<id>1</id>
<name>Beginning XML Databases</name>
<author>Gavin Powell</author>
<price>39.99</price>
</book>
<book Category="asp.net">
<id>2</id>
<name>ASP.NET 3.5 Website Programming: Problem - Design - Solution</name>
<author>Chris Love</author>
<price>44.99</price>
</book>
<book Category="asp.net">
<id>3</id>
<name>jQuery for ASP.NET Developers</name>
<author>Joe Brinkman</author>
<price>6.99</price>
</book>
<book Category="asp.net">
<id>4</id>
<name>ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution</name>
<author>Emad Ibrahim</author>
<price>49.99</price>
</book>
<book Category="XML and XSLT">
<id>5</id>
<name>Beginning XSLT and XPath: Transforming XML Documents and Data</name>
<author>Ian Williams</author>
<price>49.99</price>
</book>
<book Category="XML and XSLT">
<id>6</id>
<name>XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition</name>
<author>Michael Kay</author>
<price>59.99</price>
</book>
<book Category="Database">
<id>7</id>
<name>Professional Microsoft SQL Server 2008 Programming</name>
<author>Robert Vieira </author>
<price>49.99</price>
</book>
</books>

- Sample XML document for XSLT and XML examples
- XSLT output method HTML - How to convert xml document to html
- XSLT xsl:param - How to use parameter in xslt
- XSLT xsl:choose, xsl:when, xsl:otherwise - How to use them in xslt
- XSLT - How to test, evaluate multiple conditions in xslt
- XSLT xsl:element - How to use xsl:element in xslt
- XSLT xsl:apply-templates - How to use xsl:apply-templates in xslt
- asp.net and XSLT - Using XslCompiledTransform Class in asp.net
- Using System.Xml, System.Xml.Xsl, System.Xml.XPath Namespace in asp.net
- asp.net and XPath: evaluate // (relative path) XPath expression