How to declare a custom function returning node -set?
Basically, you need to use XPathNodeIterator to return node sets (as Samjudson says). I believe that the example you provided is a degenerated function, since you are not providing it with any parameters. However, I think it is instructive to see how you could make knots from the air.
<msxsl:script language="C#"> XPathNodeIterator getNodes() { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml("<root><fld>val</fld><fld>val2</fld></root>"); return doc.CreateNavigator().Select("/root/fld"); } </msxsl:script> However, usually you want to do something in your function, which is impossible in xslt, for example, to filter a node set based on some criteria. Criteria that are better implemented through code or depend on some external data structure. Another option is simply that you would simplify the word expression (as in the example below). You will then pass some parameters to the getNodes function. For simplicity, I use XPath-based filtering, but it could be anything:
<msxsl:script language="C#"> XPathNodeIterator getNodes(XPathNodeIterator NodesToFilter, string Criteria) { XPathNodeIterator x = NodesToFilter.Current.Select("SOMEVERYCOMPLEXPATH["+Criteria+"]"); return x; } </msxsl:script> <xsl:for-each select="user:getNodes(values/val,'SomeCriteria')"> ... </xsl:for-each> Hope this helps, Boaz
A quick google for C # xslt msxml showed a link to the next page, which provides numerous examples of the XSLT extension in Microsoft environments.
http://msdn.microsoft.com/en-us/magazine/cc302079.aspx
In particular, the section on mapping types between XSLT and .Net gives you exactly the information you need:
Type W3C XPath - equivalent .NET class (type)
- String - System.String
- Boolean - System.Boolean
- Number - System.Double
- Fragment of the result tree - System.Xml.XPath.XPathNavigator
- Node Set - System.Xml.XPath.XPathNodeIterator
So, in your example, I would try XPathNodeLiterator.