XmlUrlResolver & document()

  • Thread starter Thread starter Maxim Kazitov
  • Start date Start date
M

Maxim Kazitov

Hi,

I try to use document() function in XSLT, but looks like .Net XSLT parser don't try to resolve external URL. Does any body know what can be wrong here :


=================C#==========================
public class XmlUrlResolverExt:XmlUrlResolver
{
private static readonly ILog log = LogFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public XmlUrlResolverExt() : base() { }
public override object GetEntity(Uri uri, string role, Type type)
{
log.Debug(string.Format("XmlUrlResolverExt.GetEntity('{0}','{1}','{2}')",uri.ToString(), role, type.ToString()));
return base.GetEntity(uri, role, type);
}
public override Uri ResolveUri(Uri uri, string relativeUri)
{
log.Debug(string.Format("XmlUrlResolverExt.ResolveUri('{0}','{1}')", uri.ToString(), relativeUri));
return base.ResolveUri(uri, relativeUri);
}
}
.....................................................................
.....................................................................

XslTransform oProcessor = new XslTransform();
XsltArgumentList oXslArgs = new XsltArgumentList();
XmlUrlResolverExt oResolver = new XmlUrlResolverExt();
XmlTextWriter oWriter = new XmlTextWriter("Output.xml", System.Text.Encoding.UTF8);

oResolver.Credentials = new NetworkCredential("User", "pwd", "domain");

oProcessor.Load(new XmlTextReader(pXSLTFile), new XmlUrlResolverExt());

oXslArgs.AddParam("paramFilename", "", sFileName); // sFileName - network path in following format \\server\share\file.xml

oProcessor.Transform(oXmlDoc, oXslArgs, oWriter, oResolver);

==================XSLT======================

<?xml version="1.0" encoding="UTF-8" ?>
........................................................................
........................................................................
<xsl:param name="paramFilename"/>
<xsl:variable name="docActualsFile" select="document($paramFilename)"/>
........................................................................
........................................................................
 
Maxim said:
public override Uri ResolveUri(Uri uri, string relativeUri)
{

log.Debug(string.Format("XmlUrlResolverExt.ResolveUri('{0}','{1}')",
uri.ToString(), relativeUri));

That's the problem. uri is null, so ResolveUri method throws an
exception and so resolving process gets skipped.
 
Yes, you are right, I fix it And ResolveUri working fine, but I don't see any call's for GetEntity, and XSLT doesn't work any way.
 
I try to include file://<SERVER>/<DIR>/SOME.XML and looks like it's
doesn't work for file:// protocol (all MSDN examples related to HTTP
protocol).
 
Back
Top