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
)
public void AddParam (
	String name, 
	String namespaceUri, 
	Object parameter
)
public function AddParam (
	name : String, 
	namespaceUri : String, 
	parameter : Object
)
Not applicable.

Parameters

name

The name to associate with the parameter.

namespaceUri

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

parameter

The parameter value or object to add to the list.

Exception typeCondition

ArgumentException

The namespaceUri is either a null reference (Nothing in Visual Basic) 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)

String

Boolean (XPath)

Boolean

Number (XPath)

Double

Result Tree Fragment (XSLT)

XPathNavigator

Node Set (XPath)

XPathNodeIterator

XPathNavigator[]

Node* (XPath)

XPathNavigator

*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:

  • CLR numeric types are converted to Double.

  • The DateTime type is converted to String.

  • IXPathNavigable types are converted to XPathNavigator. XPathNavigator[] is converted to XPathNodeIterator.

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();
      xslt.Load("order.xsl");

      // 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.
     xslt.Transform("order.xml", xslArg, XmlWriter.Create("output.xml"));
    
  }
}

import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.XPath.*;
import System.Xml.Xsl.*;

public class Sample
{

    public static void main(String[] args)
    {
        // Create the XslCompiledTransform and load the styleSheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load("order.xsl");

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

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

        // Transform the file.
        xslt.Transform("order.xml", xslArg, XmlWriter.Create("output.xml"));
  
    } //main 
} //Sample

The example uses the following two data files as input.

order.xml

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

order.xsl

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: