Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This question requires a little bit more detailed answer</strong> than just pointing to a good <a href="http://dpawson.co.uk/xsl/sect2/N4486.html#d6060e85" rel="nofollow noreferrer"><strong>Muenchian Grouping</strong></a> source.</p> <p>The reason is that <strong>the needed grouping requires to identify both the names of all children of an "ele[SomeString]" element and their parent</strong>. <a href="http://dpawson.co.uk/xsl/sect2/N4486.html#d6060e238" rel="nofollow noreferrer"><strong>Such grouping</strong></a> requires to define a key that is uniquely defined by both unique sources, usually via concatenation.</p> <p><strong>This transformation</strong>:</p> <pre> &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> &lt;xsl:output omit-xml-declaration="yes" indent="yes"/> &lt;xsl:key name="kElByName" match="*" use="concat(generate-id(..), '+',name())"/> &lt;xsl:template match="node()|@*"> &lt;xsl:copy> &lt;xsl:apply-templates select="node()|@*"/> &lt;/xsl:copy> &lt;/xsl:template> &lt;xsl:template match="*[starts-with(name(), 'ele')]"> &lt;xsl:copy> &lt;xsl:copy-of select="@*"/> &lt;xsl:apply-templates select= "*[generate-id() = generate-id(key('kElByName', concat(generate-id(..), '+',name()) )[1]) ]" /> &lt;/xsl:copy> &lt;/xsl:template> &lt;/xsl:stylesheet> </pre> <p><strong>when applied on this XML document</strong>:</p> <pre> &lt;Root> &lt;ele1> &lt;child1>context1&lt;/child1> &lt;child2>test1&lt;/child2> &lt;child1>context1&lt;/child1> &lt;/ele1> &lt;ele2> &lt;child1>context2&lt;/child1> &lt;child2>test2&lt;/child2> &lt;child1>context2&lt;/child1> &lt;/ele2> &lt;ele3> &lt;child2>context2&lt;/child2> &lt;child2>test2&lt;/child2> &lt;child1>context1&lt;/child1> &lt;/ele3> &lt;/Root> </pre> <p><strong>produces the wanted result</strong>:</p> <pre> &lt;Root> &lt;ele1> &lt;child1>context1&lt;/child1> &lt;child2>test1&lt;/child2> &lt;/ele1> &lt;ele2> &lt;child1>context2&lt;/child1> &lt;child2>test2&lt;/child2> &lt;/ele2> &lt;ele3> &lt;child2>context2&lt;/child2> &lt;child1>context1&lt;/child1> &lt;/ele3> &lt;/Root> </pre>
    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. 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.
    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