Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xslt:param array in .NET

Tags:

c#

xslt

Simple question, but is the solution?

I have a typical C# Application that runs "new XslCompiledTransform.Transform(...);" I am passing it param arguments, all of type string.

I want to pass it a param that is of type array: strings, or even lets say an array of objects.

I am using C# I am being limited to XSL 1.0.

How am I able to preform this task, in a clean way to avoid writing unnecessary code in .NET?

like image 805
Andrew Avatar asked Mar 01 '23 01:03

Andrew


1 Answers

XsltArgumentList.AddParam accepts the following types for the value:

W3C Type                      Equivalent.NET Class (Type)

String (XPath)                String
Boolean (XPath)               Boolean
Number (XPath)                Double
Result Tree Fragment (XSLT)   XPathNavigator
Node Set (XPath)              XPathNodeIterator, XPathNavigator[]
Node* (XPath)                 XPathNavigator

So you can't pass in an array, but you could construct an XML fragment with your values and pass it as XPathNavigator.

Example

string[] strings = new string[] { "a", "b", "c" };

XPathNavigator[] navigators =
    strings.Select(s => new XElement("item", s).CreateNavigator()).ToArray();

XsltArgumentList args = new XsltArgumentList();
args.AddParam("items", "", navigators);

The XML nodes constructed look like this:

<item>a</item>
<item>b</item>
<item>c</item>
like image 198
dtb Avatar answered Mar 07 '23 11:03

dtb