Permalink
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (59 sloc) 3.36 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs ms.assetid caps.latest.revision author ms.author manager
XSLT Parameters
03/30/2017
.net
dotnet-standard
article
VB
CSharp
C++
jsharp
fe60aaa0-ae43-4b1c-9be1-426af66ba757
2
mairaw
mairaw
wpickett

XSLT Parameters

XSLT parameters are added to the xref:System.Xml.Xsl.XsltArgumentList using the xref:System.Xml.Xsl.XsltArgumentList.AddParam%2A method. A qualified name and namespace URI are associated with the parameter object at that time.

To use an XSLT parameter

  1. Create an xref:System.Xml.Xsl.XsltArgumentList object and add the parameter using the xref:System.Xml.Xsl.XsltArgumentList.AddParam%2A method.

  2. Call the parameter from the style sheet.

  3. Pass the xref:System.Xml.Xsl.XsltArgumentList object to the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method.

Parameter Types

The parameter object should correspond to a W3C type. The following table shows the corresponding W3C types, the equivalent Microsoft .NET classes (type), and whether the W3C type is an XPath type or XSLT type.

W3C type Equivalent .NET class (type) XPath or XSLT type
String xref:System.String?displayProperty=nameWithType XPath
Boolean xref:System.Boolean?displayProperty=nameWithType XPath
Number xref:System.Double?displayProperty=nameWithType XPath
Result Tree Fragment xref:System.Xml.XPath.XPathNavigator?displayProperty=nameWithType XSLT
Node* xref:System.Xml.XPath.XPathNavigator?displayProperty=nameWithType XPath
Node Set xref:System.Xml.XPath.XPathNodeIterator

XPathNavigator[]
XPath

*This is equivalent to a node set that contains a single node.

If the parameter object is not one of the above classes, it is converted according to the following rules. Common language runtime (CLR) numeric types are converted to xref:System.Double. The xref:System.DateTime type is converted to xref:System.String. xref:System.Xml.XPath.IXPathNavigable types are converted to xref:System.Xml.XPath.XPathNavigator. XPathNavigator[] is converted to xref:System.Xml.XPath.XPathNodeIterator.

All other types throw an error.

Example

The following example uses the xref:System.Xml.Xsl.XsltArgumentList.AddParam%2A method to create a parameter to hold calculated discount date. The discount date is calculated to be 20 days from the order date.

[!code-csharpXSLT_Param#1] [!code-vbXSLT_Param#1]

Input

order.xml

[!code-xmlXSLT_Param#2]

discount.xsl

[!code-xmlXSLT_Param#3]

Output

<?xml version="1.0" encoding="utf-8"?>  
<order>  
  <total>36.9</total>  
     15% discount if paid by: 2/4/2004 12:00:00 AM  
</order>  

See Also

XSLT Transformations