[xsl] Average result out of scope to then sort elements

Subject: [xsl] Average result out of scope to then sort elements
From: "Fran" <franciscojose@xxxxxxxxxxx>
Date: Wed, 21 Jan 2004 16:20:16 +0100
 Hi list, I've a problem and I can't find a good solution. I try to paint
all "x" elements sorting by their average result of all their "z" childrens
but a have the variable out of scope. I know that I can't utilize variables
out of their scope(for each loop)  in my XSL but I don't know how do this.
I do this with this XML:
     XML
 <x id="1">
   <y>
     <z price="32">
     <z price="45">
     <z price="67">
   <y>
</x>
<x id="2">
   <y>
     <z price="36">
     <z price="46">
     <z price="37">
   <y>
</x>

  <XSL>
   ......
      <xsl:for-each select="X">

		<xsl:for-each  select="y">
                       <!-- I calculate here the average of their
children-->
                          <xsl:variable name="resultz"
select='format-number(sum(z/@preciouni) div count(z/@preciouni), "#.00")' />
		</xsl:for-each>

           <xsl:sort select="$resultz" data-type="number"
order="descending"/> <!--Sort x elements by their average-->

         <xsl:value-of select="@id"/>
         <xsl:value-of select="$resultz"/>
     </xsl:for-each>

Any suggestion, please?
Regards
Frank



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread