<msxsl:assembly> Element
Declares assemblies for use in script blocks. This element is a child of the <msxsl:script> element.
<msxsl:assembly
name = "assemblyname"
href = "pathname"
</msxsl:assembly>
- name
References an assembly by name for use within the script block.
- href
References an assembly by filename or URI for use within the script block.
Number of occurrences |
Unlimited |
Parent elements |
Note
This element is supported only in the .NET Framework.
One, and only one, of the attributes must be specified in this element.
The name form of the attribute can specify the assembly file name in either a simplified or full form as shown in the following examples.
<ms:assembly name="System.Xml"/>
<ms:assembly name="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
The href form of the attribute can specify the assembly name as either a file path or a URI as shown in the following examples.
<ms:assembly href="Helper.dll"/>
<ms:assembly href="C:\MyApplication\Helper.dll"/>
<ms:assembly href="http://tempuri.org/Helper.dll"/>
The assembly path name is resolved twice - once during compilation and once during execution. The rules during compilation are same as the compiler rules. If a fully qualified path to the assembly is not provided, the current directory is searched for the specified assembly. If not found, the common language runtime (CLR) system directory is searched. If not found, the directories specified in the LIB environment variable are searched.
During execution, the .NET Framework loader rules are used. The current directory is searched first, followed by the global assembly cache (GAC), followed by any rules specified in the application configuration file.
The following assemblies are referenced by default:
System.dll
System.Xml.dll
Microsoft.VisualBasic.dll (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>