newbie: XSL transform and include

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();
 
M

MSFT

Hi Dan,

Thank you for using the community. From the description, you want to use
xsl:include or xsl:import to reference a xsl file embed in .NET assembly
resource. In fact, the elements xsl:include and xsl:import are elements
predefined in the namespace XSL, and .NET assembly resource or Stream
object are not considered for them. They only accpet a path string for
actual file. The work around is write the resource to temporary files and
delete files after transform.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Similar Threads


Top