XsltArgumentList.AddParam(String, String, Object) Metoda
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Dodaje parametr do elementu XsltArgumentList i kojarzy go z kwalifikowaną nazwą przestrzeni nazw.
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)
Parametry
- name
- String
Nazwa do skojarzenia z parametrem.
- namespaceUri
- String
Identyfikator URI przestrzeni nazw do skojarzenia z parametrem. Aby użyć domyślnej przestrzeni nazw, określ pusty ciąg.
- parameter
- Object
Wartość parametru lub obiekt, który ma zostać dodany do listy.
Wyjątki
Element namespaceUri jest albo null lub http://www.w3.org/1999/XSL/Transform.
Nie name jest prawidłową nazwą zgodnie ze specyfikacją XML W3C.
Parametr namespaceUri ma już skojarzony z nim parametr.
Przykłady
W poniższym przykładzie użyto metody , AddParam aby utworzyć parametr reprezentujący bieżącą datę i godzinę.
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
W przykładzie użyto następujących dwóch plików danych jako danych wejściowych.
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>
Uwagi
Element parameter powinien odpowiadać typowi W3C. W poniższej tabeli przedstawiono typy W3C, XPath lub XSLT oraz klasę corresponding.NET.
| Typ W3C | Equivalent.NET, klasa (typ) |
|---|---|
String (XPath) |
String |
Boolean (XPath) |
Boolean |
Number (XPath) |
Double |
Result Tree Fragment (XSLT) |
XPathNavigator |
Node Set (XPath) |
XPathNodeIteratorXPathNavigator[] |
Node* (XPath) |
XPathNavigator |
*Jest to odpowiednik zestawu węzłów zawierającego jeden węzeł.
Jeśli obiekt parametru wywoływany z poziomu arkusza stylów nie jest jednym z powyższych, jest konwertowany zgodnie z następującymi regułami:
Typy liczbowe CLR są konwertowane na Double.
IXPathNavigable typy są konwertowane na XPathNavigator.
XPathNavigator[]jest konwertowany na XPathNodeIterator.
Wszystkie inne typy zgłaszają błąd.