-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.php
48 lines (36 loc) · 1.11 KB
/
transform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
$url = @$_REQUEST['url'];
$format = @$_REQUEST['format'];
$callback = @$_REQUEST['callback'];
$xp = new XsltProcessor();
$xsl = new DomDocument;
if ($format === "luax") {
$xsl->load('xmltolua.xsl');
header('Content-Type: text/plain; charset=UTF-8');
} else if ($format === "lua") {
$xsl->load('xmltolua-compact.xsl');
header('Content-Type: text/plain; charset=UTF-8');
} else if ($format === "json") {
$xsl->load('xmltojson-compact.xsl');
header('Content-Type: application/json; charset=UTF-8');
} else if ($format === "jsonp") {
$xsl->load('xmltojsonp-compact.xsl');
header('Content-Type: application/javascript; charset=UTF-8');
}
$xp->importStyleSheet($xsl);
$xp->setParameter('', 'decimalSupported', 'no');
if ($callback && $format === "jsonp")
$xp->setParameter('', 'callback', $callback);
$xml = new DomDocument;
$contents = file_get_contents($url);
if ($contents) {
$xml->loadXML($contents);
if ($xform = $xp->transformToXML($xml)) {
echo $xform;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
}
} else {
trigger_error('URL could not be loaded.', E_USER_ERROR);
}
?>