Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT sort on more than one child node, per parent
    primarykey
    data
    text
    <p>I have the following XML:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;entries&gt; &lt;entry&gt; &lt;title&gt;Entry 1&lt;/title&gt; &lt;prices&gt; &lt;price&gt;10&lt;/price&gt; &lt;price&gt;50&lt;/price&gt; &lt;/prices&gt; &lt;/entry&gt; &lt;entry&gt; &lt;title&gt;Entry 2&lt;/title&gt; &lt;prices&gt; &lt;price&gt;200&lt;/price&gt; &lt;price&gt;300&lt;/price&gt; &lt;/prices&gt; &lt;/entry&gt; &lt;entry&gt; &lt;title&gt;Entry 3&lt;/title&gt; &lt;prices&gt; &lt;price&gt;70&lt;/price&gt; &lt;price&gt;500&lt;/price&gt; &lt;/prices&gt; &lt;/entry&gt; &lt;/entries&gt; </code></pre> <p>Each element has more than one price tag, I want to select the MAX price, per element and use it for comparison with the rest of the elements.</p> <p>My xslt is:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;table border="1"&gt; &lt;tr&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Highest Price&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="entries/entry"&gt; &lt;xsl:sort select="prices/price" order="descending" data-type="number"/&gt; &lt;tr&gt; &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="prices/price"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>It doesn't work. It produces:</p> <pre><code>Title Highest Price Entry 2 200 Entry 3 70 Entry 1 10 </code></pre> <p>While it should produce:</p> <pre><code>Title Highest Price Entry 3 500 Entry 2 300 Entry 1 50 </code></pre> <p>Please advise me. I have to use XSLT1, so I can't really do:</p> <pre><code>&lt;xsl:sort select="max(prices/price)" order="descending" data-type="number"/&gt; </code></pre> <p>...</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.
 

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