title: Delimiting the output for xslt (in non trivial cases)
body: <p>I would like to know the best way to delimit xml output in an xsl transform.  "position() != last()" doesn't always work because it makes assumptions about the input.</p>
  
  <p>This toy example demonstrates:</p>
  
  <pre><code>  &lt;xsl:template match="/"&gt;
      &lt;html&gt;
        &lt;body&gt;
          &lt;xsl:for-each select="//cd"&gt;
            &lt;xsl:if test="title !='Unchain my heart'"&gt;
              &lt;xsl:value-of select="title" /&gt;
              &lt;xsl:if test="position() != last()"&gt;
                &lt;xsl:text&gt;; &lt;/xsl:text&gt;  &lt;!-- sometimes the delimiter will end if last element is a duplicate; --&gt;
              &lt;/xsl:if&gt;
            &lt;/xsl:if&gt;
          &lt;/xsl:for-each&gt;
        &lt;/body&gt;
      &lt;/html&gt;
    &lt;/xsl:template&gt;
  </code></pre>
  
  <p>will result in</p>
  
  <pre><code>... Pavarotti Gala Concert; The dock of the bay; Picture book; Red; 
  </code></pre>
  
  <p>note the trailing semicolon.</p>
  
  <p>Any ideas?</p>
  
  <p>(xml data from this example <a href="http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&amp;xsltfile=cdcatalog" rel="nofollow">http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&amp;xsltfile=cdcatalog</a>)</p>