【问题标题】:Edit a XSL:param in C#在 C# 中编辑 XSL:param
【发布时间】:2012-10-04 15:07:05
【问题描述】:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="blah">Content 1</xsl:param>
<xsl:param name="blah2">Content 2</xsl:param>
</xsl:stylesheet>

如果我有上述 XSLT 文件,那么“正确”的方法是什么,不仅可以获取数据,还可以对其进行编辑并将其保存回文件而不进行转换等。

XmlDocument xslDoc = new XmlDocument();
      xslDoc.Load(@"C:\params.xslt");

      XmlNamespaceManager nsMgr = new XmlNamespaceManager(xslDoc.NameTable);
      nsMgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");

      XmlNode PARAM_blah = xslDoc.SelectSingleNode(@"/xsl:stylesheet/xsl:param[@name='blah']", nsMgr);
      string blah = PARAM_blah.InnerText;

这很容易返回有问题的参数的值,但是如果我想编辑它并将这个更改保存到文件中,我该怎么做呢?

【问题讨论】:

  • 你试过 PARAM_blah.InnerText = "value";然后是 xslDoc.Save(fileStream) ?
  • @rene 这是我的第一个想法,但不确定分配给fileStream 的内容。我可以将 XSLT 读入文件流吗?但是我需要确保我的更改在那里?
  • FileStream filstream = File.Create("yournew.xslt");

标签: c# xml-parsing xml-serialization


【解决方案1】:

只需这样做:

  PARAM_blah.InnerText = "Content 2";
  xslDoc.Save(@"c:\params.xslt")

【讨论】:

  • 谢谢。我不知道这很容易。工作正常。保存迭代或序列化
猜你喜欢
  • 2012-11-02
  • 1970-01-01
  • 2011-03-23
  • 1970-01-01
  • 1970-01-01
  • 2015-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多