On Mar 20, 3:21 pm, Martin Honnen <mahotr...@yahoo.de> wrote:
> RccH wrote:
> > Beginner using xslt... So. I have an XML file which has a link into
> > xslt file like following...
>
> > <?xml version='1.0' encoding='utf-8' ?>
> > <?xml-stylesheet type="text/xsl" href="transform.xsl"?>
> > <customers> rest of the xml....
>
> > So How, using C# or VB.NET do I apply that xsl file into this same
> > xmlfile and write the transformed file into disk?
>
> That <?xml-stylesheet ...?> thing is a processing instruction so you can
> read the whole XML file into an XPathDocument, then navigate to that
> processing instruction and read out the target data, a regular
> expression might help for that.
>
> XPathDocument xmlDoc = new XPathDocument(@"XMLFile1.xml");
> XPathNavigator navigator = xmlDoc.CreateNavigator();
> if (navigator.MoveToChild(XPathNodeType.ProcessingInstruction))
> {
> if (navigator.Name == "xml-stylesheet")
> {
> string target = navigator.Value;
> Match match = Regex.Match(target,
> @"href=""([^""]+)""");
> if (match.Success)
> {
> string href = match.Groups[1].Value;
> navigator.MoveToRoot();
> XslCompiledTransform xsltProcessor = new
> XslCompiledTransform();
> xsltProcessor.Load(href);
> using (XmlWriter xmlWriter =
> XmlWriter.Create(Console.Out, xsltProcessor.OutputSettings))
> {
> xsltProcessor.Transform(xmlDoc, xmlWriter);
> }
> }
> }
> }
>
> In reality it might be more complex as the href URI is relative to the
> XML document so you need to make sure you resolve it correctly.
>
> --
>
> Martin Honnen --- MVP XML
>
http://JavaScript.FAQTs.com/ Thank you. That helped... especially the part using regular expression