Basic node-set Usage

XSLT describes the availability of a "script block", which is simply an element that should be considered script. This is very similar to the script tag in HTML and in many cases, Javascript is used for scripting. The .Net XSLT engine allows script blocks via the msxsl:script tag. Here is an example:

<msxsl:script language="javascript" implements-prefix="js">
  <![CDATA[
    function space2underscore(inputString) 
    {
      return inputString.replace(" ", "_");
    }
  ]]>
</msxsl:script>

This simple function can replace spaces in a string with underscores. Script blocks are also able to work with node-sets such as the result of an XPath expression. A node-set is represented in the .Net runtime as either an XPathNodeIterator or XPathNavigator. The XPathNodeIterator is used when the node-set does not have a root element and the XPathNavigator is when the node-set does have a root element.

It is outside the scope of this page to discuss in full how to develop extension objects via the msxsl:script tag, but I have attached a sample project that takes in a node-set and returns a node-set to be used as a simple sample.

  • [get | view] (2008-02-13 06:16:03, 16.5 KB) [[attachment:BasicNodeSetExtensions.zip]]
 All files | Selected Files: delete move to page

DevCenter/Projects/ScriptBlocks/BasicNodeSets (last edited 2008-02-13 06:18:25 by localhost)