XslTransform and document()
-
:confused:I'm writing a C# app which uses some xslt scripts to transform XML files. The XSLT files are embedded as resources in the application assembly. Some of these files use 2 input: one is the XML file to be transformed, another is an XML fragment contained in a distinct file, accessed via document() XSL function. The location of this second input file is known at runtime, and is passed from the application to the Transform method using an XsltArgumentList. The code I have written works fine if I load the XSLT from file, but the transformation *fails to access the 2nd input document when I load it from the assembly resources*. In both cases, the parameter is received correctly and the transformation works except for the external document data, which in one case are completely ignored as if the document did not exist. Maybe I'm missing some credentials, or what else can be wrong? Thx guys for helping a newbie... :-) Here's a dummy sample: --- let's say we have a dummy contacts list in a XML file, and I want to prepend some XML coming from another file; the XSLT looks like: ... where the full path for the file to be prepended is passed as "newdoc" parameter. I add the tags above to examine the parameter value. --- the code for the transformation follows: it works fine if I use the Load from file method, but FAILS if I load the XSLT from resources. In both cases, I can be sure that the parameter is received correctly, but it seems that the XSLT loaded from resources CANNOT ACCESS the file using document() function ( above is always empty, while contains the file name as expected): // setup params XsltArgumentList xlArgs = new XsltArgumentList(); xlArgs.AddParam("newdoc", "", "c:\\Work\\SomeDummyFile.xml"); // load input XML XPathDocument doc = new XPathDocument("c:\\Work\\theInputFile.xml"); // open output XmlTextWriter wr = new XmlTextWriter("c:\\work\\theOutputFile.xml"), null); wr.Formatting = System.Xml.Formatting.Indented; // transform XmlUrlResolver res = new XmlUrlResolver(); res.Credentials = System.Net.CredentialCache.DefaultCredentials; XslTransform xslt = new XslTransform(); // xslt.Load("c:\\work\\Test.xslt"); <-
-
:confused:I'm writing a C# app which uses some xslt scripts to transform XML files. The XSLT files are embedded as resources in the application assembly. Some of these files use 2 input: one is the XML file to be transformed, another is an XML fragment contained in a distinct file, accessed via document() XSL function. The location of this second input file is known at runtime, and is passed from the application to the Transform method using an XsltArgumentList. The code I have written works fine if I load the XSLT from file, but the transformation *fails to access the 2nd input document when I load it from the assembly resources*. In both cases, the parameter is received correctly and the transformation works except for the external document data, which in one case are completely ignored as if the document did not exist. Maybe I'm missing some credentials, or what else can be wrong? Thx guys for helping a newbie... :-) Here's a dummy sample: --- let's say we have a dummy contacts list in a XML file, and I want to prepend some XML coming from another file; the XSLT looks like: ... where the full path for the file to be prepended is passed as "newdoc" parameter. I add the tags above to examine the parameter value. --- the code for the transformation follows: it works fine if I use the Load from file method, but FAILS if I load the XSLT from resources. In both cases, I can be sure that the parameter is received correctly, but it seems that the XSLT loaded from resources CANNOT ACCESS the file using document() function ( above is always empty, while contains the file name as expected): // setup params XsltArgumentList xlArgs = new XsltArgumentList(); xlArgs.AddParam("newdoc", "", "c:\\Work\\SomeDummyFile.xml"); // load input XML XPathDocument doc = new XPathDocument("c:\\Work\\theInputFile.xml"); // open output XmlTextWriter wr = new XmlTextWriter("c:\\work\\theOutputFile.xml"), null); wr.Formatting = System.Xml.Formatting.Indented; // transform XmlUrlResolver res = new XmlUrlResolver(); res.Credentials = System.Net.CredentialCache.DefaultCredentials; XslTransform xslt = new XslTransform(); // xslt.Load("c:\\work\\Test.xslt"); <-
one word: "Security".... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconxsltransformclassimplementsxsltprocessor.asp[^] "Most of the Load methods also take Evidence as a parameter. The Evidence parameter is the System.Security.Policy.Evidence that is associated with the style sheet. The security level of the style sheet affects the security level of any subsequent resources it references, such as the script it contains, any document() functions it uses, and any extension objects used by the XsltArgumentList." I had the same problem... :mad:
"When the only tool you have is a hammer, a sore thumb you will have."