tags:

views:

536

answers:

5

Currently I use:

<?xml-stylesheet type="text/xsl" href="XSL.xsl"?>

To link XSL to XML.

If my xml was here: www.externaldomain.com/rss.xml (Outside of my domain) how can i get the XSL linked to the XML?

Can i point the XSL to a File or Link?

+2  A: 

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

marc_s
+1  A: 

You can't achieve this with "pure" xml+xslt. Some external code will need to identify the xml and the xslt which should transform it.

Since you seem to be transforming XML, I'm going to guess you're doing this in the webbrowser.

You can do this using javascript, as demonstrated on w3schools.

Eamon Nerbonne
+4  A: 

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"&gt;
]>
<?xml-stylesheet type="text/xsl" href="XSL.xsl" ?>
<wrapper>
    &content;
</wrapper>
Mads Hansen
A: 

You could write a local xml file as wrapper:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XSL.xsl" ?>
<wrapper Source="http://www.externaldomain.com/rss.xml"/&gt;

And extend your stylesheet so that it understands the wrapper:

<xsl:template match="wrapper">
  <xsl:apply-templates select="document(./@Source)"/>
</xsl:template>

I haven't tested it with XML files over http but it works with local XML files that I don't want to change to include a xml-stylesheet processing instruction. It works mit Firefox, Opera and IE (7, I haven't tried other versions)

Name
A: 

Mads Hansen's answer unfortunatly does not work in Firefox.

Robert Read