I am trying to implement a .NET xslt extension object the checks for the existence of an xml file following examples from here and there. I also pondered some related SO posts which weren't much help.
When I try to find the extension with the following code snippet, it displays "Extension function is not available":
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:XsltExtensionObject="urn:XsltExtensionObject"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl XsltExtensionObject">
...
<xsl:choose>
<xsl:when test="function-available('XsltExtensionObject:getFile')">
Extension function is available
</xsl:when>
<xsl:otherwise>
Extension function is not available
</xsl:otherwise>
</xsl:choose>
...
I created a separate class library called XsltExtensionObject within the same VS 2012 solution as follows (did t in VB to be consistent with the first example):
Public Class FileExist
Private exist As Boolean
Public Sub New()
exist = False
End Sub
Public Function getFile(ByVal myFile As String) As Boolean
exist = System.IO.File.Exists(myFile)
Return exist
End Function
End Class
I execute the xsl transform as follows:
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(MapPath("homepage.xslt"));
XsltArgumentList xslArgs = new XsltArgumentList();
XsltExtensionObject.FileExist obj = new XsltExtensionObject.FileExist();
xslArgs.AddExtensionObject("urn:XsltExtensionObject", obj);
xmldoc.Load(MapPath("lists.xml"));
StringWriter sw = new StringWriter();
xslt.Transform(new XmlNodeReader(xmldoc), null, sw);
content.InnerHtml = sw.ToString();
}
Why can't it find the extension? What am I missing here? An assembly reference?