Apply XSL to External XML

You can create a local XML file that includes the XML content of the remote XML file through an entity reference.

The example below will give you the content of the remote XML file inside of a wrapper document element.

Then you can include a stylesheet processing instruction on your local XML file.

However, since the local file has a wrapper document element, you might need to point to a "wrapper XSLT" that uses xsl:import to import the original XSL.xsl and apply-templates starting with the content inside the wrapper element.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wrapper [
<!ENTITY content SYSTEM "http://stackoverflow.com/feeds">
]>
<?xml-stylesheet type="text/xsl" href="XSL.xsl" ?>
<wrapper>
    &content;
</wrapper>

If you're trying to run the XSLT inside .NET, you can easily use the XslCompiledTransform class in .NET to achieve this.

If you're trying to run this on e.g. the command line, there's a bunch of tools you can use to apply a XSLT file to a given XML file - typically however one that's on your local harddisk.

See e.g. Oleg Tkachenko's web site for info on NXSLT and this other XSLT tools, or see this CodeProject article for a Windows shell extension to apply a XSLT to a given XML file (on your local harddisk).

Hope this helps a bit.

Marc

Tags:

Xml

Xslt