Share via


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

Definición

Agrega un parámetro a XsltArgumentList y lo asocia al nombre completo del espacio de nombres.

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

Nombre que se va a asociar al parámetro.

namespaceUri
String

URI de espacio de nombres que se va a asociar al parámetro. Para utilizar el espacio de nombres predeterminado, hay que especificar una cadena vacía.

parameter
Object

Valor del parámetro u objeto que se va a agregar a la lista.

Excepciones

namespaceUri es null o http://www.w3.org/1999/XSL/Transform.

El name no es un nombre válido según la especificación W3C XML.

El namespaceUri tiene ya un parámetro asociado.

Ejemplos

En el ejemplo siguiente se usa el AddParam método para crear un parámetro que represente la fecha y hora actuales.

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

En el ejemplo se usan los dos archivos de datos siguientes 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>

Comentarios

parameter debe corresponder a un tipo W3C. En la tabla siguiente se muestran los tipos W3C, XPath o XSLT, y la clase corresponding.NET.

Tipo W3C clase 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

*Es equivalente a un conjunto de nodos que contiene un solo nodo.

Si el objeto de parámetro que se invoca desde dentro de la hoja de estilos no es uno de los anteriores, se convierte según las reglas siguientes:

El resto de los tipos inician un error.

Se aplica a

Consulte también