I have some XML, a XSL file and 4 CSS files. I am trying to process the XML using XSLTProcessor but it isn't working.
$xml = new DomDocument;
$xml->load('label.xml');
$xsl = new DomDocument;
$xsl->load('HTMLRestOfWorldRoutingLabelRendererOrig.xsl');
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
$result = $proc->transformToXML($xml);
echo $result;
But this just displays the below without any sort of formatting.
<?xml version="1.0"?>
1
1.11kg
piece1
1100123456782011641024001011
123456782|123456782||1||John Smith|TNT Express|ATHERSTONE|CV9 1TT|GB|S||TNT Corporate Head Office|Neptunusstraat 41-63|AMSTERDAM|1011 AA|NL||EX|N|PR||||0|12.34|GBP|N|piecelinegoods desc|3|1.11|1.3676310000000003|N|18 Jan 2012|13:51:00
2
1.11kg
piece1
1100123456782021641024001011
123456782|123456782||2||John Smith|TNT Express|ATHERSTONE|CV9 1TT|GB|S||TNT Corporate Head Office|Neptunusstraat 41-63|AMSTERDAM|1011 AA|NL||EX|N|PR||||0|12.34|GBP|N|piecelinegoods desc|3|1.11|1.3676310000000003|N|18 Jan 2012|13:51:00
3
1.11kg
piece3
1100123456782031641024001011
123456782|123456782||3||John Smith|TNT Express|ATHERSTONE|CV9 1TT|GB|S||TNT Corporate Head Office|Neptunusstraat 41-63|AMSTERDAM|1011 AA|NL||EX|N|PR||||0|12.34|GBP|N|piecelinegoods desc|3|1.11|1.3676310000000003|N|18 Jan 2012|13:51:00
123456782
John Smith
TNT Express
TNT House
ATHERSTONE
Warks
CV9 1TT
GB
TNT Corporate Head Office
Neptunusstraat 41-63
2132 JA Hoofddorp
AMSTERDAM
1011 AA
NL
100445
GB
3
Express
PR
2012-01-18
INT
AIR
C
2
CVT
EMA
LGG
SP8
19
2012-01-19
01
GBP 12.34
BSH
My label.xml is at http://pastebin.com/Shm09jCK
I have uploaded HTMLRestOfWorldRoutingLabelRendererOrig.xsl to http://pastebin.com/QPXE3B0r
I must be missing something obvious but this is new to me and I am not sure!
Try:
<xsl:output method="html" />
In your XSLT code there isn't any template that has a
match
attribute. This means that none of the templates are executed and the XSLT processor applies the built-in (default) templates for every node type.The net result from applying the built-in templates is that the output is a concatenation of all text nodes in the source XML document -- which is exactly what you get.
Solution:
Define at least one matching template such as
<xsl:template match="/">
. Within the code of this template you may call your named templates, though calling templates is generally a bad practice and applying templates should generally be preferred.