P
Porthos
Hi All,
I'm trying to find the minimum value of a set of data (see below).
I want to compare the lengths of these attribute values and display
the lowest one.
This would be simple if I could re-assign values to a variable,
but from what I gather I can't do that. How do I keep track of the
lowest value as I loop through? My XSL document only finds the length
of each string and prints it out (for now). I can write a template
that calls itself for recursion, but I don't know how to keep the
minimum value readially available as I go through each loop.
Thanks,
James
XML Document
=============================
<calendar name="americana">
<month value="January"/>
<month value="February"/>
<month value="March"/>
<month value="April"/>
<month value="May"/>
<month value="June"/>
<month value="July"/>
<month value="August"/>
<month value="September"/>
<month value="October"/>
<month value="November"/>
<month value="December"/>
</calendar>
XSL Document (so far)
=============================
<xsl:template match="/">
<xsl:for-each select="calendar/month">
<xsl:call-template name="find_min_max">
<xsl:with-param name="min" select="string-length(@value)"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="find_min_max">
<xslaram name="min" select="0"/>
<xsl:value-of select="$min"/>
<br/>
</xsl:template>
I'm trying to find the minimum value of a set of data (see below).
I want to compare the lengths of these attribute values and display
the lowest one.
This would be simple if I could re-assign values to a variable,
but from what I gather I can't do that. How do I keep track of the
lowest value as I loop through? My XSL document only finds the length
of each string and prints it out (for now). I can write a template
that calls itself for recursion, but I don't know how to keep the
minimum value readially available as I go through each loop.
Thanks,
James
XML Document
=============================
<calendar name="americana">
<month value="January"/>
<month value="February"/>
<month value="March"/>
<month value="April"/>
<month value="May"/>
<month value="June"/>
<month value="July"/>
<month value="August"/>
<month value="September"/>
<month value="October"/>
<month value="November"/>
<month value="December"/>
</calendar>
XSL Document (so far)
=============================
<xsl:template match="/">
<xsl:for-each select="calendar/month">
<xsl:call-template name="find_min_max">
<xsl:with-param name="min" select="string-length(@value)"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="find_min_max">
<xslaram name="min" select="0"/>
<xsl:value-of select="$min"/>
<br/>
</xsl:template>