Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In principle you need to use the XPathNodeIterator to return node sets (as Samjudson says). I take it that the example you gave is a degenerated function, as you do not supply it with any parameters. However, I think it is instructive the see how you <em>could</em> fabricate nodes out of thin air. </p> <pre><code>&lt;msxsl:script language="C#"&gt; XPathNodeIterator getNodes() { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml("&lt;root&gt;&lt;fld&gt;val&lt;/fld&gt;&lt;fld&gt;val2&lt;/fld&gt;&lt;/root&gt;"); return doc.CreateNavigator().Select("/root/fld"); } &lt;/msxsl:script&gt; </code></pre> <p>However, typically you would want to do something in your function that is not possible in xslt, like filtering a node set based on some criteria. A criteria that is better implemented through code or depends om some external data structure. Another option is just that you would to simplify a wordy expression (as in the example bellow). Then you would pass some parameters to you getNodes function. For simplicity I use a XPath based filtering but it could be anything:</p> <pre><code> &lt;msxsl:script language="C#"&gt; XPathNodeIterator getNodes(XPathNodeIterator NodesToFilter, string Criteria) { XPathNodeIterator x = NodesToFilter.Current.Select("SOMEVERYCOMPLEXPATH["+Criteria+"]"); return x; } &lt;/msxsl:script&gt; &lt;xsl:for-each select="user:getNodes(values/val,'SomeCriteria')"&gt; ... &lt;/xsl:for-each&gt; </code></pre> <p>Hopes this helps, Boaz</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload