Note that there are some explanatory texts on larger screens.

plurals
  1. POxslt extract and sort leaf nodes by name - unexpected result
    primarykey
    data
    text
    <p>I wanted to extract leaf nodes and have them sorted. </p> <p>My XSL gives unexpected results. How can I solve this?</p> <p>Input</p> <pre><code>&lt;root&gt; &lt;b&gt; &lt;b33 zzz="2" fff="3"&gt;&lt;/b33&gt; &lt;b11&gt;&lt;/b11&gt; &lt;b22&gt;&lt;/b22&gt; &lt;/b&gt; &lt;a&gt; &lt;a27&gt;&lt;/a27&gt; &lt;a65 fff="0" eee="2" zzz="10"&gt;&lt;/a65&gt; &lt;a11&gt;&lt;/a11&gt; &lt;/a&gt; &lt;/root&gt; </code></pre> <p>Xsl</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/"&gt; &lt;root&gt; &lt;xsl:call-template name="leafnodes"/&gt; &lt;/root&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[not(*)]|@*" name="leafnodes"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()"&gt; &lt;xsl:sort select="name()"/&gt; &lt;/xsl:apply-templates&gt; &lt;xsl:apply-templates select="@*"&gt; &lt;xsl:sort select="name()"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Output (I would expected it to be sorted, it is not)</p> <pre><code>&lt;root&gt; &lt;b33 fff="3" zzz="2" /&gt; &lt;b11 /&gt; &lt;b22 /&gt; &lt;a27 /&gt; &lt;a65 eee="2" fff="0" zzz="10" /&gt; &lt;a11 /&gt; &lt;/root&gt; </code></pre> <p>I would expect the nodes in the order a11, a27, a65, b11, b22, b33.</p> <p>If I leave out the '[not(*)]', the xsl takes all nodes and sorts them properly. How can this be solved?</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. 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