Sandman wrote:
I appolagize for the length of the post.
What I really don't get is what he's going to do with the data. If he's
gonna print it, then XSL is the way to go, IMHO.
Ok, please elaborate - any suggestions are welcome!
You do like this:
<?php
// XML + XSL
$oXsl = xslt_create();
if ($sResult = xslt_process($oXsl, 'test.xml', 'test.xsl', NULL)){
echo $sResult;
} else {
die (xslt_error($oXsl));
}
xslt_free($oXsl);
?>
This will parse files test.xml and test.xsl which are located where the
script is located. The content of the files:
(test.xml)
<functions>
<function>
<name>array_push</name>
<examples>
<example>
<name>a way to do it</name>
<code>
<![CDATA[
$myArray = array("foo", "bar");
$myArray = array_push($myArray, "goo");
]]>
</code>
</example>
<example>
<name>another way</name>
<code>
<![CDATA[
$myArray = array("foo", "bar", "goo");
$myArray = array_push($myArray, "goo");
]]>
</code>
</example>
</examples>
</function>
<function>
<name>array_pop</name>
<examples>
<example>
<name>you use it like this (code doesn't work :)</name>
<code>
<![CDATA[
$myArray = array("foo", "bar");
$myArray = array_pop($myArray, "goo");
]]>
</code>
</example>
</examples>
</function>
</functions>
test.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="function">
<h1>
<xsl:value-of select="name"/>
</h1>
<xsl:for-each select="examples">
<xsl:for-each select="example">
<div>
<xsl:value-of select="name"/>
<pre>
<code>
<xsl:value-of select="code"/>
</code>
</pre>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output I got when finished:
<?xml version="1.0" encoding="UTF-8"?>
<h1>array_push</h1><div>a way to do it<pre><code>
$myArray = array("foo", "bar");
$myArray = array_push($myArray, "goo");
</code></pre></div><div>another way<pre><code>
$myArray = array("foo", "bar", "goo");
$myArray = array_push($myArray, "goo");
</code></pre></div>
<h1>array_pop</h1><div>you use it like this (code doesn't work
:)<pre><code>
$myArray = array("foo", "bar");
$myArray = array_pop($myArray, "goo");
</code></pre></div>
I am _really_ new to all this XSL business so this probably can be done much
cleaner, but this works :)
--
Dado
There is no time like the pleasant.