Export (0) Print
Expand All

XsltArgumentList.AddParam Method

Adds a parameter to the XsltArgumentList and associates it with the namespace qualified name.

Namespace:  System.Xml.Xsl
Assembly:  System.Xml (in System.Xml.dll)

public void AddParam(
	string name,
	string namespaceUri,
	Object parameter


Type: System.String

The name to associate with the parameter.

Type: System.String

The namespace URI to associate with the parameter. To use the default namespace, specify an empty string.

Type: System.Object

The parameter value or object to add to the list.


The namespaceUri is either null or http://www.w3.org/1999/XSL/Transform.

The name is not a valid name according to the W3C XML specification.

The namespaceUri already has a parameter associated with it.

The parameter should correspond to a W3C type. The following table shows the W3C types, either XPath or XSLT, and the corresponding.NET class.

W3C Type

Equivalent.NET Class (Type)

String (XPath)


Boolean (XPath)


Number (XPath)


Result Tree Fragment (XSLT)


Node Set (XPath)



Node* (XPath)


*This is equivalent to a node set that contains a single node.

If the parameter object being invoked from within the style sheet is not one of the above, it is converted according to the following rules:

All other types throw an error.

The following example uses the AddParam method to create a parameter representing the current date and time.

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;

public class Sample

    public static void Main()

        // Create the XslCompiledTransform and load the stylesheet.
        XslCompiledTransform xslt = new XslCompiledTransform();

        // Create the XsltArgumentList.
        XsltArgumentList xslArg = new XsltArgumentList();

        // Create a parameter which represents the current date and time.
        DateTime d = DateTime.Now;
        xslArg.AddParam("date", "", d.ToString());

        // Transform the file. 
        using (XmlWriter w = XmlWriter.Create("output.xml"))
            xslt.Transform("order.xml", xslArg, w);

The example uses the following two data files as input.


<!--Represents a customer order-->
  <book ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
  <cd ISBN='2-3631-4'>


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="date"/>
  <xsl:template match="/">
      <date><xsl:value-of select="$date"/></date>
      <total><xsl:value-of select="sum(//price)"/></total>

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft