I'm writing an application to display a event calendar in a browser. The events and dates are stored in a XML-File. For the transformation I use XSLT and SVG to generate a XHTML Page. I use PHP to transform the XML-File with XSLT dynamically on the server.
Right now, I'm able to load the current month and display the Calendar successfully. My goal now is to implement a button into the XSLT, and switch to the next month on button click. To achieve this, I'm trying to call a PHP function out of the XSLT.
This is what I tried so far: calendar.xsl:
<xsl:stylesheet version="1.0" xmlns:html="http://ift.tt/lH0Osb" xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:svg="http://ift.tt/nvqhV5" xmlns:xlink="http://ift.tt/PGV9lw" xmlns:php="http://php.net/xsl">
<xsl:template match="/">
...
<svg:a xlink:href="php:function('Calendar::nextMonth')">
<svg:text x="15" y="15" fill="red">NEXT</svg:text>
</svg:a>
...
index.php
<?php header('Content-type: image/svg+xml');
include 'calendar.php';
Calendar::loadCalender("2", "2015", "calendar.xml", "calendar.xsl");
?>
calendar.php
public static function nextMonth() {
self::loadCalender("3", "2015", "calendar.xml", "calendar.xsl");
}
public static function loadCalender($month, $year, $xmlfile, $xslfile) {
$xslDoc = new DOMDocument();
$xslDoc->load($xslfile);
$xmlDoc = new DOMDocument();
$xmlDoc->load($xmlfile);
$xsltProcessor = new XSLTProcessor();
$xsltProcessor->registerPHPFunctions();
$xsltProcessor->importStyleSheet($xslDoc);
$xsltProcessor->setParameter('','yearToDisplay', $year);
$xsltProcessor->setParameter('','monthToDisplay', $month);
echo $xsltProcessor->transformToXML($xmlDoc);
}
If I open index.php, the XSLT Transformation works without any problems and I can see the first month. But if I push the NEXT button, nothing happens. How can I achieve this? I'm pretty new to PHP and XSLT.
No comments:
Post a Comment