Skip to content

Commit bfeb05c

Browse files
committed
On non Linux OS, resolve xsl:import in PHP to work around
libxml/libxslt issues on these platforms. This should fix #255, potentially fix #288
1 parent b71c43c commit bfeb05c

File tree

13 files changed

+147
-41
lines changed

13 files changed

+147
-41
lines changed

src/generator/engine/AbstractEngine.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ abstract class AbstractEngine implements EngineInterface {
4747
protected function getXSLTProcessor($template) {
4848
$tpl = new fDomDocument();
4949
$tpl->load($template);
50-
$xsl = new fXSLTProcessor($tpl);
51-
return $xsl;
50+
if (stripos(PHP_OS, 'Linux') !== 0) {
51+
$this->resolveImports($tpl);
52+
}
53+
return new fXSLTProcessor($tpl);
5254
}
5355

5456
protected function clearDirectory($path) {
@@ -94,6 +96,27 @@ protected function copyStatic($path, $dest, $recursive = true) {
9496
}
9597
}
9698

99+
private function resolveImports(fDOMDocument $doc) {
100+
$doc->registerNamespace('xsl', 'http://www.w3.org/1999/XSL/Transform');
101+
$baseDir = dirname($doc->documentURI);
102+
$baseElement = $doc->documentElement;
103+
foreach($doc->query('/xsl:stylesheet/xsl:import') as $importNode) {
104+
/** @var $importNode \DOMElement */
105+
$import = new fDOMDocument();
106+
$import->load($baseDir . '/' . $importNode->getAttribute('href'));
107+
108+
$newParent = $importNode->parentNode;
109+
foreach ($import->documentElement->childNodes as $child) {
110+
if ($child->localName === 'output') {
111+
continue;
112+
}
113+
$importedChild = $doc->importNode($child, true);
114+
$newParent->insertBefore($importedChild, $importNode);
115+
}
116+
$newParent->removeChild($importNode);
117+
}
118+
}
119+
97120
}
98121

99122
class EngineException extends \Exception {

templates/html/class.xsl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
<?xml version="1.0" ?>
21
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
32
xmlns="http://www.w3.org/1999/xhtml"
43
xmlns:pdx="http://xml.phpdox.net/src"
54
xmlns:pdxf="http://xml.phpdox.net/functions"
65
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
7-
exclude-result-prefixes="pdx pdxf pu">
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
812

913
<xsl:import href="components.xsl" />
1014
<xsl:import href="functions.xsl" />

templates/html/components.xsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
xmlns="http://www.w3.org/1999/xhtml"
33
xmlns:pdx="http://xml.phpdox.net/src"
44
xmlns:pdxf="http://xml.phpdox.net/functions"
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
58
xmlns:git="http://xml.phpdox.net/gitlog"
6-
exclude-result-prefixes="pdx pdxf git">
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
712

813
<xsl:param name="base" select="''" />
914
<xsl:param name="xml" select="''" />

templates/html/directory.xsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22
xmlns="http://www.w3.org/1999/xhtml"
3-
xmlns:ctx="ctx://engine/html"
3+
xmlns:pdx="http://xml.phpdox.net/src"
44
xmlns:pdxf="http://xml.phpdox.net/functions"
5-
xmlns:pdx="http://xml.phpdox.net/src">
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
612

713
<xsl:import href="components.xsl" />
814
<xsl:import href="functions.xsl" />

templates/html/functions.xsl

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22
xmlns="http://www.w3.org/1999/xhtml"
3-
xmlns:func="http://exslt.org/functions"
3+
xmlns:pdx="http://xml.phpdox.net/src"
44
xmlns:pdxf="http://xml.phpdox.net/functions"
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
510
extension-element-prefixes="func"
6-
exclude-result-prefixes="pdxf">
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
712

813
<func:function name="pdxf:link">
9-
<xsl:param name="ctx" />
10-
<xsl:param name="method" />
11-
<xsl:param name="copy" />
14+
<xsl:param name="ctx"/>
15+
<xsl:param name="method"/>
16+
<xsl:param name="copy"/>
1217

1318
<xsl:variable name="dir">
1419
<xsl:choose>
@@ -27,50 +32,65 @@
2732
</xsl:variable>
2833

2934
<xsl:variable name="withMethod">
30-
<xsl:if test="$method != ''"><xsl:value-of select="concat('/', $method)" /></xsl:if>
35+
<xsl:if test="$method != ''">
36+
<xsl:value-of select="concat('/', $method)"/>
37+
</xsl:if>
3138
</xsl:variable>
3239

3340
<xsl:variable name="link">
34-
<xsl:value-of select="concat($base, $dir, '/', translate($ctx/@full, '\', '_'), $withMethod, '.', $extension)" />
41+
<xsl:value-of
42+
select="concat($base, $dir, '/', translate($ctx/@full, '\', '_'), $withMethod, '.', $extension)"/>
3543
</xsl:variable>
3644

3745
<xsl:variable name="text">
3846
<xsl:choose>
39-
<xsl:when test="$copy"><xsl:value-of select="$copy" /></xsl:when>
40-
<xsl:otherwise><xsl:value-of select="$ctx/@name" /></xsl:otherwise>
47+
<xsl:when test="$copy">
48+
<xsl:value-of select="$copy"/>
49+
</xsl:when>
50+
<xsl:otherwise>
51+
<xsl:value-of select="$ctx/@name"/>
52+
</xsl:otherwise>
4153
</xsl:choose>
4254
</xsl:variable>
4355

4456
<func:result>
4557
<xsl:choose>
46-
<xsl:when test="$ctx/@unresolved = 'true'"><xsl:value-of select="$text" /></xsl:when>
47-
<xsl:otherwise><a title="{$ctx/@full}" href="{$link}"><xsl:value-of select="$text" /></a></xsl:otherwise>
58+
<xsl:when test="$ctx/@unresolved = 'true'">
59+
<xsl:value-of select="$text"/>
60+
</xsl:when>
61+
<xsl:otherwise>
62+
<a title="{$ctx/@full}" href="{$link}">
63+
<xsl:value-of select="$text"/>
64+
</a>
65+
</xsl:otherwise>
4866
</xsl:choose>
4967
</func:result>
5068
</func:function>
5169

5270
<func:function name="pdxf:nl2br">
53-
<xsl:param name="string"/>
54-
<xsl:variable name="format">
71+
<xsl:param name="string"/>
72+
<xsl:variable name="format">
5573
<xsl:value-of select="normalize-space(substring-before($string,'&#10;'))"/>
5674
<xsl:choose>
5775
<xsl:when test="contains($string,'&#10;')">
58-
<br />
59-
<xsl:copy-of select="pdxf:nl2br(substring-after($string,'&#10;'))" />
76+
<br/>
77+
<xsl:copy-of select="pdxf:nl2br(substring-after($string,'&#10;'))"/>
6078
</xsl:when>
6179
<xsl:otherwise>
6280
<xsl:value-of select="$string"/>
6381
</xsl:otherwise>
6482
</xsl:choose>
65-
</xsl:variable>
66-
<func:result><xsl:copy-of select="$format" /></func:result>
83+
</xsl:variable>
84+
<func:result>
85+
<xsl:copy-of select="$format"/>
86+
</func:result>
6787
</func:function>
6888

6989
<func:function name="pdxf:format-number">
7090
<xsl:param name="value"/>
7191
<xsl:param name="format">0.##</xsl:param>
72-
<func:result>
73-
<xsl:choose>
92+
<func:result>
93+
<xsl:choose>
7494
<xsl:when test="string(number($value))='NaN'">
7595
<xsl:value-of select="format-number(0, $format)"/>
7696
</xsl:when>
@@ -82,7 +102,7 @@
82102
</func:function>
83103

84104
<func:function name="pdxf:filesize">
85-
<xsl:param name="bytes" />
105+
<xsl:param name="bytes"/>
86106

87107
<func:result>
88108
<xsl:choose>

templates/html/index.xsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22
xmlns="http://www.w3.org/1999/xhtml"
3-
xmlns:git="http://xml.phpdox.net/gitlog"
43
xmlns:pdx="http://xml.phpdox.net/src"
5-
xmlns:pdxf="http://xml.phpdox.net/functions">
4+
xmlns:pdxf="http://xml.phpdox.net/functions"
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
612

713
<xsl:import href="functions.xsl"/>
814
<xsl:import href="components.xsl" />

templates/html/interface.xsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22
xmlns="http://www.w3.org/1999/xhtml"
33
xmlns:pdx="http://xml.phpdox.net/src"
4-
xmlns:idx="http://xml.phpdox.net/src"
54
xmlns:pdxf="http://xml.phpdox.net/functions"
6-
exclude-result-prefixes="idx pdx pdxf">
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
712

813
<xsl:import href="components.xsl" />
914
<xsl:import href="functions.xsl" />

templates/html/method.xsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
xmlns:pdx="http://xml.phpdox.net/src"
44
xmlns:pdxf="http://xml.phpdox.net/functions"
55
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6-
exclude-result-prefixes="pdx pdxf">
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
712

813
<xsl:import href="components.xsl" />
914
<xsl:import href="functions.xsl" />

templates/html/namespaces.xsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22
xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:pdx="http://xml.phpdox.net/src"
4+
xmlns:pdxf="http://xml.phpdox.net/functions"
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
37
xmlns:idx="http://xml.phpdox.net/src"
4-
exclude-result-prefixes="idx">
8+
xmlns:git="http://xml.phpdox.net/gitlog"
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
512

613
<xsl:import href="components.xsl" />
7-
814
<xsl:output method="xml" indent="yes" encoding="UTF-8" doctype-system="about:legacy-compat" />
915

1016
<xsl:template match="/">

templates/html/reports/index.xsl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22
xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:pdx="http://xml.phpdox.net/src"
4+
xmlns:pdxf="http://xml.phpdox.net/functions"
5+
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
6+
xmlns:func="http://exslt.org/functions"
7+
xmlns:idx="http://xml.phpdox.net/src"
38
xmlns:git="http://xml.phpdox.net/gitlog"
4-
xmlns:pdx="http://xml.phpdox.net/src">
9+
xmlns:ctx="ctx://engine/html"
10+
extension-element-prefixes="func"
11+
exclude-result-prefixes="idx pdx pdxf pu git ctx">
512

613
<xsl:import href="../components.xsl" />
714

0 commit comments

Comments
 (0)