【问题标题】:XML document within Sharepoint webpart codebehindSharepoint webpart 代码隐藏中的 XML 文档
【发布时间】:2011-01-04 03:19:57
【问题描述】:

我正在 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);

我怎么能这样做? 谢谢,

【问题讨论】:

标签: sharepoint xslt resources web-parts


【解决方案1】:

我的建议是:

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

希望这对你有用。

【讨论】:

    猜你喜欢
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 2011-09-14
    • 2013-03-20
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    相关资源
    最近更新 更多