D
Dan
Could anyone give me a code sample for launching a XSLT transformation
embedded as assembly resource and which in turn references (xsl:include or
xsl:import) other embedded XSLT scripts? I have managed to call an embedded
XSLT script and also to extend it with my own functions via
AddExtensionObject (see sample below, maybe some other newbie finds it
useful
, but I have some scripts which include other scripts
(e.g.<xsl:include href="SomeOtherScript.xslt"/>) and I'd like to keep them
in separate files rather than merging all into one larger less-manageable
script: of course the include href works when the scripts are executed from
files, but not when extracted from embedded resources. How can I let them
work?
Thanx!
Dummy example for calling an embedded XSLT with extension functions:
// load XSLT from resources
XslTransform xslt = new XslTransform();
XmlUrlResolver res = new XmlUrlResolver();
res.Credentials = System.Net.CredentialCache.DefaultCredentials;
Assembly a = Assembly.GetExecutingAssembly();
Stream st = a.GetManifestResourceStream("TheNamespace.TheScript.xslt"));
xslt.Load(new XmlTextReader(new StreamReader(st, Encoding.UTF8)), res,
XmlSecureResolver.CreateEvidenceForUrl(sTheOutputFile));
// add extensions
XsltArgumentList xlArgs = new XsltArgumentList();
xlArgs.AddExtensionObject("urn:xsltExtension-MyExtensions",
MyExtensionsObject);
// load input XML
XPathDocument doc = new XPathDocument(theFileToBeTransformed);
// open output (ANSI)
XmlTextWriter wr = new XmlTextWriter(sTheOutputFile,
Encoding.GetEncoding(1252));
wr.Formatting = System.Xml.Formatting.Indented;
// transform
xslt.Transform(doc, xlArgs, wr, res);
wr.Close();
embedded as assembly resource and which in turn references (xsl:include or
xsl:import) other embedded XSLT scripts? I have managed to call an embedded
XSLT script and also to extend it with my own functions via
AddExtensionObject (see sample below, maybe some other newbie finds it
useful

(e.g.<xsl:include href="SomeOtherScript.xslt"/>) and I'd like to keep them
in separate files rather than merging all into one larger less-manageable
script: of course the include href works when the scripts are executed from
files, but not when extracted from embedded resources. How can I let them
work?
Thanx!
Dummy example for calling an embedded XSLT with extension functions:
// load XSLT from resources
XslTransform xslt = new XslTransform();
XmlUrlResolver res = new XmlUrlResolver();
res.Credentials = System.Net.CredentialCache.DefaultCredentials;
Assembly a = Assembly.GetExecutingAssembly();
Stream st = a.GetManifestResourceStream("TheNamespace.TheScript.xslt"));
xslt.Load(new XmlTextReader(new StreamReader(st, Encoding.UTF8)), res,
XmlSecureResolver.CreateEvidenceForUrl(sTheOutputFile));
// add extensions
XsltArgumentList xlArgs = new XsltArgumentList();
xlArgs.AddExtensionObject("urn:xsltExtension-MyExtensions",
MyExtensionsObject);
// load input XML
XPathDocument doc = new XPathDocument(theFileToBeTransformed);
// open output (ANSI)
XmlTextWriter wr = new XmlTextWriter(sTheOutputFile,
Encoding.GetEncoding(1252));
wr.Formatting = System.Xml.Formatting.Indented;
// transform
xslt.Transform(doc, xlArgs, wr, res);
wr.Close();