Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 693391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:44:56+00:00 2026-05-14T02:44:56+00:00

Help me, Stackoverflow! I have a simple .NET 3.5 console app that reads some

  • 0

Help me, Stackoverflow!

I have a simple .NET 3.5 console app that reads some data and sends emails. I’m representing the email format in an XSLT stylesheet so that we can easily change the wording of the email without needing to recompile the app.

We’re using Extension Objects to pass data to the XSLT when we apply the transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:EmailNotification="ext:EmailNotification">

— this way, we can have statements like:

<p>
    Dear <xsl:value-of select="EmailNotification:get_FullName()" />:
</p>

The above works fine. I pass the object via code like this (some irrelevant code omitted for brevity):

// purely an example structure
public struct EmailNotification
{
    public string FullName { get; set; }
}

// Somewhere in some method ... 

var notification = new Notification("John Smith");

// ...

XsltArgumentList xslArgs = new XsltArgumentList();
xslArgs.AddExtensionObject("ext:EmailNotification", notification);

// ...

// The part where it breaks! (This is where we do the transformation)
xslt.Transform(fakeXMLDocument.CreateNavigator(), xslArgs, XmlWriter.Create(transformedXMLString));

So, all of the above code works. However, I wanted to get a little fancy (always my downfall) and pass a collection, so that I could do something like this:

<p>The following accounts need to be verified:</p>
<xsl:for-each select="EmailNotification:get_SomeCollection()">
    <ul>
        <li>
            <xsl:value-of select="@SomeAttribute" />
        </li>
    </ul>
<xsl:for-each>

When I pass the collection in the extension object and attempt to transform, I get the following error:

"Extension function parameters or return values which have Clr type 'String[]' are not supported."

or List, or IEnumerable, or whatever I try to pass in.

So, my questions are:

  1. How can I pass in a collection to my XSLT?

  2. What do I put for the xsl:value-of select=”” inside the xsl:for-each ?

Is what I am trying to do impossible?


Edit: After I saw the two answers below, I took Chris Hynes’ code and modified it very slightly to suit my needs. Solution is as follows:

// extension object
public struct EmailNotification
{
    public List<String> StringsSetElsewhere { private get; set; }
    public XPathNavigator StringsNodeSet
    {
        get
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement root = xmlDoc.CreateElement("Strings");
            xmlDoc.AppendChild(root);
            foreach (var s in StringsSetElsewhere)
            {
                XmlElement element = xmlDoc.CreateElement("String");
                element.InnerText = s;
                root.AppendChild(element);
            }
            return xmlDoc.CreateNavigator();
        }
    }
}

And in my XSLT …

<xsl:for-each select="EmailNotification:get_StringsNodeSet()//String">
    <ul>
        <li>
            <xsl:value-of select="." />
        </li>
    </ul>
</xsl:for-each>

Worked perfectly!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:44:57+00:00Added an answer on May 14, 2026 at 2:44 am

    The XSLT for-each expects a node set to iterate over — you can’t directly pass an array back from your C# code. You should return an XPathNodeIterator.

    Something like this:

    public static XPathNodeIterator GetSomeCollection()
    {    
        XmlDocument xmlDoc = new XmlDocument();
    
        string[] stringsToReturn = new string[] { "String1", "String2", "String3" };
    
        XmlElement root = xmlDoc.CreateElement("Strings");
    
        xmlDoc.AppendChild(root);
    
        foreach (string s in stringsToReturn)
        {
            XmlElement el = xmlDoc.CreateElement("String");
    
            el.InnerText = s;
    
            root.AppendChild(el);
        }
    
        XPathNodeIterator xNodeIt = xmlDoc.CreateNavigator().Select(".");
    
        return xNodeIt;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help me Stackoverflow! So, I feel that I have set up my environment correctly
Help! I have an Axis web service that is being consumed by a C#
HELP! I just setup a virtual host for two sites that have a lot
I have a simple ADO.NET Entity Framework 4.0 model (edmx) which defines database tables
I posted this question: https://stackoverflow.com/questions/418597/java-and-net-for-php-programmer and the answers I was given didn't really help
Help! I have a PHP (PHP 5.2.5) script on HOST1 trying to connect to
I want to be able to display some simple chunks of HTML in my
I have been looking over StackOverflow and have not found any answers yet, if
With the help of the Stack Overflow community I've written a pretty basic-but fun
Help me ..my page index is not working in visual studio. my page load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.