XsltArgumentList.AddParam(String, String, Object) Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
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
Identificador URI del espacio de nombres que se va a asociar al parámetro . Para usar el espacio de nombres predeterminado, especifique una cadena vacía.
- parameter
- Object
Valor de parámetro o objeto que se va a agregar a la lista.
Excepciones
namespaceUri es null o http://www.w3.org/1999/XSL/Transform.
no name es un nombre válido según la especificación XML W3C.
namespaceUri Ya tiene 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.NET correspondiente.
| Tipo W3C | Clase equivalente.NET (tipo) |
|---|---|
String (XPath) |
String |
Boolean (XPath) |
Boolean |
Number (XPath) |
Double |
Result Tree Fragment (XSLT) |
XPathNavigator |
Node Set (XPath) |
XPathNodeIteratorXPathNavigator[] |
Node* (XPath) |
XPathNavigator |
*Esto equivale a un conjunto de nodos que contiene un único 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:
Los tipos numéricos CLR se convierten en Double.
IXPathNavigable Los tipos se convierten en XPathNavigator.
XPathNavigator[]se convierte en XPathNodeIterator.
El resto de los tipos inician un error.