title: how to use Parameter in XSL and count() correctly to get data from xml
body: <ol>
  <li>I am trying the following to pass a parameter by the state code and get the details for the orders based on state and the count of number of orders I tried the following code but I am not able to make the parameter work in xsl.</li>
  <li>Example I want to pass the parameter as getState=TX (where getState is the parameter name) and it should only get me the corresponding data of TX and the same applies to MO and CA. I'm limited to Xsl 1.0  also I am able to get the count but its printing outside the element I need it  like this <strong>&lt;state name=&quot;TX&quot; count &quot;2&quot;&gt;</strong></li>
  <li>The state has to be passed as a code only meaning TX,CA,MO (as a parameter not the full name)
  java -jar saxon-he-10.5.jar -xsl:walmart.xsl -s:orders.xml -o:testoutput.xml getState=TX -&gt; can anyone please confirm is this how its supposed to be passed while generating the output file?</li>
  <li>Output what I have currently looks like this it is sorted in descending based order of date. Can anyone please advice how the above can be achieved(count and parameter).</li>
  </ol>
  <p>The current output file looks as below</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;details&gt;
     &lt;state name="TX"&gt;count:2
     &lt;order date="2021-08-15"
               item="onions"
               address="amway avenue"
               phone="(432) 666-7890"
               inventory="9976454"/&gt;
     &lt;order date="2021-10-11"
               item="cereal"
               address="34 main st"
               phone="(212) 566-7670"
               inventory="0247556"/&gt;
     &lt;/state&gt;
     &lt;state name="CA"&gt;count:2
     &lt;order date="2021-02-19"
               item="eggs"
               address="Audobon st"
               phone="(232) 456-3211"
               inventory="0244559"/&gt;
     &lt;order date="2021-05-13"
               item="brocolli"
               address="47 apartment"
               phone="(444) 564-3433"
               inventory="3434654"/&gt;
     &lt;/state&gt;
     &lt;state name="MO"&gt;count:2
     &lt;order date="2021-02-27"
               item="fries"
               address="paseo blvd"
               phone="(309) 123-5644"
               inventory="2245526"/&gt;
     &lt;order date="2021-12-04"
               item="juice"
               address="locust st"
               phone="(309) 566-5555"
               inventory="2245556"/&gt;
     &lt;/state&gt;
  &lt;/details&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>walmart.xsl this is my xsl file which I tried</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
      &lt;xsl:param name="getState" select="response/walmart"/&gt;
      &lt;xsl:template match="/"&gt;
          &lt;xsl:element name="details"&gt;
              &lt;state name="TX"&gt;
          count:&lt;xsl:value-of select= "count(response/walmart[state = 'TX'])"/&gt;
                  &lt;xsl:apply-templates select="response/walmart[state = 'TX']"&gt;
                      &lt;xsl:sort select="order_date" order="ascending"/&gt;
                  &lt;/xsl:apply-templates&gt;
              &lt;/state&gt;
              &lt;state name="CA"&gt;
          count: &lt;xsl:value-of select= "count(response/walmart[state = 'CA'])"/&gt;
                  &lt;xsl:apply-templates select="response/walmart[state = 'CA']"&gt;
                      &lt;xsl:sort select="order_date" order="ascending"/&gt;
                  &lt;/xsl:apply-templates&gt;
              &lt;/state&gt;
              &lt;state name="MO"&gt;
          count:&lt;xsl:value-of select= "count(response/walmart[state = 'MO'])"/&gt;
                  &lt;xsl:apply-templates select="response/walmart[state = 'MO']"&gt;
                      &lt;xsl:sort select="order_date" order="ascending"/&gt;
                  &lt;/xsl:apply-templates&gt;
              &lt;/state&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="walmart"&gt;
          &lt;order date="{order_date}" item="{item}" address="{walmart_address}" phone ="{walmart_contact_phone}" inventory="{inventory_number}" &gt;
          &lt;/order&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>this is the xml file to pull data orders.xml</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;response&gt;
      &lt;walmart&gt;
          &lt;order_date&gt;2021-10-11&lt;/order_date&gt;
          &lt;item&gt;cereal&lt;/item&gt;
          &lt;state&gt;TX&lt;/state&gt;
          &lt;walmart_address&gt;34 main st&lt;/walmart_address&gt;
          &lt;walmart_contact_phone&gt;(212) 566-7670&lt;/walmart_contact_phone&gt;
          &lt;inventory_number&gt;0247556&lt;/inventory_number&gt;
      &lt;/walmart&gt;
      &lt;walmart&gt;
          &lt;order_date&gt;2021-05-13&lt;/order_date&gt;
          &lt;item&gt;brocolli&lt;/item&gt;
          &lt;state&gt;CA&lt;/state&gt;
          &lt;walmart_address&gt;47 apartment&lt;/walmart_address&gt;
          &lt;walmart_contact_phone&gt;(444) 564-3433&lt;/walmart_contact_phone&gt;
          &lt;inventory_number&gt;3434654&lt;/inventory_number&gt;
      &lt;/walmart&gt;
      &lt;walmart&gt;
          &lt;order_date&gt;2021-08-15&lt;/order_date&gt;
          &lt;item&gt;onions&lt;/item&gt;
          &lt;state&gt;TX&lt;/state&gt;
          &lt;walmart_address&gt;amway avenue&lt;/walmart_address&gt;
          &lt;walmart_contact_phone&gt;(432) 666-7890&lt;/walmart_contact_phone&gt;
          &lt;inventory_number&gt;9976454&lt;/inventory_number&gt;
      &lt;/walmart&gt;
      &lt;walmart&gt;
          &lt;order_date&gt;2021-02-19&lt;/order_date&gt;
          &lt;item&gt;eggs&lt;/item&gt;
          &lt;state&gt;CA&lt;/state&gt;
          &lt;walmart_address&gt;Audobon st&lt;/walmart_address&gt;
          &lt;walmart_contact_phone&gt;(232) 456-3211&lt;/walmart_contact_phone&gt;
          &lt;inventory_number&gt;0244559&lt;/inventory_number&gt;
      &lt;/walmart&gt;
      &lt;walmart&gt;
          &lt;order_date&gt;2021-12-04&lt;/order_date&gt;
          &lt;item&gt;juice&lt;/item&gt;
          &lt;state&gt;MO&lt;/state&gt;
          &lt;walmart_address&gt;locust st&lt;/walmart_address&gt;
          &lt;walmart_contact_phone&gt;(309) 566-5555&lt;/walmart_contact_phone&gt;
          &lt;inventory_number&gt;2245556&lt;/inventory_number&gt;
      &lt;/walmart&gt;
      &lt;walmart&gt;
          &lt;order_date&gt;2021-02-27&lt;/order_date&gt;
          &lt;item&gt;fries&lt;/item&gt;
          &lt;state&gt;MO&lt;/state&gt;
          &lt;walmart_address&gt;paseo blvd&lt;/walmart_address&gt;
          &lt;walmart_contact_phone&gt;(309) 123-5644&lt;/walmart_contact_phone&gt;
          &lt;inventory_number&gt;2245526&lt;/inventory_number&gt;
      &lt;/walmart&gt;
  &lt;/response&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Any inputs to make the code better and suggestions are much appreciated.</p>