Share via


XsltArgumentList.AddParam(String, String, Object) Metodo

Definizione

Aggiunge un parametro a XsltArgumentList e lo associa al nome completo dello spazio dei nomi.

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)

Parametri

name
String

Il nome da associare al parametro.

namespaceUri
String

URI dello spazio dei nomi da associare al parametro. Per utilizzare lo spazio dei nomi predefinito, specificare una stringa vuota.

parameter
Object

L'oggetto o il valore del parametro da aggiungere all'elenco.

Eccezioni

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

name non è un nome valido in base alla specifica XML W3C.

A namespaceUri è già associato un parametro.

Esempio

Nell'esempio seguente viene usato il AddParam metodo per creare un parametro che rappresenta la data e l'ora correnti.

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

Nell'esempio vengono usati i due file di dati seguenti come 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>

Commenti

Deve parameter corrispondere a un tipo W3C. La tabella seguente illustra i tipi W3C, XPath o XSLT e la 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

*Questo è equivalente a un set di nodi che contiene un unico nodo.

Se l'oggetto parametro richiamato dall'interno del foglio di stile non è uno dei seguenti, viene convertito in base alle regole seguenti:

Per tutti gli altri tipi verrà generato un errore.

Si applica a

Vedi anche