Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>XSLT 1.0:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;!-- index Description elements by their text value --&gt; &lt;xsl:key name="kDescription" match="Description" use="text()" /&gt; &lt;xsl:template match="/"&gt; &lt;output&gt; &lt;!-- process all Description elements... --&gt; &lt;xsl:apply-templates select="Problems/Problem/Description"&gt; &lt;!-- ...sorted by their own text value, ascending --&gt; &lt;xsl:sort select="text()" /&gt; &lt;!-- pass in the File value that we want to filter for --&gt; &lt;xsl:with-param name="file" select="'file1'" /&gt; &lt;/xsl:apply-templates&gt; &lt;/output&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Description"&gt; &lt;xsl:param name="file" select="''" /&gt; &lt;!-- check if the current Description node is the first in its respective group, that has a File value we care for --&gt; &lt;xsl:if test=" $file != '' and generate-id() = generate-id(key('kDescription', .)[../File = $file][1]) "&gt; &lt;!-- for the sake of simplicity, just make a copy here --&gt; &lt;xsl:copy-of select="." /&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>With this input:</p> <pre><code>&lt;Problems&gt; &lt;Problem&gt; &lt;File&gt;file1&lt;/File&gt; &lt;Description&gt;desc1&lt;/Description&gt; &lt;/Problem&gt; &lt;Problem&gt; &lt;File&gt;file1&lt;/File&gt; &lt;Description&gt;desc2&lt;/Description&gt; &lt;/Problem&gt; &lt;Problem&gt; &lt;File&gt;file2&lt;/File&gt; &lt;Description&gt;desc3&lt;/Description&gt; &lt;/Problem&gt; &lt;Problem&gt; &lt;File&gt;file2&lt;/File&gt; &lt;Description&gt;desc1&lt;/Description&gt; &lt;/Problem&gt; &lt;Problem&gt; &lt;File&gt;file1&lt;/File&gt; &lt;Description&gt;desc2&lt;/Description&gt; &lt;/Problem&gt; &lt;/Problems&gt; </code></pre> <p>I get:</p> <pre><code>&lt;output&gt; &lt;Description&gt;desc1&lt;/Description&gt; &lt;Description&gt;desc2&lt;/Description&gt; &lt;/output&gt; </code></pre> <p>A brief explanation of the part of the stylesheet that does the heavy lifting:</p> <pre><code>$file != '' and generate-id() = generate-id(key('kDescription', .)[../File = $file][1]) </code></pre> <p>The first part is obvious - it's just there to make sure that a <code>$file</code> filter string was passed in.</p> <p>The second part is plain Muenchian grouping with a little twist. It compares the IDs of two nodes, the current one (<code>generate-id()</code>) and one from the <code>kDescription</code> group, filtered by <code>$file</code> value. </p> <p><code>kDescription</code> indexes <code>&lt;Description&gt;</code> elements by their text value, which means that nodes with the same text but a different accompanying <code>&lt;File&gt;</code> will be returned by the call to <code>key()</code>. We need to filter them out.</p> <p>If the current node is equal to the first node of the group that has the right <code>&lt;File&gt;</code> value, the test succeeds and something gets printed, otherwise nothing happens.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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