I am unable to parse the following XSLT file with the code following:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" indent="yes" omit-xml-declaration="no" />
<!-- BASE -->
<xsl:template match="/root">
<html>
<head>
<title><xsl:value-of select="@title" /></title>
<style type="text/css">
<![CDATA[
h1, h2, h3, h4 {
text-transform:capitalize;
}
h5.date {
margin:0 0 0.5em 0;
font-size:1.2em;
width:25%;
text-align:center;
border:0.5px inset rgb(0,0,0);
}
div {
border:2px inset rgb(0,0,0);
}
div.date {
border:1px inset rgb(0,0,0);
background-color:rgb(255,255,230);
}
]]>
</style>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="/root/dir">
<div>
<h2><xsl:value-of select="@title" /></h2>
<xsl:apply-templates />
</div>
</xsl:template>
<!-- ALL FILES -->
<xsl:template match="/root/dir/file">
<div>
<xsl:choose>
<xsl:when test="document(.)/event">
<h3><xsl:value-of select="document(.)/event/@title" /></h3>
</xsl:when>
<xsl:when test="document(.)/interest">
<h3>
<xsl:value-of select="document(.)/interest/@title" />
<xsl:if test="document(.)/interest/advisor">
<em><xsl:text> </xsl:text>(<xsl:value-of select="document(.)/interest/advisor" />)</em>
</xsl:if>
</h3>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="document(.)" />
</div>
</xsl:template>
<!-- EVENTS -->
<xsl:template match="/event">
<xsl:apply-templates>
<xsl:sort select="@date" order="descending" type="text" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="/event/day">
<div class="date">
<h5 class="date"><xsl:value-of select="@date" /></h5>
<ul>
<xsl:apply-templates />
</ul>
</div>
</xsl:template>
<xsl:template match="/event/day/location">
<li><strong>Location:</strong><xsl:text> </xsl:text><xsl:value-of select="." /></li>
</xsl:template>
<xsl:template match="/event/day/times">
<li><strong>Times:</strong><xsl:text> </xsl:text><xsl:value-of select="begin" /> - <xsl:value-of select="end" /></li>
</xsl:template>
<xsl:template match="/event/day/credit">
<li>
<strong>
<xsl:choose>
<xsl:when test="@type = 'commserv'">
Community Service Hours:
</xsl:when>
</xsl:choose>
</strong>
<xsl:text> </xsl:text>
<xsl:value-of select="." />
</li>
</xsl:template>
<!-- INTERESTS -->
<xsl:template match="/interest">
<ul>
<xsl:apply-templates />
</ul>
</xsl:template>
<xsl:template match="/interest/advisor" />
<xsl:template match="/interest/start">
<li><strong>Cause:</strong>
<p><xsl:value-of select="." /></p>
</li>
</xsl:template>
<xsl:template match="/interest/ex">
<li>
<p><em>EX)</em><xsl:text> </xsl:text><xsl:value-of select="." /></p>
</li>
</xsl:template>
<xsl:template match="/interest/current">
<li><strong>Currently:</strong>
<p><xsl:value-of select="." /></p>
</li>
</xsl:template>
</xsl:stylesheet>
$xproc = new XSLTProcessor();
$xproc->importStyleSheet(DomDocument::load($stylesheet));
echo($xproc->transformToXML(DomDocument::loadXML($output)));
$output is equal to the XML below:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="style.xsl" ?>
<root title="Test">
<dir title="events">
<file title="fall-festival">data/events/fall-festival.xml</file>
<file title="nursing-home-visit">data/events/nursing-home-visit.xml</file>
</dir>
<dir title="interests">
<file title="japanese">data/interests/japanese.xml</file>
</dir>
<dir title="jobs">
</dir>
<dir title="traits">
</dir>
</root>
This is the error returned:
<br />
<b>Warning</b>: DOMDocument::loadXML() [<a href='function.loadXML'>function.loadXML</a>]: Premature end of data in tag root line 2 in Entity, line: 14 in <b>/var/www/localhost/htdocs/profile/index.php</b> on line <b>23</b><br />
<br />
<b>Warning</b>: XSLTProcessor::transformToXml() expects parameter 1 to be object, boolean given in <b>/var/www/localhost/htdocs/profile/index.php</b> on line <b>23</b><br />
</root>
Why does this method of parsing not work for the provided XML and XSLT?