Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <a href="http://www.w3.org/TR/xslt" rel="nofollow noreferrer">xsl(t)</a> and <a href="http://docs.php.net/class.xsltprocessor" rel="nofollow noreferrer">php's XSLTProcessor</a>.<br> In xslt 2.0 you could use something like</p> <pre><code>&lt;xsl:for-each-group select="release" group-by="title"&gt; </code></pre> <p>Unfortunately <a href="http://xmlsoft.org/XSLT/" rel="nofollow noreferrer">libxslt</a> doesn't support this (at least the version used in the php.net win32 build of php 5.3.2 doesn't).<br> But you can use the <a href="http://radio-weblogs.com/0118231/stories/2005/05/25/areYouTheGuyWhoDiscoveredTheMuenchianMethodOfGroupingInXslt.html" rel="nofollow noreferrer">Muenchian grouping method</a>.</p> <p>test.xsl:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="html" version="4.0" encoding="utf-8" indent="yes"/&gt; &lt;xsl:key name="release-by-title" match="release" use="title" /&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;...&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;xsl:apply-templates /&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="releases"&gt; &lt;table border="1"&gt; &lt;xsl:for-each select="release[count(. | key('release-by-title', title)[1]) = 1]"&gt; &lt;xsl:sort select="title" /&gt; &lt;tr&gt; &lt;th colspan="3"&gt;&lt;xsl:value-of select="title" /&gt;&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="key('release-by-title', title)"&gt; &lt;xsl:sort select="year" /&gt; &lt;tr&gt; &lt;td&gt;&lt;xsl:value-of select="year" /&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="label" /&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="format" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>test.xml containing the xml document you provided.<br> And test.php:</p> <pre><code>&lt;?php $doc = new DOMDocument; $doc-&gt;load('test.xsl'); $stylesheet = new XSLTProcessor; $stylesheet-&gt;importStyleSheet($doc); $doc-&gt;load('test.xml'); header('Content-type: text/html; charset=utf-8'); echo $stylesheet-&gt;transformToXML($doc); </code></pre> <p>And the output (onlye the &lt;table&gt;-part) is:</p> <pre><code>&lt;table border="1"&gt; &lt;tr&gt;&lt;th colspan="3"&gt;The M.O.F Blend&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;2002&lt;/td&gt; &lt;td&gt;Blenda Records&lt;/td&gt; &lt;td&gt;LP&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;2002&lt;/td&gt; &lt;td&gt;Blenda Records&lt;/td&gt; &lt;td&gt;CD&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;th colspan="3"&gt;Versions&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;1999&lt;/td&gt; &lt;td&gt;Not On Label&lt;/td&gt; &lt;td&gt;12", EP&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;th colspan="3"&gt;Ännu En Gång Vol. 3&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;2001&lt;/td&gt; &lt;td&gt;Hemmalaget&lt;/td&gt; &lt;td&gt;Cass, Comp, Mix&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Now, that's not much of an explaination. But maybe it gives you some hints to what to search for.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload