Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 27th, 2005, 09:23 AM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default MAX and MIN ON TD

Hi,

I am building a table with xslt 1.0 (msxml) and would like to find the max and min values on each row and highlight the <td>s with blue and red respectively. However, I can not figure out how to do that.

Here is what I have tried but to no avail. I would appreicate if someone could help me to that.

Cheers,

Cleyton

<xsl:template match="Groups">




        <xsl:for-each select="Group">
          <xsl:variable name="nGroups" select="../../@ngroups"/>



            <xsl:if test="Group[not(preceding-sibling::Group/@sample &lt; .)]/@sample">


            <td class="tdBorder">
                <div style="background-color:#FF9999"><xsl:value-of select="@sample"/></div>
            </td>
            </xsl:if>

            <xsl:if test="(position() = last()) and (position() &lt; $NumCol)">
                      <xsl:call-template name="FillerCells">
                         <xsl:with-param name="cellCount" select="$NumCol - position()"/>
                  </xsl:call-template>
           </xsl:if>
        </xsl:for-each>

    </xsl:template>


Reply With Quote
  #2 (permalink)  
Old July 27th, 2005, 09:32 AM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I forgot to send the xml. This is an extract since it is quite long

Cheers

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xsl" href="Statistic.xslt"?>
<Cluster>
        <Solutions variance="100520.0000">
        <Solution ngroups="2" variance="79966.4596" varexp="20.4472">
            <Groups>
                <Group id="1" sample="13098" variance="39988.7861">
                    <GroupVar varid="LMTAA" mean="3.3365" absdevmean="0.8517" stddevmean="0.7009" variance=""/>
                    <GroupVar varid="LMPWA" mean="3.2585" absdevmean="-0.0002" stddevmean="-0.0002" variance=""/>
                    <GroupVar varid="LMGCA" mean="3.0231" absdevmean="0.5150" stddevmean="0.4429" variance=""/>
                    <GroupVar varid="LMAEA" mean="3.6182" absdevmean="0.2483" stddevmean="0.2527" variance=""/>
                </Group>
                <Group id="2" sample="12033" variance="39977.6735">
                    <GroupVar varid="LMTAA" mean="1.5577" absdevmean="-0.9271" stddevmean="-0.7630" variance=""/>
                    <GroupVar varid="LMPWA" mean="3.2590" absdevmean="0.0002" stddevmean="0.0002" variance=""/>
                    <GroupVar varid="LMGCA" mean="1.9475" absdevmean="-0.5606" stddevmean="-0.4821" variance=""/>
                    <GroupVar varid="LMAEA" mean="3.0996" absdevmean="-0.2703" stddevmean="-0.2751" variance=""/>
                </Group>
            </Groups>
        </Solution>
    </Solutions>
    </Cluster>


Reply With Quote
  #3 (permalink)  
Old July 27th, 2005, 09:48 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

It's not enough to compare a value with its preceding siblings to determine if it's the max or min; you need to compare it with all its siblings.

if test="not(../*/@sample > ./@sample)"

should do the trick. (Read it as "if there is no element among the children of my parent whose value is greater than my own"). This is a very concise way of writing the code, but not efficient on large data sets - however it's probably OK for your use case.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old July 27th, 2005, 10:13 AM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Thanks for you reply.

I tried this now but am getting an error saying that the file is not well fomed & missing. I think the problem is when I use the "<" than sign.

What is wrong when I do this?

<xsl:when test="not(../*/@sample < ./@sample)">



<xsl:choose>
                <xsl:when test="not(../*/@sample > ./@sample)">
                    <td class="tdBorder">
                        <div style="background-color:#FF9999"><xsl:value-of select="@sample"/></div>
                    </td>
                </xsl:when>
                <xsl:when test="not(../*/@sample < ./@sample)">
                    <td class="tdBorder">
                        <div style="background-color:#CCECFF"><xsl:value-of select="@sample"/></div>
                    </td>
                </xsl:when>
                <xsl:otherwise>
                    <td class="tdBorder">
                        <div style="background-color:#FFFFFF"><xsl:value-of select="@sample"/></div>
                    </td>
                </xsl:otherwise>

            </xsl:choose>





Reply With Quote
  #5 (permalink)  
Old July 27th, 2005, 10:26 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

A less-than sign in an XML document must always be escaped as &lt;

I usually escape > as &gt; as well for symmetry, though that's not structly necessary unless it's part of a ]]> sequence.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #6 (permalink)  
Old July 27th, 2005, 10:27 AM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael,

I have figured out how to do that. I just changed the "<" with "&lt;" and ">" with "&gt;".

You mentioned that this is a very concise way of writing the code, but not efficient on large data sets. I am concerned about this since the xml is going to be big.

What is the other alterantive when you have a large xml file? I have checked page 184 of XSLT Prog Ref 2nd edition but am not sure if recursion is the answer here.

Cheers,

Claudio

Reply With Quote
  #7 (permalink)  
Old July 27th, 2005, 11:03 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

It's not teh size of the XML file that matters, its the number of nodes in the list whose max or min you are finding.

Other ways of finding min/max are

(a) sort and take the lowest/highest

(b) a recursive scan of the list, passing the highest-so-far or lowest-so-far as a parameter on the recursive call

(c) in XSLT 2.0, the min() or max() functions

(d) reuse the min() or max() functions/templates from the EXSLT or FXSL libraries

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #8 (permalink)  
Old July 27th, 2005, 12:39 PM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot Michael

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one get the Max or Min Filename? crabjoe ASP.NET 1.0 and 1.1 Basics 4 January 15th, 2008 03:48 PM
MAX/MIN Value Help slbibs SQL Server 2005 4 November 6th, 2007 03:00 AM
MIN( MAX( UPDATE Stuart Stalker SQL Language 3 February 21st, 2007 06:10 AM
Min / Max followup danbush XSLT 2 August 31st, 2005 12:02 PM
SQL Max() and Min() functions help shana Oracle ASP 1 April 25th, 2005 08:34 PM



All times are GMT -4. The time now is 03:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.