Share via


XsltArgumentList.AddParam(String, String, Object) Método

Definição

Adiciona um parâmetro ao XsltArgumentList e o associa ao nome qualificado de namespace.

public:
 void AddParam(System::String ^ name, System::String ^ namespaceUri, System::Object ^ parameter);
public void AddParam (string name, string namespaceUri, object parameter);
member this.AddParam : string * string * obj -> unit
Public Sub AddParam (name As String, namespaceUri As String, parameter As Object)

Parâmetros

name
String

O nome a ser associado ao parâmetro.

namespaceUri
String

O URI de namespace a ser associado ao parâmetro. Para usar o namespace padrão, especifique uma cadeia de caracteres vazia.

parameter
Object

O valor do parâmetro ou o objeto a ser adicionado à lista.

Exceções

O namespaceUri é null ou http://www.w3.org/1999/XSL/Transform.

O name não é um nome válido de acordo com a especificação W3C XML.

O namespaceUri já tem um parâmetro associado a ele.

Exemplos

O exemplo a seguir usa o AddParam método para criar um parâmetro que representa a data e a hora atuais.

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.
        using (XmlWriter w = XmlWriter.Create("output.xml"))
        {
            xslt.Transform("order.xml", xslArg, w);
        }
    }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl

Public Class Sample

    Public Shared Sub Main()

        ' Create the XslCompiledTransform and load the stylesheet.
        Dim xslt As New XslCompiledTransform()
        xslt.Load("order.xsl")

        ' Create the XsltArgumentList.
        Dim xslArg As New XsltArgumentList()

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

        Using w As XmlWriter = XmlWriter.Create("output.xml")
            ' Transform the file.
            xslt.Transform("order.xml", xslArg, w)
        End Using

    End Sub
End Class

O exemplo usa os dois arquivos de dados a seguir como entrada.

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>

Comentários

O parameter deve corresponder a um tipo W3C. A tabela a seguir mostra os tipos W3C, XPath ou XSLT e a classe corresponding.NET.

Tipo W3C Classe Equivalent.NET (Tipo)
String (XPath) String
Boolean (XPath) Boolean
Number (XPath) Double
Result Tree Fragment (XSLT) XPathNavigator
Node Set (XPath) XPathNodeIterator

XPathNavigator[]
Node* (XPath) XPathNavigator

os *This são equivalentes a um nó definida que contém um único nó.

Se o objeto de parâmetro que está sendo invocado de dentro da folha de estilos não for um dos acima, ele será convertido de acordo com as seguintes regras:

Todos os outros tipos lançam um erro.

Aplica-se a

Confira também