Skip to content

Commit

Permalink
Experiment with XSLT.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Davies committed Jan 25, 2011
1 parent d638c69 commit c8c4af8
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions classes/kohana/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class Kohana_Sitemap
* @var DOMElement
*/
protected $_root;

/**
* @var XSLTProcessor
*/
protected $_xslt;

protected $_styles = array();

/**
* Setup the XML document
Expand All @@ -19,6 +26,9 @@ public function __construct()
{
// XML document
$this->_xml = new DOMDocument('1.0', Kohana::$charset);

// XSLT
$this->_xslt = new XSLTProcessor;

// Attributes
$this->_xml->formatOutput = TRUE;
Expand All @@ -44,6 +54,20 @@ public function add( Sitemap_URL $object )
$this->_root->appendChild($this->_xml->importNode($url, TRUE));
}

/**
* Add an XSL to the root XML document.
*
* @param string $url
* @param constant Bitwise OR of the libxml option constants.
* @return Sitemap
*/
public function add_stylesheet($url, $options = NULL)
{
$this->_styles[] = array('location' => $url, 'options' => $options);

return $this;
}

/**
* Ping web services
*
Expand Down Expand Up @@ -122,6 +146,7 @@ public static function encode($string)
}

/**
*
* Format a unix timestamp into W3C Datetime
*
* @access public
Expand Down Expand Up @@ -154,9 +179,23 @@ public static function date_format($unix)
*/
public function render()
{
// Default uncompressed
$response = $this->_xml->saveXML();

if (empty($this->_styles))
{
$response = $this->_xml->saveXML();
}
else
{
foreach($this->_styles as $style)
{
$xsl = new DOMDocument;
$xsl->load($style['location'], $style['options']);

$this->_xslt->importStylesheet($xsl);
}

$response = $this->_xslt->transformToXML($this->_xml);
}

if ($this->gzip)
{
// Try and gzip the file before we send it off.
Expand Down

0 comments on commit c8c4af8

Please sign in to comment.