Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

math:max with an attribute

Status
Not open for further replies.

MikeAJ

Programmer
May 22, 2002
108
US
Hello, I'm trying to use a math:max template that I found online, but I need it to work with attributes that may contain a word instead of a number.

Here is the template:
Code:
<xsl:template name="math:max">
   <xsl:param name="nodes" select="/.." />
   <xsl:choose>
      <xsl:when test="not($nodes)">NaN</xsl:when>
      <xsl:otherwise>
         <xsl:for-each select="$nodes">
            <xsl:sort data-type="number" order="descending" />
            <xsl:if test="position() = 1">
               <xsl:value-of select="number(.)" />
            </xsl:if>
         </xsl:for-each>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Here is a snippet of my xml:
Code:
<CLASS>
   <PART part_number="332234"  price="7111"  esdMin="Call" esdMax="Call"/>
   <PART part_number="331643"  price="7411"  esdMin="5"    esdMax="70"/>
</CLASS>
<PART part_number="331177"  price="4415"  esdMin="Call" esdMax="Call"/>
<PART part_number="160513"  price="415"   esdMin="7"    esdMax="3"/>
<PART part_number="332636"  price="2715"  esdMin="72"   esdMax="20"/>
<PART part_number="332613"  price="1111"  esdMin="5"    esdMax="70"/>
<PART part_number="331753"  price="77411" esdMin="5"    esdMax="70"/>

So, I have a couple of different problems. The first is that I need to pull the highest esdMin and the highest esdMax, no matter where in the tree they live. Unless, I find the work "Call" in either spot. In that case, I need to disregard all of the numbers, and simply display "Call".

The problem I was running into is that the math:max function was returning NaN, due to the work "Call". Anyone see a way around this?

Thanks,
Mike
 
You may find an example here that uses recursion to determine a maximum value of a set of nodes.

This thread shows how to avoid the nonnumeric problem: thread426-1341056

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top