Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:key name="kLineById0Id1" match="line[field[@id=2]]" use="concat(field[@id=0],'+',field[@id=1])"/&gt; &lt;xsl:template match= "line[field[@id=2] and generate-id() = generate-id(key('kLineById0Id1', concat(field[@id=0], '+',field[@id=1]) )[1]) ] "&gt; &lt;xsl:element name="type-{field[@id=0]}"&gt; &lt;document&gt; &lt;xsl:value-of select="field[@id=1]"/&gt; &lt;/document&gt; &lt;sum&gt; &lt;xsl:value-of select= "sum(key('kLineById0Id1', concat(field[@id=0], '+',field[@id=1]) ) /field[@id=2] ) "/&gt; &lt;/sum&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="text()"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;document&gt; &lt;line id="0"&gt; &lt;field id="0"&gt;MAR&lt;/field&gt; &lt;field id="1"&gt;doc1&lt;/field&gt; &lt;field id="2"&gt;2&lt;/field&gt; &lt;/line&gt; &lt;line id="1"&gt; &lt;field id="0"&gt;MAR&lt;/field&gt; &lt;field id="1"&gt;doc2&lt;/field&gt; &lt;field id="2"&gt;3&lt;/field&gt; &lt;/line&gt; &lt;line id="2"&gt; &lt;field id="0"&gt;AAA&gt;&lt;/field&gt; &lt;field id="1"&gt;doc4&lt;/field&gt; &lt;/line&gt; &lt;line id="3"&gt; &lt;field id="0"&gt;MAR&lt;/field&gt; &lt;field id="1"&gt;doc1&lt;/field&gt; &lt;field id="2"&gt;4&lt;/field&gt; &lt;/line&gt; &lt;/document&gt; </code></pre> <p><strong>produces the wanted, correct result:</strong></p> <pre><code>&lt;type-MAR&gt; &lt;document&gt;doc1&lt;/document&gt; &lt;sum&gt;6&lt;/sum&gt; &lt;/type-MAR&gt; &lt;type-MAR&gt; &lt;document&gt;doc2&lt;/document&gt; &lt;sum&gt;3&lt;/sum&gt; &lt;/type-MAR&gt; </code></pre> <p><strong>Explanation</strong>: The <strong><a href="http://www.jenitennison.com/xslt/grouping/muenchian.html" rel="nofollow">Muenchian method for grouping</a></strong> is used with the key defined as the concatenation of two elements.</p>
    singulars
    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.
    3. 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