Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>XSLT extension methods must return a type that is supported within XSL transformations. The following table shows the W3C XPath types and their corresponging .NET type:</p> <pre> W3C XPath Type | Equivalent .NET Class (Type) ------------------------------------------------------ String | System.String Boolean | System.Boolean Number | System.Double Result Tree Fragment | System.Xml.XPath.XPathNavigator Node Set | System.Xml.XPath.XPathNodeIterator </pre> <p>The table is taken from the section <em>Mapping Types between XSLT and .NET</em> in this <a href="http://msdn.microsoft.com/en-us/magazine/cc302079.aspx" rel="noreferrer">MSDN Magazine article</a>.</p> <p>Instead of returning a <code>string[]</code> array you would have to return an <code>XPathNodeIterator</code> like it is done in the following example:</p> <pre><code>&lt;msxsl:script implements-prefix="extension" language="C#"&gt; &lt;![CDATA[ public XPathNodeIterator GetList(string str, string delimiter) { string[] items = str.Split(delimiter.ToCharArray(), StringSplitOptions.None); XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("root")); using (XmlWriter writer = doc.DocumentElement.CreateNavigator().AppendChild()) { foreach (string item in items) { writer.WriteElementString("item", item); } } return doc.DocumentElement.CreateNavigator().Select("item"); } ]]&gt; &lt;/msxsl:script&gt; </code></pre> <p>In your XSL transform you can then iterate over the elements in the returned node set using <code>xsl:for-each</code>:</p> <pre><code>&lt;xsl:template match="/"&gt; &lt;root&gt; &lt;xsl:for-each select="extension:GetList('one,two,three', ',')"&gt; &lt;value&gt; &lt;xsl:value-of select="."/&gt; &lt;/value&gt; &lt;/xsl:for-each&gt; &lt;/root&gt; &lt;/xsl:template&gt; </code></pre>
 

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