I have a document library named "xsl library" with a bunch of xsl's... and I need to read a file (anyone one) from there so I can use it transform a xml that renders a we开发者_如何学JAVAbpart... the layout out of a webpart is determined by the xsl... how can I do it?
Notes: Enviroment -> Sharepoint 2007
So it looks like you need some server side code:
SPFile xslFile = SPContext.Current.Web.GetFile("/myWeb/myXlsLibrary/myXsl.xsl");
Stream xslStream = xslFile.OpenBinaryStream();
Then you code similar to one provided by Vlad above to make the transformation.
See MSDN for more info on functions used - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getfile.aspx , http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.openbinarystream.aspx.
XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(XmlReader.Create(new StringReader(stringWithXsltStylesheetCode)));
XmlDocument result = new XmlDocument();
using (XmlWriter xw = result.CreateNavigator().AppendChild())
{
proc.Transform(inputXmlDocument, null, xw);
xw.Close();
}
精彩评论