2012-10-04 22 views
1
<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文件,什麼是「正確」的方式不只是獲取數據,而且還編輯並保存迴文件而不做改變等編輯XSL:PARAM在C#

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; 

這很容易返回問題帕拉姆的價值,但如果我想那麼這個編輯並保存此更改的文件,我怎麼會去嗎?

+0

你嘗試PARAM_blah.InnerText = 「值」;然後xslDoc.Save(fileStream)? – rene

+0

@rene這是我第一次想到,但不知道要分配給'fileStream'。我可以將XSLT讀入文件組?但那麼我需要確保我的變化進入那裏? – JustAnotherDeveloper

+0

FileStream filstream = File.Create(「yournew.xslt」); – rene

回答

1

只要做到這一點:

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

謝謝。我不知道這是如此簡單。工作正常。保存迭代或序列化 – JustAnotherDeveloper