tags:

views:

85

answers:

1

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?

+3  A: 

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>
dtb
What would be the simplest way to convert an array of strings to a XPathNavigator[], because I don't want to handle complex C# code for such a minimal task.
Andrew
I've added an example.
dtb