Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 19th, 2007, 03:42 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Included XSLT and use as object

I have an application that generates and XML file and i want to be able to run an XSLT on the file to generate multiple .HTMl files, i ahve the xslt included in my project but how do i call the XSLT file without using

"Transform.Load("\\\\<server>\\<User>\\<Website>\\ XSLT\\Services.xslt")

can i call the file that is included in my project instead of calling a file on my system?

or another question can i call the XSLT as an object or class? or a more dynmic way to call the XSLT without it being dependent on a specific file location?

Thanks
  #2 (permalink)  
Old October 20th, 2007, 06:34 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What kind of project is it? I'll make the assumption that because you are turning XML into HTML that you are doing a web project.

If your XSLT lives in your project here:

    <project>\XSLT\Services.xslt

then you can access the file this way:

    strXsltFile = MapPath("~/XSLT/Services.xslt");

This will do two things:
- Resolve the ~ into your application instance name (with or without virtual directories)
- Map the virtual path to the physical path of the web application.

-Peter
  #3 (permalink)  
Old October 31st, 2007, 04:40 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can embed an XSLT file into your DLL, it then becomes a resource.

In the solution explorer select the XSLT file and in the properties change it from "Content" to "Embedded Resource" to get it included in the dll.

If you have an XSLT file called "myXSLT.xslt" in an the root directory of an assembly called "Namespace.dll" then the following code will load the transform:

Code:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream s = assembly.GetManifestResourceStream("Namespace.myXSLT.xslt");

XmlTextReader reader = new XmlTextReader(s);
XslTransform t = new XslTransform();
t.Load(reader);
/- Sam Judson : Wrox Technical Editor -/


Similar Threads
Thread Thread Starter Forum Replies Last Post
apply-template from included xslt stylesheet chobo XSLT 9 April 16th, 2008 05:25 PM
Generate A Workbook With Macro Included robnot Excel VBA 1 February 16th, 2007 07:08 PM
XSLT in IE: adding js object to a stylesheet Vx BOOK: Professional Ajax ISBN: 978-0-471-77778-6 2 August 22nd, 2006 11:00 AM
dll config files - included in the build stuarth VS.NET 2002/2003 0 July 13th, 2005 06:59 AM
Why are my math functions not being included? jkeen BOOK Beginning Linux Programming, 3rd Edition 4 October 22nd, 2004 05:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.