Lillem4n thoughts

2010-01-10

A friend of mine needed to use the Kohana XML-module to create XML with a XSLT-stylesheet attatched to it. This is a quick example of how you could do that. There are several other ways, but this is pretty straight forward.

The following code should be placed inside a controller method:

// First we need a DOM document do begin with
$dom = new DomDocument('1.0', 'UTF-8');

// Format the output so we can read it more easily
$dom->formatOutput = true;

// This sets the used XSL stylesheet to "example.xsl"
$dom->appendChild($dom->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="example.xsl"'));

// We need a root node in the XML
$xml_root = $dom->appendChild($dom->createElement('root'));

// This is the big XML data... database queries and other nice data should be in here
// Right now there is only a tiny bit of foo-node and bar-content
$someXmlContent = array('foo' => 'bar');

2009-11-03

When adding modules to kohana, most oftenly you need to add that module to the config file to have it loaded. Now I find this mostly an unnecessary hassle. (Its useful when sharing module path between applications, though).

However, just comment out the module settings, replacing it with this code snippet: