2010-01-12 2 views
1

Я загрузки файла XSLT в C# код SharePoint веб-части, как показано ниже:XML документ в Sharepoint WebPart CodeBehind

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

Файл XSLT является довольно большой около 134 линий.

Мне нужно ссылаться на изображения в XSLT, путь к которому генерируется кодом.

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

Как я могу это сделать? Спасибо,

+0

Если вы не придерживаетесь .NET 1.0 или 1.1, вы должны использовать XslCompiledTransform http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx вместо XslTransform. – Filburt

ответ

0

Мое предложение:

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); 

Надеется, что это делает трюк для вас.