views:

253

answers:

1

Hi,

I am loading an XSLT file in c# sharepoint webpart code as below:

  string path = context.Request.MapPath("/_layouts/RSSWeatherXSL.xsl");
   XslTransform trans = new XslTransform();
     trans.Load(path); // loading xsl file

The XSLT file is rather large around 134 lines.

I need to reference images within the XSLT the path to which is generated by the codebehind.

SPWeb currentWeb = SPControl.GetContextWeb(Context);
2.Type currentType = this.GetType();
3.string classResourcePath = SPWebPartManager.GetClassResourcePath(currentWeb, currentType);

How could I do this? Thanks,

A: 

My suggestion is:

string path = context.Request.MapPath("/_layouts/RSSWeatherXSL.xsl");

XmlDocument styledocument = new XmlDocument();
styledocument.Load(path);

XmlNode imagepath = styledocument.DocumentElement.AppendChild(styledocument.CreateElement("xsl:variable", "http://www.w3.org/1999/XSL/Transform"));

XmAttribute varname = imagepath.Attributes.Append(styledocument.CreateAttribute("name"));
varname.Value = "imagepath_1";

XmAttribute varselect = imagepath.Attributes.Append(styledocument.CreateAttribute("select"));
varselect.Value = "'here_goes_your_generated_path_in_single_quotes'";

// add more <xsl:variable /> nodes as needed

XslCompiledTransform trans = new XslCompiledTransform();
trans.Load(styledocument);

Hope this does the trick for you.

Filburt