XSLT Transform problems..embed -vs- file access

G

Greg Merideth

I have an XSL file that I am using to transform some XML data using this
method below. The problem is that if I use an embedded .XSL file in
the .NET assembly, I get an error indicating that the URI is invalid,
however if I open the file from the harddrive in the current directory,
it works.

Here's the method, notice that after s is loaded with the .xsl file from
the resource stream that if you do a messagebox.show with s.readtoend
you get a messagebox with all of the correct .xsl data in it, the same
data you get from the regular .load command. in the embedded version it
simply fails.

// load in the XML data file
XPathDocument doc = new XPathDocument(fileName+".xml");
XslTransform transForm = new XslTransform();

// here's where i load the .xsl in from the assembly if you do a
// System.Windows.Forms.MessageBox.Show(sr2.ReadToEnd(),""); you will
// see all of the .xsl data properly loaded
Stream s =
typeof(_xmlData).Assembly.GetManifestResourceStream("xmlData.XSLTData.xsl");
// make a stream reader
StreamReader sr2 = new StreamReader(s);

// bingo...fails here with invalid URI
transForm.Load(sr2.ReadToEnd());

// however if you do this instead it works
transForm.Load("XSLTData.xsl");

FileStream fs = new FileStream("XSLTData.html",FileMode.Create);
XPathNavigator nav = doc.CreateNavigator();
transForm.Transform(nav,null,fs);

Any idea why I can't use an embedded version?

I can whip up a quick .zip file with the source files in it if needed.
 
V

Vadim Chekan

Greg said:
I have an XSL file that I am using to transform some XML data using this
method below. The problem is that if I use an embedded .XSL file in
the .NET assembly, I get an error indicating that the URI is invalid,
however if I open the file from the harddrive in the current directory,
it works.

Looks like some pieces are loaded related to "current URL".

You do unfair comparation between file and resource approach.
Try change file read like this and see if it still works:

FileStream fs = new FileStream(fileName);
StreamReader sr3 = new StreamReader(fs);
transForm.Load(sr3.ReadToEnd());

Vadim Chekan.
 
G

Greg Merideth

Solved my own problem.

I saw what you meant by the transform.load was looking for a filename
not a string a of XML data so I worked it to

transForm.Load(new XmlTextReader(new StringReader(sr.ReadToEnd())));

passing in the xml as a new filestream and now it works fine. So I can
use an embedded XSL file and perform XSLT transforms without external files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top