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?
Any help would be appreciated...
> Beginner using xslt... So. I have an XML file which has a link into
> xslt file like following...
[quoted text clipped - 5 lines]
> 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.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
RccH - 21 Mar 2007 10:28 GMT
> > Beginner using xslt... So. I have an XML file which has a link into
> > xslt file like following...
[quoted text clipped - 43 lines]
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
Thank you. That helped... especially the part using regular expression
for href parsing...