Sign Up! Login: Password: New User? Forgot? Support
Top Mods!
Wowhead Search
by sonofsamedi
Digital Clock
by Wolfar15
Admin Forums
Welcome to the GuildPortal Help Community! These forums are for admin-to-admin help.
Available Forums
Forums : Voodoo Tech and Scripter's Den of Scriptniquity > EQ2 Guild Roster XSL and Raid Count
SchandlichEQ2 (New Admin) 1/7/2010 4:20 PM EST : EQ2 Guild Roster XSL and Class Count
SchandlichEQ2
Posts: 158
Posts With Wolves

Hello. First time poster here. I hope this hasn't been done before, but I thought I would share a little code I wrote.

You can see a working example here:

I am using the XML roster feed found on the EQ2 players site. I am also using a custom XSLT file I built found here. I am sorting by level at the moment. Hopefully later today I will have one for sorting by rank and then by level.

Since the feed does not return the cool little totals that are on eq2players.com (and since I am too lazy to just buy a dang site and do the counting server-side), I made a little javascript to return count and display the number of each class.

Here is the code found in the Guild Summary Widget:
<table style="margin-top: 10px;">
    <tbody>
        <tr>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Berserker</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Guardian</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Paladin</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Shadow Knight</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Bruiser</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Monk</td>
        </tr>
        <tr>
            <td style="text-align: center;"><span id="spn_Berserker_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Guardian_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Paladin_count">0</span></td>
            <td style="text-align: center;"><span id="spn_SK_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Bruiser_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Monk_count">0</span></td>
        </tr>
    </tbody>
</table>
<table style="margin-top: 10px;">
    <tbody>
        <tr>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Templar</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Inquisitor</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Defiler</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Mystic</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Warden</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Fury</td>
        </tr>
        <tr>
            <td style="text-align: center;"><span id="spn_Templar_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Inquisitor_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Defiler_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Mystic_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Warden_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Fury_count">0</span></td>
        </tr>
    </tbody>
</table>
<table style="margin-top: 10px;">
    <tbody>
        <tr>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Assassin</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Ranger</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Brigand</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Swashbuckler</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Troubador</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Dirge</td>
        </tr>
        <tr>
            <td style="text-align: center;"><span id="spn_Assassin_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Ranger_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Brigand_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Swashbuckler_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Troubador_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Dirge_count">0</span></td>
        </tr>
    </tbody>
</table>
<table style="margin-top: 10px;">
    <tbody>
        <tr>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Wizard</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Warlock</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Conjuror</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Necromancer</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Coercer</td>
            <td style="text-align: center ! important; width: 120px;" class="ForumCategoryHeader">Illusionist</td>
        </tr>
        <tr>
            <td style="text-align: center;"><span id="spn_Wizard_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Warlock_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Conjuror_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Necromancer_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Coercer_count">0</span></td>
            <td style="text-align: center;"><span id="spn_Illusionist_count">0</span></td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">     
$(document).ready(function(){     
var classes = document.getElementById("tbl_roster").innerHTML; 
 
var berserker_matches = 0;
var guardian_matches = 0;
var paladin_matches = 0;
var sk_matches = 0;
var bruiser_matches = 0;
var monk_matches = 0;
var templar_matches = 0;
var inquisitor_matches = 0;
var defiler_matches = 0;
var mystic_matches = 0;
var warden_matches = 0;
var fury_matches = 0;
var assassin_matches = 0;
var ranger_matches = 0;
var brigand_matches = 0;
var swashbuckler_matches = 0;
var troubador_matches = 0;
var dirge_matches = 0;
var wizard_matches = 0;
var warlock_matches = 0;
var conjuror_matches = 0;
var necromancer_matches = 0;
var coercer_matches = 0;
var illusionist_matches = 0;
 
berserker_matches = classes.match(/Berserker/g);
guardian_matches = classes.match(/Guardian/g);
paladin_matches = classes.match(/Paladin/g);
sk_matches = classes.match(/Shadow Knight/g);
bruiser_matches = classes.match(/Bruiser/g);
monk_matches = classes.match(/Monk/g);
templar_matches = classes.match(/Templar/g);
inquisitor_matches = classes.match(/Inquisitor/g);
defiler_matches = classes.match(/Defiler/g);
mystic_matches = classes.match(/Mystic/g);
warden_matches = classes.match(/Warden/g);
fury_matches = classes.match(/Fury/g);
assassin_matches = classes.match(/Assassin/g);
ranger_matches = classes.match(/Ranger/g);
brigand_matches = classes.match(/Brigand/g);
swashbuckler_matches = classes.match(/Swashbuckler/g);
troubador_matches = classes.match(/Troubador/g);
dirge_matches = classes.match(/Dirge/g);
wizard_matches = classes.match(/Wizard/g);
warlock_matches = classes.match(/Warlock/g);
conjuror_matches = classes.match(/Conjuror/g);
necromancer_matches = classes.match(/Necromancer/g);
coercer_matches = classes.match(/Coercer/g);
illusionist_matches = classes.match(/Illusionist/g);
 
if (berserker_matches != null) {
document.getElementById("spn_Berserker_count").innerHTML = berserker_matches.length;
    }
if (guardian_matches != null) {
document.getElementById("spn_Guardian_count").innerHTML = guardian_matches.length;
    }
if (paladin_matches != null) {
document.getElementById("spn_Paladin_count").innerHTML = paladin_matches.length;
    }
if (sk_matches != null) {
document.getElementById("spn_SK_count").innerHTML = sk_matches.length;
    }
if (bruiser_matches != null) {
document.getElementById("spn_Bruiser_count").innerHTML = bruiser_matches.length;
    }
if (monk_matches != null) {
    document.getElementById("spn_Monk_count").innerHTML = monk_matches.length;
    }
if (templar_matches != null) {
document.getElementById("spn_Templar_count").innerHTML = templar_matches.length;
    }
if (inquisitor_matches != null) {
document.getElementById("spn_Inquisitor_count").innerHTML = inquisitor_matches.length;
    }
if (defiler_matches != null) {
document.getElementById("spn_Defiler_count").innerHTML = defiler_matches.length;
    }
if (mystic_matches != null) {
document.getElementById("spn_Mystic_count").innerHTML = mystic_matches.length;
    }
if (warden_matches != null) {
document.getElementById("spn_Warden_count").innerHTML = warden_matches.length;
    }
if (fury_matches != null) {
document.getElementById("spn_Fury_count").innerHTML = fury_matches.length;
    }
    if (assassin_matches != null) {
document.getElementById("spn_Assassin_count").innerHTML = assassin_matches.length;
    }
if (ranger_matches != null) {
document.getElementById("spn_Ranger_count").innerHTML = ranger_matches.length;
    }
if (brigand_matches != null) {
document.getElementById("spn_Brigand_count").innerHTML = brigand_matches.length;
    }
if (swashbuckler_matches != null) {
document.getElementById("spn_Swashbuckler_count").innerHTML = swashbuckler_matches.length;
    }
if (troubador_matches != null) {
document.getElementById("spn_Troubador_count").innerHTML = troubador_matches.length;
    }
if (dirge_matches != null) {
    document.getElementById("spn_Dirge_count").innerHTML = dirge_matches.length;
    }
if (wizard_matches != null) {
document.getElementById("spn_Wizard_count").innerHTML = wizard_matches.length;
    }
if (warlock_matches != null) {
document.getElementById("spn_Warlock_count").innerHTML = warlock_matches.length;
    }
if (conjuror_matches != null) {
document.getElementById("spn_Conjuror_count").innerHTML = conjuror_matches.length;
    }
if (necromancer_matches != null) {
document.getElementById("spn_Necromancer_count").innerHTML = necromancer_matches.length;
    }
if (coercer_matches != null) {
document.getElementById("spn_Coercer_count").innerHTML = coercer_matches.length;
    }
if (illusionist_matches != null) {
document.getElementById("spn_Illusionist_count").innerHTML = illusionist_matches.length;
    }
})     
</script>

If anyone knows a more efficient way to do this, please let me know!

TopBottom

Mottie (MVP) 1/8/2010 12:55 AM EST : RE: EQ2 Guild Roster XSL and Class Count
GuildPortal MVP
Mottie
Posts: 3883
Zomgawsh Poster

Hi SchandlichEQ2!

My OCD compelled me to make your code more efficient Here is the result of the Guild Summary Widget:
<style type="text/css">
 #classCount td { text-align: center; height: 50px; }
 #classCount .ForumCategoryHeader { width: 120px; }
</style>
<div id="classCount"></div>
<script type="text/javascript">
$(document).ready(function(){


 var classesPerRow = 6;
 var classes = (["Berserker", "Guardian", "Paladin", "Shadow Knight", "Bruiser", "Monk", "Templar", "Inquisitor", "Defiler", "Mystic", "Warden", "Fury", "Assassin", "Ranger", "Brigand", "Swashbuckler", "Troubador", "Dirge", "Wizard", "Warlock", "Conjuror", "Necromancer", "Coercer", "Illusionist"]);

 // Don't change anything below
 // ***********************

 var rosterTable = $('#tbl_roster').text();
 var tbl = '<table><tr>';
 $.each(classes, function(j){
  var matches = rosterTable.match(new RegExp ( this , "gi")) || 0;
  matches = (typeof(matches.length)=="undefined") ? 0 : matches.length;
  tbl += '<td><div class="ForumCategoryHeader">' + this + '</div>' + matches + '</td>';
  if ((j+1)%classesPerRow === 0) tbl += '</tr><tr>';
 })
 tbl += '</tr></table>';
 $('#classCount').html(tbl);
})
</script>

Also if you want to add a way to sort your roster, you'll have to make a couple of quick changes:

Add this in with your Guild Summary coding:
<style type="text/css">
th.ForumCategoryHeader {
 -moz-background-clip:border;
 -moz-background-inline-policy:continuous;
 -moz-background-origin:padding;
 background: transparent url(http://www.axiomfiles.com/images/ThemeGfx/RedSilver/redsilverfcatbackground.png) repeat scroll 0 0;
 border:0 none;
 color:#FFFFFF;
 font-weight:bold;
 margin:0;
 padding:2px;
 vertical-align:middle;
 height: 30px;
}
th.header span {
 background: url(http://i201.photobucket.com/albums/aa236/Mottie1/testsite/icons/sort-white.gif) left center no-repeat;
 cursor: pointer;
 font-weight: bold;
 text-align:center;
 padding-left: 20px;
 cursor: pointer;
}
th.headerSortUp span { background: url(http://i201.photobucket.com/albums/aa236/Mottie1/testsite/icons/asc-white.gif) left center no-repeat; }
th.headerSortDown span { background: url(http://i201.photobucket.com/albums/aa236/Mottie1/testsite/icons/desc-white.gif) left center no-repeat; }
</style>
<script type="text/javascript">
$(document).ready(function(){
 $('#tbl_roster').tablesorter();
})
</script>
and make these changes to your XSL (I added thead, tbody, switched header td to th and added a span to each header for the sort arrows; basically, the stuff in blue)
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <table border="0" style="width: 75%;margin-top: 10px" id="tbl_roster">
      <thead>
        <tr>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Character Name</th>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Class</th>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Level</th>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Tradeskill</th>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Tradeskill Level</th>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Secondary Tradeskill</th>
          <th class="ForumCategoryHeader" style="text-align:center !important"><span></span>Guild Rank</th>
        </tr>
      </thead>
      <tbody>

        <xsl:for-each select="guild/members/member">
          <xsl:sort select="level" order="descending"/>
          <tr>
            <td style="padding-left:8px;">
              <xsl:element name="a">
                <xsl:attribute name="href">
                  <xsl:text>http://eq2players.station.sony.com/Blackburrow/</xsl:text>
                  <xsl:value-of select="concat(normalize-space(name), '/')"/>
                </xsl:attribute>
                <xsl:attribute name="target">
                  <xsl:text>_blank</xsl:text>
                </xsl:attribute>
                <xsl:value-of select="normalize-space(name)"/>
              </xsl:element>
            </td>
            <td style="padding-left:8px;">
              <xsl:value-of select="class"/>
            </td>
            <td style="text-align:center">
              <xsl:value-of select="level"/>
            </td>
            <td style="padding-left:8px;">
              <xsl:value-of select="artisanClass" />
            </td>
            <td style="text-align:center">
              <xsl:value-of select="artisanLevel" />
            </td>
            <td style="padding-left:8px;text-transform: capitalize;">
              <xsl:value-of select="secondaryTradeskillClass"/>
            </td>
            <td style="padding-left:8px;">
              <xsl:value-of select="guildRank"/>
            </td>
          </tr>
        </xsl:for-each>
      </tbody>
    </table>
  </xsl:template>
</xsl:stylesheet>
TopBottom

SchandlichEQ2 (New Admin) 1/11/2010 2:02 PM EST : RE: EQ2 Guild Roster XSL and Class Count
SchandlichEQ2
Posts: 158
Posts With Wolves

Perfect! Thank you.

Working with Telerik too much lately and my good 'ol Javascript is a bit rusty. Thanks!
TopBottom

Admins Online
There are   members online.
So-and-so has logged on!
%title%
%message%