|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Need your help
Marco,
Given your XML: The following XSL demonstrates 3 ways of getting the max. <?xml version="1.0" encoding="iso8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/">
<xsl:for-each select="company/division">
<xsl:sort select="@DID"/>
<xsl:apply-templates select="."/>
<xsl:text>=============================
</xsl:text>
</xsl:for-each>
</xsl:template><xsl:template match="division"> <xsl:for-each select="projects/project"> <xsl:sort select="@PID"/> <xsl:value-of select="concat('PID=', @PID, ' Budget=', BUDGET, '
')"/> </xsl:for-each> <xsl:text>max-by-sort=</xsl:text>
<xsl:call-template name="max-by-sort">
<xsl:with-param name="nodes" select="projects/project"/>
</xsl:call-template>
<xsl:text>
</xsl:text> <xsl:text>max-by-tail-recursion=</xsl:text>
<xsl:call-template name="max-by-tail-recursion">
<xsl:with-param name="nodes" select="projects/project/BUDGET"/>
</xsl:call-template>
<xsl:text>
</xsl:text> <xsl:text>max-by-recursion=</xsl:text>
<xsl:call-template name="max-by-recursion">
<xsl:with-param name="nodes" select="projects/project/BUDGET"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:template> <xsl:template name="max-by-sort">
<xsl:param name="nodes" select="/.."/> <xsl:for-each select="$nodes">
<xsl:sort select="BUDGET"/>
<xsl:if test="position() = last()">
<xsl:value-of select="BUDGET"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:choose> <xsl:when test="$nodes"> <xsl:call-template name="max-by-tail-recursion"> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> <xsl:with-param name="max"> <xsl:choose> <xsl:when test="$max > $nodes[1]"> <xsl:value-of select="$max"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$nodes[1]"/> </xsl:otherwise> </xsl:choose> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$max"/> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:choose>
<xsl:when test="$nodes[1] > $max-of-rest">
<xsl:value-of select="$nodes[1]" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$max-of-rest" />
</xsl:otherwise>
</xsl:choose>
</xsl:when> <xsl:otherwise>
<xsl:value-of select="0" />
</xsl:otherwise>
</xsl:choose>
</xsl:template></xsl:stylesheet> When applied it yields this: PID=ENG1 Budget=1985555 PID=ENG2 Budget=3000000 PID=ENG3 Budget=4000000 max-by-sort=4000000 max-by-tail-recursion=4000000 max-by-recursion=4000000 ============================= PID=SAL1 Budget=100000 PID=SAL2 Budget=2000000 PID=SAL2 Budget=2000000 max-by-sort=2000000 max-by-tail-recursion=2000000 max-by-recursion=2000000 ============================= max-by-recursion is the approach you were trying for, it seems. Please note that htere are freely useable libraries that do this sort of thing--sorting, grouping, etc. The exsl project has implementations, for example. Regards, --A Here is my xlst code so far: _________________________________________________________________ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
|
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
|

Cart








