Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dalton 14 posts 34 karma points
    Jun 08, 2011 @ 14:57
    dalton
    0

    Is there a way to select the top two and also anything that ties?

    For example if you were looking through stats and you had games that had a scores of 8,6,6,4,3 but i only wanna use the value of the top 2 unless there is a tie so in this case i want to display 8,6,6 but if the scores were 8,6,5,4,3 i would only want to display 8,6.

       <xsl:for-each select="schedule/game">
        <xsl:sort select="pts" data-type="number" order="descending"/>
        <xsl:choose>
        <xsl:when test="position()=1">
            <tr>
                <td>Points</td>
                <td><xsl:value-of select="pts"/></td>
                <td>&#160;&#160;&#160;</td>
                <td><xsl:value-of select="opponent"/></td>
            </tr>
        </xsl:when>
        <xsl:when test="not(position()>2) and pts>0 and position()!=1">
            <tr>
                <td>&#160;&#160;&#160;</td>
                <td><xsl:value-of select="pts"/></td>
                <td>&#160;&#160;&#160;</td>
                <td><xsl:value-of select="opponent"/></td>
            </tr>
        </xsl:when>
        <xsl:otherwise></xsl:otherwise>
        </xsl:choose></xsl:for-each>

    This is what i already have I only need help with figuring out the tie part please and thankyou.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 08, 2011 @ 15:11
    Tom Fulton
    0

    For the tie part, you could try using XSLT keys to only select unique stats values.

    Above your <xsl:template>

    <xsl:key name="uniquePts" match="game" use="pts"/> 

    Then adjust your for-each loop

    <xsl:for-each select="schedule/game [generate-id() = generate-id(key('uniquePts', pts)[1])]">

    That way in your example, you would only get 8,6 instead of 8,6,6.

    Would that work?

    -Tom

     

  • dalton 14 posts 34 karma points
    Jun 08, 2011 @ 15:40
    dalton
    0

    Oh sorry my question was a little confusing but in my case i want to show 8,6,6 if there is two 6's 

    <report><game>
            <score>8</score><team>red</team>
        </game>
        <game>
            <score>6</score><team>blue</team>
    </game> <game> <score>6</score><team>green</team>
    </game> <game> <score>5</score><team>yellow</team>
    </game> <game> <score>3</score><team>orange</team>
    </game> </report>

    Here are two examples of the xml for a season of games in any sport for two different teams

    <report>
        <game>
            <score>8</score>
        </game>
        <game>
            <score>6</score>
        </game>
        <game>
            <score>5</score>
        </game>
        <game>
            <score>4</score>
        </game>
        <game>
            <score>3</score>
        </game>
    </report>

    So now for the first team i wanna show theree highest two scores but there happens to be a tie betweens the two games where they scored 6 . So in this case i need to show them both in my list. In the other game i would just show 8 and 6 because there the top two.

    The html would then look like this

    top 2 scores    8 vs teamblue   6 vs team red  6 vs team green
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 10, 2011 @ 20:34
    Tom Fulton
    0

    I think you could still use the key part I posted above to select unique scores, then as you are writing out each score check for any duplicates

    <xsl:if test="count(schedule/game [score = current()/score]) &gt; 0">
    <!-- there is a tie, select all with the same score, except the current -->
    <xsl:for-each select="schedule/game [score = current()/score][position() &gt; 1">
    ...info about the tied game...
    </xsl:for-each>
    </xsl:if>
  • dalton 14 posts 34 karma points
    Jun 10, 2011 @ 21:49
    dalton
    0

    yea that works Thanks  a lot I appreciate it

Please Sign in or register to post replies

Write your reply to:

Draft