XML : xsl triying to sort by count

i'm having an error trying to sort a list of products b a count of elements, having the xml:

  <segma>      <conservacio>          <cons estat="A">Excel·lent conservació</cons>          <cons estat="B">Bona conservació</cons>          <cons estat="C">Regular conservació</cons>          <cons estat="D">Mala conservació</cons>      </conservacio>        <categories>          <categoria cat="1">Mobiliari</categoria>          <categoria cat="2">Alimentació</categoria>          <categoria cat="3">Roba</categoria>      </categories>        <clients>          <registre dni="111">Marti</registre>          <registre dni="222">Jana</registre>          <registre dni="333">Edu</registre>          <registre dni="444">Santi</registre>          <registre dni="555">Mia</registre>          <registre dni="666">Pau M</registre>              </clients>        <productes>          <prod id="1" cons="A" cat="1">              <nom>Cuna</nom>              <preu_nou>70</preu_nou>              <preu>30</preu>              <ofertes>                  <oferta client="111" />                  <oferta client="333" />              </ofertes>              <venta client="111" />          </prod>            <prod id="2" cons="B" cat="2">              <nom>Baby cook</nom>              <preu_nou>120</preu_nou>              <preu>60</preu>              <ofertes>                  <oferta client="111" />                  <oferta client="333" />                  <oferta client="444" />                  <oferta client="555" />                    </ofertes>              <venta client="555" />          </prod>                     <prod id="3" cons="A" cat="1">              <nom>Mama pata</nom>              <preu_nou>70</preu_nou>              <preu>5</preu>              <ofertes>                  <oferta client="444" />                  <oferta client="555" />              </ofertes>              <venta client="444" />          </prod>                 <prod id="4" cons="B" cat="3">              <nom>Conjunt xandall</nom>              <preu_nou>40</preu_nou>              <preu>15</preu>              <ofertes>                  <oferta client="222" />                  <oferta client="555" />              </ofertes>              <venta client="222" />          </prod>             <prod id="5" cons="C" cat="3">              <nom>Pack 3 texans</nom>              <preu_nou>70</preu_nou>              <preu>25</preu>              <ofertes>                  <oferta client="333" />                  <oferta client="444" />                  <oferta client="555" />              </ofertes>              <venta client="333" />          </prod>             <prod id="6" cons="A" cat="2">              <nom>Saca leches</nom>              <preu_nou>130</preu_nou>              <preu>70</preu>              <ofertes>                  <oferta client="111" />                  <oferta client="222" />                  <oferta client="555" />              </ofertes>              <venta client="111" />          </prod>                 <prod id="7" cons="C" cat="2">              <nom>Llet continuació</nom>              <preu_nou>11</preu_nou>              <preu>3</preu>              <ofertes>              </ofertes>          </prod>                     </productes>  </segma>    

I want to see every product with the number of "oferta" sorted by how many "oferta" a product has, i'm triying with the following xls:

  <h2>Ex 7</h2>  <table border="1">      <xsl:for-each select="//prod">       <xsl:variable name="producte" select="@id"/>        <xsl:variable name="contador" select="count(//prod[@id=$producte]/ofertes/oferta)"/>        <xsl:sort select="$contador"/>        <tr>         <td>          <xsl:value-of select="nom"/>        </td>          <td>          <xsl:value-of select="$contador"/>        </td>       </tr>     </xsl:for-each>   </table>    

I wanted to have an output like:

  Baby Cook 4    Pack 3 texans 3    etc..    

Can somebody tell me why i'm in trouble??

No comments:

Post a Comment