我在c#sharepoint webpart代码中加载一个XSLT文件,如下所示:
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 :(得分: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);
希望这对你有用。