fcaglayan
fcaglayan

Reputation: 31

How to render a local XML with an XSL on a remote server

At my application I am using XSLT to render XML files.

This is working fine when clients have xsl files:

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

But when I try to use an xsl file on my server in XML files like:

<?xml-stylesheet type="text/xsl" href="http://www.mysite.com/xsl/test.xsl"?>

This is not working. It seems like a security restriction but is there a way to render local XML files with a remote XSL on a remote server?

Upvotes: 3

Views: 3426

Answers (2)

Alex
Alex

Reputation: 19

In IE11, there is still a workaround. You should go to "Internet options -> Security -> Local Internet -> Custom Level -> Miscellaneous -> Access data sources across domains" and set it to “Enable” or “Prompt”(last option is recommended in order you still have some control over this). This will enable loading/processing your local xml by remote xsl.

Upvotes: 1

Nils Werner
Nils Werner

Reputation: 36795

The "security restriction" you're seeing is called same origin policy. This means that your XSLT stylesheets must come from the same server your XML was loaded from.

If your XML comes from a server with scripting ability like PHP or so you can circumvent this by creating a proxy script. This script will essentially load the remote XSL file and make it appear to be a local one:

<?php
header('Content-type: text/xsl');
echo file_get_contents('http://www.mysite.com/xsl/test.xsl');
?>

Upvotes: 1

Related Questions