RE: [xsl] position()=last() always 1 problem

Subject: RE: [xsl] position()=last() always 1 problem
From: Donal Regan <donal_regan10@xxxxxxxxxxx>
Date: Fri, 16 Jan 2004 08:46:46 +0000 (GMT)
I got it working by adding an element <summed> before
the <xsl:for-each select="ratios"> and using

 <xsl:apply-templates
select="msxsl:node-set($multiSum)/summed" />

and the following template

<xsl:template match="summed">
  <xsl:for-each select="number">
    <xsl:sort data-type="number" order="ascending"/>
      <test><xsl:value-of select="."/></test>
	<xsl:if test="position()=last()">
	  <max><xsl:value-of select="."/></max>
	</xsl:if>
  </xsl:for-each>
</xsl:template> 




--- Josh Canfield <josh.canfield@xxxxxxxxxxxx> wrote:
> If you know that the node you want is the first one,
> just pass it to the apply-templates.
> Change:
>   <xsl:apply-templates
> select="msxsl:node-set($sortedNumbers)/inorder" />
> To:
>   <xsl:apply-templates
> select="msxsl:node-set($sortedNumbers)/inorder[1]"
> />
> 
> Josh
> 
> -----Original Message-----
> From: Donal Regan [mailto:donal_regan10@xxxxxxxxxxx]
> Sent: Thursday, January 15, 2004 10:47 PM
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] position()=last() always 1 problem
> 
> 
> Hello,
> 
> I want to add some values and then find the maximum
> result. The addition is fine but then I try to sort
> the results and look at the "last()" one, my output
> is
> just  all the sums, rather than the max value.
>  Any help would be greatly appreciated.
> 
> Donal.
> I have the following XML input
> <data var0='tpop' var1='bpop'>
> <ratios>
>  <teensRatio>0.2</teensRatio>
>  <babiesRatio>0.3</babiesRatio>
>  <infantsRatio>0.1</infantsRatio>
> </ratios>
> <ratios>
>  <teensRatio>0.1</teensRatio>
>  <babiesRatio>0.1</babiesRatio>
>  <infantsRatio>0.05</infantsRatio>
> </ratios>
> <ratios>
>  <teensRatio>0.2</teensRatio>
>  <babiesRatio>0.15</babiesRatio>
>  <infantsRatio>0.1</infantsRatio>
> </ratios>
> etc;
> </data>
> 
> my output is 
> <max>0.5</max>
> <max>0.2</max>
> <max>0.35</max>
> 
> I would like
> 
> <max>0.5</max>
> 
> This the stylesheet.
> 
> <xsl:template match="data">
> <xsl:variable name="multiSum">
>  <xsl:for-each select="ratios">
>    <xsl:variable name="r0">
>      <xsl:choose>
> 	<xsl:when test="$var0='tpop'">
> 	  <xsl:value-of select="teensRatio"/>
> 	</xsl:when>
> 	<xsl:when test="$var0='bpop'">
> 	  <xsl:value-of select="babiesRatio"/>
> 	</xsl:when>
> 	<xsl:when test="$var0='ipop'">
> 	  <xsl:value-of select="infantsRatio"/>
> 	</xsl:when>
>     </xsl:choose>
>   </xsl:variable>
>   <xsl:variable name="r1">
>      <xsl:choose>
> 	<xsl:when test="$var1='tpop'">
> 	  <xsl:value-of select="teensRatio"/>
> 	</xsl:when>
> 	<xsl:when test="$var1='bpop'">
> 	  <xsl:value-of select="babiesRatio"/>
> 	</xsl:when>
> 	<xsl:when test="$var1='ipop'">
> 	  <xsl:value-of select="infantsRatio"/>
> 	</xsl:when>
>     </xsl:choose>
>   </xsl:variable>
>   <number><xsl:value-of select="$r0 +
> $r1"/></number>
>  </xsl:for-each>
> </xsl:variable>
> <xsl:apply-templates
> select="msxsl:node-set($multiSum)/number" />
> </xsl:template>
> 	
> <xsl:template match="number">
>   <xsl:variable name="sortedNumbers">
>   <xsl:for-each select=".">
>     <xsl:sort data-type="number" order="ascending"/>
>       <inorder><xsl:copy-of select="."/></inorder>
>   </xsl:for-each>
>   </xsl:variable>
>   <xsl:apply-templates
> select="msxsl:node-set($sortedNumbers)/inorder" />
> </xsl:template>
> 		
> <xsl:template match="inorder">
>  <xsl:for-each select="number">
>    <xsl:if test="position()=last()">
>      <max><xsl:value-of select="."/></max>
>    </xsl:if>
>  </xsl:for-each>
> </xsl:template>
> 
>
________________________________________________________________________
> Yahoo! Messenger - Communicate instantly..."Ping" 
> your friends today! Download Messenger Now 
> http://uk.messenger.yahoo.com/download/index.html
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
>  

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" 
your friends today! Download Messenger Now 
http://uk.messenger.yahoo.com/download/index.html

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


Current Thread