2010-01-12 65 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); 

希望这不会把戏给你。