title: Sort list and eliminate duplicates in XSLT?
body: <p>Starting point is an XML-list like</p>
  
  <pre><code>&lt;attributes&gt;
          &lt;para role="tocmain1"/&gt;
          &lt;para role="tocmain1"/&gt;
          &lt;other style="fix"/&gt;
          &lt;other style="fix"/&gt;
          &lt;para role="tocmain2"/&gt;
          &lt;para role="tocmain2"/&gt;
          &lt;para role="tocmain2"/&gt;
          &lt;para role="tocmain3"/&gt;
          &lt;para role="tocmain3"/&gt;
          &lt;para language="de"/&gt;
          &lt;para language="de"/&gt;
          &lt;para role="tocmain3"/&gt;
  &lt;/attributes&gt;
  </code></pre>
  
  <p>I would like to reduce the occurrences of each element + attribute + value instance to just one occurrence.</p>
  
  <p>Like this:</p>
  
  <pre><code>&lt;attributes&gt;
       &lt;other style="fix"/&gt;
       &lt;para language="de"/&gt;
       &lt;para role="tocmain1"/&gt;
       &lt;para role="tocmain2"/&gt;
       &lt;para role="tocmain3"/&gt;    
  &lt;/attributes&gt;`
  </code></pre>
  
  <p>So far I have only succeeded to order the list alphabetically. All my attempts to reduce the list have been in vain so far.</p>
  
  <p>That is what I have right now:</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt;
  &lt;xsl:template match="/"&gt;
      &lt;attributes&gt;
          &lt;xsl:for-each select="attributes/node()"&gt;               
              &lt;xsl:sort select="name()" order="ascending"/&gt;           
              &lt;xsl:sort select="@*" order="ascending"/&gt;                   
              &lt;xsl:choose&gt; 
                  &lt;xsl:when test="name() = name(preceding::*[1]) and self::node()/@* = preceding::*/@*"/&gt; 
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:copy-of select="."/&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:for-each&gt; 
      &lt;/attributes&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>