Export (0) Print
Expand All

<msxsl:using> Element

Declares additional namespaces for use in script blocks. This element is a child of the <msxsl:script> element.

<msxsl:using
  namespace = "namespace-name"
</msxsl:using>

namespace
Required. References a namespace for use within the script block.

 

Number of occurrences

Unlimited

Parent elements

<msxsl:script> Element

noteNote:
This element is supported only in the .NET Framework.

The namespace declaration allows you to use the types in a namespace without having to specify the namespace.

The namespaces may be user-defined or system-defined.

The following namespaces are in scope by default:

  • System

  • System.Collection

  • System.Text

  • System.Text.RegularExpressions

  • System.Xml

  • System.Xml.Xslt

  • System.Xml.XPath

  • Microsoft.VisualBasic (if Visual Basic is used)

The following example demonstrates accessing a class in a user-defined assembly named MyCompany.HelperAssembly.

This is the C# code contained in the MyCompany.HelperAssembly assembly.

class MyCompany.XmlHelper.NodeContents
{
   XPathNavigator _nav;

   public NodeContents(XPathNavigator nav)
   {
      _nav = nav;
   }

   public string GetNodeContents()
   {
      return _nav.InnerXml;
   }
}

The following stylesheet adds a reference to the assembly and imports the appropriate namespace. The classes in the assembly namespace are referenced in the script block.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="http://MyCompany/"
                version="1.0">

  <msxsl:script language="C#" implements-prefix="user">
    <msxsl:assembly name="MyCompany.HelperAssembly" />
    <msxsl:using namespace="MyCompany.XmlHelper" />
    function string FragmentValue(XPathNavigator nav)
    {
       NodeContents myContents = new NodeContents(nav);
       return myContents.GetNodeContents();
    }
  </msxsl:script>
  

    <xsl:template match="/">
            <xsl:value-of select="user:FragmentValue(customer[1])"/>
    </xsl:template>
</xsl:stylesheet>




Build Date:

2012-08-02
Show:
© 2014 Microsoft