Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XmlResolver implementation does not get called

$
0
0

Hello,

I want to use images in XSLT trasnformation. These images are included in my project as EmbeddedResources. I'm trying to implement custom XmlResolver that will look for it in Resources, but GetEntities method of my custom XmlResolver never gets called and images are not found. Any idea what is wrong with this code?

XmlResolver Implementation

public class EmbeddedResourceXsltResolver : XmlResolver
	{
		public override System.Net.ICredentials Credentials
		{
			set { throw new NotImplementedException(); }
		}
		//THIS NEVER GETS INVOKED
		public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
		{
			var executingAssembly = Assembly.GetExecutingAssembly();
			foreach (var resourceName in executingAssembly.GetManifestResourceNames())
			{
				if (resourceName.EndsWith("." + absoluteUri.LocalPath))
				{
					var xslt = executingAssembly.GetManifestResourceStream(resourceName);
					return XmlReader.Create(new StreamReader(xslt),
						null, absoluteUri.LocalPath);
				}
			}
			return null;
		}
	}

XSLT Transformation

// Prepare XSLT
				XslCompiledTransform xslt = new XslCompiledTransform(true);
				// If XSLT has scripts, this must be enabled. By default it's disabled.
				XsltSettings xslt_settings = new XsltSettings();
				xslt_settings.EnableScript = true;
				// Creates a XmlReader from your XSL string
				using (XmlReader xmlreader = XmlReader.Create(new StringReader(xsltInput)))
				{
					//Load the style sheet.
					xslt.Load(xmlreader, xslt_settings, new EmbeddedResourceXsltResolver());
					// transform
					using (StringWriter stringWriter = new StringWriter())					
					{						
						xslt.Transform(xpathDocument, null, stringWriter);						
						// save to string
						html = stringWriter.ToString();
					}
				}
				return true;

XSLT

<

tdalign="right">

<

imgsrc="document.png"/>

</

td>

document.png is built in as an EmbeddedResource.

Thank you.


Isolda



Viewing all articles
Browse latest Browse all 935

Trending Articles