Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is a response that assumes that you don't have any mixed content in your data. It only takes into account the two first steps (@name and @col), you can adapt for further steps. Maybe it can be rewritten with a recursive named template that takes the list of your sorting param as input. Could you provide an XML sample if my XSLT don't work for you.</p> <p>XSLT 2.0 sample :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt; &lt;xsl:template match="*"&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="@*"/&gt; &lt;xsl:for-each-group select="*" group-by="if (exists(@name)) then @name else ''"&gt; &lt;xsl:sort select="current-grouping-key()" data-type="text"/&gt; &lt;xsl:for-each-group select="current-group()" group-by="if (exists(@row)) then @row else -1"&gt; &lt;xsl:sort select="current-grouping-key()" data-type="number"/&gt; &lt;xsl:apply-templates select="current-group()"/&gt; &lt;/xsl:for-each-group&gt; &lt;/xsl:for-each-group&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Note that the code iterates on a group with same values, so that if an attribute is not present on elements, the elements are grouped together.</p> <p>I take as Input the following XML :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;items&gt; &lt;item row="5" col="9"&gt;&lt;/item&gt; &lt;item name="d" row="20" col="12" tabindex="" sequence=""&gt;&lt;/item&gt; &lt;item row="1" col="5" &gt;&lt;/item&gt; &lt;item name="d" row="5" col="6" &gt;&lt;/item&gt; &lt;item name="a" row="7" col="8" &gt;&lt;/item&gt; &lt;item name="s" row="1" col="5" &gt;&lt;/item&gt; &lt;item name="c" row="5" col="9"&gt;&lt;/item&gt; &lt;item row="2" col="5" &gt;&lt;/item&gt; &lt;item row="20" col="9"&gt;&lt;/item&gt; &lt;item row="0" col="9"&gt;&lt;/item&gt; &lt;item name="s" row="2" col="10" tabindex="" sequence=""&gt;&lt;/item&gt; &lt;item name="z" row="8" col="15" tabindex="" sequence=""&gt;&lt;/item&gt; &lt;/items&gt; </code></pre> <p>I have the following result :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;items&gt; &lt;item row="0" col="9"/&gt; &lt;item row="1" col="5"/&gt; &lt;item row="2" col="5"/&gt; &lt;item row="5" col="9"/&gt; &lt;item row="20" col="9"/&gt; &lt;item name="a" row="7" col="8"/&gt; &lt;item name="c" row="5" col="9"/&gt; &lt;item name="d" row="5" col="6"/&gt; &lt;item name="d" row="20" col="12" tabindex="" sequence=""/&gt; &lt;item name="s" row="1" col="5"/&gt; &lt;item name="s" row="2" col="10" tabindex="" sequence=""/&gt; &lt;item name="z" row="8" col="15" tabindex="" sequence=""/&gt; &lt;/items&gt; </code></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. 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