[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: position()=last() always 1 problem
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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|