Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old July 13th, 2005, 07:43 AM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to aowen355
Default XslPath help

I have a program that pulls data from a SQL server and converts it to XML. The next thing i want to do is figure out a way to apply XSL to this XML doc. Ideally I would like to just append a line to the top of the XML doc like this <?xml-stylesheet type="text/xsl" href="Sample.xsl"?> From what I understand, XslPath is supposed to do this, but it is causing errors in the final outputted XML document.

Any suggestions?

-Andrew

 
Old July 13th, 2005, 08:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do you apply the stylesheet line? I do not know the XslPath property or method? How about this...
Code:
public static void AddXslIncludeInstruction(string filename, string stylesheet)
{
    XmlDocument doc = null;
    try
    {
        doc = new XmlDocument();
        doc.Load(filename);
        if(stylesheet != null)
        {
            doc.InsertBefore(doc.CreateProcessingInstruction(
                "xml-stylesheet", "type=\"text/xsl\" href=\"" + stylesheet + "\""),
                doc.DocumentElement);
        }
        doc.Save(filename);
    }
    catch(Exception e)
    {
        System.Console.WriteLine(e.Message);
        throw;
    }
}
(the above code is not tested, but I think it works)

Hope it helps, Jacob.
 
Old July 13th, 2005, 08:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just tested it... It works! Jacob.
 
Old July 14th, 2005, 01:01 PM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to aowen355
Default

Thank you sir, I appreciate your help!

-Andrew










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