Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL to show highest number of copies in catalog.xml file
    primarykey
    data
    text
    <p>In this the <code>catalog.xml</code> file. I have two books who have the same inventory (i.e. 20). I want to write an XSL file that will display the highest number of copies of a book in a catalog. If there are two or more books of the same inventory then they have to be displayed.</p> <pre><code>&lt;catalog&gt; &lt;Book&gt; &lt;sku&gt;12345&lt;/sku&gt; &lt;title&gt;Beauty Secrets&lt;/title&gt; &lt;condition&gt;New&lt;/condition&gt; &lt;current_inventory&gt;20&lt;/current_inventory&gt; &lt;price&gt;99.99&lt;/price&gt; &lt;/Book&gt; &lt;Book&gt; &lt;sku&gt;54321&lt;/sku&gt; &lt;title&gt;Picturescapes&lt;/title&gt; &lt;current_inventory&gt;20&lt;/current_inventory&gt; &lt;condition&gt;New&lt;/condition&gt; &lt;price&gt;50.00&lt;/price&gt; &lt;/Book&gt; &lt;Book&gt; &lt;sku&gt;33333&lt;/sku&gt; &lt;title&gt;Tourist Perspectives&lt;/title&gt; &lt;condition&gt;New&lt;/condition&gt; &lt;current_inventory&gt;0&lt;/current_inventory&gt; &lt;price&gt;75.00&lt;/price&gt; &lt;/Book&gt; &lt;Book&gt; &lt;sku&gt;10001&lt;/sku&gt; &lt;title&gt;Fire in the Sky&lt;/title&gt; &lt;condition&gt;Used&lt;/condition&gt; &lt;current_inventory&gt;0&lt;/current_inventory&gt; &lt;price&gt;10.00&lt;/price&gt; &lt;/Book&gt; &lt;/catalog&gt; </code></pre> <p>Below is my <code>catalog3.xsl</code> file which is able to display only one out of the two books:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:variable name="max"/&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;h2&gt;Titles of Books for which Most Copies are Available&lt;/h2&gt; &lt;table border="2"&gt; &lt;tr bgcolor="#9acd32"&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;No of Copies&lt;/th&gt; &lt;/tr&gt; &lt;xsl:apply-templates/&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="catalog"&gt; &lt;xsl:for-each select="Book"&gt; &lt;xsl:sort select="current_inventory" data-type="number" order="descending"/&gt; &lt;tr&gt; &lt;xsl:if test="position()= 1"&gt; &lt;p&gt;&lt;xsl:value-of select="$max = "/&gt;&lt;/p&gt; &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="current_inventory"/&gt;&lt;/td&gt; &lt;/xsl:if&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Could anybody correct me to achieve my goal of displaying all the copies having the same maximum inventory in the catalog. Thanks.</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.
 

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