2010-01-12 64 views
1

我加載以下用C#的SharePoint的WebPart代碼XSLT文件:XML文檔的WebPart代碼隱藏

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 2010-01-12 11:53:50

回答

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

希望這不會把戲給你。