XSLT if two values of an element match then merge cells?
<p>I'm trying to create a piece of XHTML out of an XML and a XSLT file. </p>

<p>I want to test if the value of two or more XML elements coincide with other ones in the table, in which case, I want those cells to be merged in the result XHTML file.</p>

<p>I'll use a simple w3schools example for simplicity. (More people should do this on stackoverflow).</p>

<p>Here is the XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;catalog&gt;
&lt;cd&gt;
    &lt;title&gt;Empire Burlesque&lt;/title&gt;
    &lt;artist&gt;Bob Dylan&lt;/artist&gt;
&lt;/cd&gt;
&lt;cd&gt;
    &lt;title&gt;Empire Burlesque&lt;/title&gt;
    &lt;artist&gt;Bonnie Tyler&lt;/artist&gt;
&lt;/cd&gt;
&lt;cd&gt;
    &lt;title&gt;Empire Burlesque&lt;/title&gt;
    &lt;artist&gt;Mr G&lt;/artist&gt;
&lt;/cd&gt;
&lt;cd&gt;
    &lt;title&gt;Greatest Hits&lt;/title&gt;
    &lt;artist&gt;Dolly Parton&lt;/artist&gt;
&lt;/cd&gt;
&lt;/catalog&gt;
</code></pre>

<p>Here is the XSLT:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
&lt;xsl:template match="/"&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h2&gt;My CD Collection&lt;/h2&gt;
&lt;table border="1"&gt;
&lt;tr bgcolor="#9acd32"&gt;
  &lt;th&gt;Title&lt;/th&gt;
  &lt;th&gt;Artist&lt;/th&gt;
&lt;/tr&gt;
&lt;xsl:for-each select="catalog/cd"&gt;
&lt;tr&gt;
  &lt;xsl:choose&gt;
  &lt;xsl:when test="count(title) %gr 2"&gt;
     &lt;td rowspan="2"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
  &lt;/xsl:when&gt;
  &lt;xsl:otherwise&gt;
     &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
  &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;td&gt;&lt;xsl:value-of select="artist"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/xsl:for-each&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
</code></pre>

<p>The two elements in the XSLT that are wrong are: the TEST and ROWSPAN.</p>

<ol>
<li><p>How do I test if there are more than one instance for a title? (In this case Empire Burlesque)</p></li>
<li><p>How do I tell the program to merge these two cells in that case (so the output is one cell that says Empire Burlesque) with rowspan 3.</p></li>
</ol>

<p>NOTE: Please don't tell me to do test='Empire Burlesque'. I want it to work for other repeating instances if I where to add them in. Thank you.</p>