public sealed class XsltArgumentList
|
When the parameters and objects are added to the XsltArgumentList, they are associated with a namespace qualified name and a namespace URI, respectively.
The following are advantages to passing an object rather than using an embedded script such as
<msxsl:script>
:
For more information about using the XsltArgumentList, see the conceptual topic at MSDN: xsltargumentlistforstylesheetparametersextensionobjects.
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
AddExtensionObject | Adds a new object to the XsltArgumentList and associates it with the namespace URI. |
AddParam | Adds a parameter to the XsltArgumentList and associates it with the namespace qualified name. |
Clear | Removes all parameters and extension objects from the XsltArgumentList. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetExtensionObject | Gets the object associated with the given namespace. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetParam | Gets the parameter associated with the namespace qualified name. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
RemoveExtensionObject | Removes the object with the namespace URI from the XsltArgumentList. |
RemoveParam | Removes the parameter from the XsltArgumentList. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public XsltArgumentList(); |
namespaceUri
extension
Exception Type | Condition |
---|---|
ArgumentException | The namespaceUri is either null or http://www.w3.org/1999/XSL/Transform The namespaceUri already has an extension object associated with it. |
using System; using System.IO; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; public class Sample { private const String filename = "books.xml"; private const String stylesheet = "prices.xsl"; public static void Main() { Sample test = new Sample(); } public Sample() { //Create the XslTransform and load the stylesheet. XslTransform xslt = new XslTransform(); xslt.Load(stylesheet); //Load the XML data file. XPathDocument doc = new XPathDocument(filename); //Create an XsltArgumentList. XsltArgumentList xslArg = new XsltArgumentList(); //Add an object to convert the book price. BookPrice obj = new BookPrice(); xslArg.AddExtensionObject("urn:price-conv", obj); //Create an XmlTextWriter to output to the console. XmlTextWriter writer = new XmlTextWriter(Console.Out); //Transform the file. xslt.Transform(doc, xslArg, writer); writer.Close(); } //Convert the book price to a new price using the conversion factor. public class BookPrice{ private decimal newprice = 0; public decimal NewPriceFunc(decimal price, decimal conv){ decimal tmp = price*conv; newprice = decimal.Round(tmp, 2); return newprice; } } }
The example uses the following data files as input.
books.xml
<bookstore> <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore>prices.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myObj="urn:price-conv"> <!--currency conversion factor--> <xsl:param name="conv" select="1.537"/> <xsl:template match="bookstore"> <bookstore> <xsl:for-each select="book"> <book> <xsl:copy-of select="node()"/> <conv-price> <!--<xsl:value-of select="myObj:NewPriceFunc(./price, $conv)"/>--> </conv-price> </book> </xsl:for-each> </bookstore> </xsl:template> </xsl:stylesheet>
name
namespaceUri
parameter
Exception Type | Condition |
---|---|
ArgumentException | The namespaceUri is either null or http://www.w3.org/1999/XSL/Transform . The name is not a valid name according to the W3C XML specification. The namespaceUri already has a parameter associated with it. |
W3C XPath Type | Equivalent .NET XPath Class (Type) |
---|---|
String | System.String |
Boolean | System.Boolean |
Number | System.Double |
Node Fragment | System.Xml.XPath.XPathNavigator |
Node Set | System.Xml.XPath.XPathNodeIterator |
If parameter is not one of the preceding classes, it is coerced to either a Double or String, as appropriate.Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, and Decima l types are coerced to a Double. All other types are coerced to a String using the ToString method.
using System; using System.IO; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; public class Sample { private const String filename = "order.xml"; private const String stylesheet = "order.xsl"; public static void Main() { //Create the XslTransform and load the stylesheet. XslTransform xslt = new XslTransform(); xslt.Load(stylesheet); //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()); //Create the XmlTextWriter to write the output to the console. XmlTextWriter writer = new XmlTextWriter(Console.Out); //Transform the file. xslt.Transform(new XPathDocument(filename), xslArg, writer); writer.Close(); } }
The example uses the following two data files as 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>
public void Clear(); |
~XsltArgumentList(); |
namespaceUri
public virtual int GetHashCode(); |
name
namespaceUri
public Type GetType(); |
protected object MemberwiseClone(); |
namespaceUri
name
namespaceUri
public virtual string ToString(); |