Author Topic: XSLT Template for Supergroup Transform (guildportal)  (Read 3821 times)

IceHeart

  • Boss
  • ****
  • Posts: 173
  • a.k.a 'Ice' - Shadow Souls' Top Cat
    • Shadow Souls
XSLT Template for Supergroup Transform (guildportal)
« on: December 22, 2008, 09:43:18 AM »
Hi guys.
Figured I'd post this one, some people may find it useful.

The XSLT below can be used at Guildportal with an XML/XSLT box (if you're a paying site).

It may be also  updated to have the transformation performed at the client browser if this is a non-paying guildportal site or at a different website.

This particular version  is kinda longish, but our SG family includes 4 different SGs, and I'll be using the extracts for both full rosters as well as 'who's online' shorter versions, so I wanted to set it up once and then be able to tweak it easily without having to mess too much with the internal XML elements for each file. But it can be much simplified by removing all the variables if you do not need that.

It includes a couple cool things, such as a generated DHTMLTooltip, if the site supports it, (but the script link can be easily added anyways) as well as Table sorting, by 'borrowing' CIT's tablesorter .js link.

There are undoubtedly easier/simpler ways to do this, but this one kinda worked for me, so hope somebody else may find it useful.
Cheers,
Ice

_____

To enable this in a Guildportal paying site :
1. Copy the code below to Notepad and save to a file, with extension".xsl".
2.Tweak the 'variables' to show the columns you want, filter online oly, etc..
3. Upload this file to your Guildportal's 'axiom files' host  - or anywhere else in the 'Net where you have file hosting. Note the URL for the file there.
4. Here in CIT, find your supergroup extract XML.. it will be in the form of :
Code: [Select]
http://cit/cohtitan.com/xml/sg/####    where ### is your CIT SG number . Note this URL.
5. In Guildportal, create an "XML/XSLT Box" and provide the XML source link to CIT, and the XSL to your hosted file.
6. Enjoy!

Code: [Select]

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" version="4.0" indent="yes"/>
  <!--
An XSLT Transform for the City Info tracker Supergroup XML export.
http://cit.cohtitan.com
This Transform is geared towards use in the Guildportal site, but can be easily adapted to other sites or webpages.
http://ww.guildportal.com
Created by 'IceHeart', Dec 2008
Find me at:
http://www.cohtitan.com/forum/index.php?action=profile;u=3588
or at:
http://shadowsouls.guildportal.com
-->

  <!--
The Transform assumes that the following objects are available for maximum functionality:
jQuery, http://jquery.com/
jQuery.tsort, http://tablesorter.com/docs/
jQuery.dhtmltooltip, http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm
If they are not, the basic table will still work, but will be less dynamic.
-->

  <!--Configuration variables: 1, enable, 0 or other disable-->
  <xsl:variable name="FilterOnlineOnly">0</xsl:variable>
  <xsl:variable name="ShowGameId">1</xsl:variable>
  <xsl:variable name="ShowOrigin">1</xsl:variable>
  <xsl:variable name="ShowArchetype">1</xsl:variable>
  <xsl:variable name="ShowStatus">1</xsl:variable>
  <xsl:variable name="ShowServer">0</xsl:variable>
  <xsl:variable name="ShowLevel">1</xsl:variable>
  <xsl:variable name="ShowPrimarySet">1</xsl:variable>
  <xsl:variable name="ShowSecondarySet">1</xsl:variable>
  <xsl:variable name="ShowVerifiedCount">1</xsl:variable>
  <xsl:variable name="ShowUnverifiedCount">0</xsl:variable>
  <xsl:variable name="ShowGlobalId">0</xsl:variable>
  <xsl:variable name="ShowCITFooter">1</xsl:variable>

  <!--Values for NameToolTip can be 'Basic' or 'DHTMLTooltip'; anything else is ignored and a tooltip will not be created-->
  <!--Basic will create a standard text-only tooltip with core character info, does not require anything else-->
  <!--DHTMLTooltip will create a dhtmltootlip-enabled tooltip html element with character info and avatar-->
  <xsl:variable name="NameToolTip">DHTMLTooltip</xsl:variable>

  <xsl:template match="/">
        <script type="text/javascript" src="http://cit.cohtitan.com/scripts/jquery.tsort.js"/>
   <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="character" name="character">
    <tr class="NormGridRow" style=" height: 1.7em; border: solid 1px #b00000;">
      <xsl:if test="$ShowGameId = '1'">
        <td>
          <xsl:choose>
            <xsl:when test="game_id='1'">
              <img src="http://www.cohtitan.com/img/icons_16/Hero.png" alt="Hero" title="Hero"/>
            </xsl:when>
            <xsl:when test="game_id='2'">
              <img src="http://www.cohtitan.com/img/icons_16/Villain.png" alt="Villain" title="Villain"/>
            </xsl:when>
          </xsl:choose>
        </td>
      </xsl:if>
      <xsl:if test="$ShowOrigin = '1'">
        <td>
          <xsl:element name="img">
            <xsl:attribute name="src">
              <xsl:value-of select="concat('http://www.cohtitan.com/img/icons_16/',origin_name,'.png')"/>
            </xsl:attribute>
            <xsl:attribute name="alt">
              <xsl:value-of select="origin_name"/>
            </xsl:attribute>
            <xsl:attribute name="title">
              <xsl:value-of select="origin_name"/>
            </xsl:attribute>

          </xsl:element>
        </td>
      </xsl:if>
      <xsl:if test="$ShowArchetype = '1'">
        <td>
          <xsl:element name="img">
            <xsl:attribute name="src">
              <xsl:value-of select="concat('http://www.cohtitan.com/img/icons_16/',archetype_name,'.png')"/>
            </xsl:attribute>
            <xsl:attribute name="alt">
              <xsl:value-of select="archetype_name"/>
            </xsl:attribute>
            <xsl:attribute name="title">
              <xsl:value-of select="archetype_name"/>
            </xsl:attribute>
          </xsl:element>
        </td>
      </xsl:if>
      <td>
        <xsl:element name="a">
          <xsl:attribute name="href">
            <xsl:value-of select="concat('http://cit.cohtitan.com/character/',char_id)"/>
          </xsl:attribute>
          <xsl:if test="$NameToolTip = 'Basic'">
            <xsl:attribute name="title">
              <xsl:value-of select="concat(name,': ',origin_name,' ',archetype_name,', Level ',security_level,', ',primary_name, ' / ',secondary_name )"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$NameToolTip = 'DHTMLTooltip'">
            <xsl:attribute name="onMouseover">
              <xsl:variable name="DDriveTipString">
                <xsl:text disable-output-escaping="yes">ddrivetip(&apos;</xsl:text>
                <xsl:if test="medium_avatar!=''">
                  <xsl:text disable-output-escaping="yes">&lt;img src=&quot;</xsl:text>
                  <xsl:value-of select="medium_avatar"/>
                  <xsl:text disable-output-escaping="yes">&quot;/&gt;</xsl:text>
                </xsl:if>
                <xsl:text disable-output-escaping="yes">&lt;br/&gt;&lt;strong&gt;</xsl:text>
                <xsl:value-of select="name"/>
                <xsl:text disable-output-escaping="yes">&lt;/strong&gt;&lt;br/&gt;</xsl:text>
                <xsl:value-of select="concat(origin_name,' - ',archetype_name)"/>
                <xsl:text disable-output-escaping="yes">&lt;br/&gt;Level: </xsl:text>
                <xsl:value-of select="security_level"/>
                <xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
                <xsl:value-of select="concat(primary_name,' / ',secondary_name)"/>
                <xsl:text disable-output-escaping="yes">&lt;br/&gt; Badges:</xsl:text>
                <xsl:value-of select="verified_count"/>
                <xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
                <xsl:text disable-output-escaping="yes">&apos;)</xsl:text>
              </xsl:variable>
              <xsl:value-of select="$DDriveTipString"/>
            </xsl:attribute>
            <xsl:attribute name="onMouseout">
              <xsl:value-of select="'hideddrivetip()'"/>
            </xsl:attribute>

          </xsl:if>
          <xsl:value-of select="name"/>
        </xsl:element>
      </td>
      <xsl:if test="$ShowStatus = '1'">
        <td>
          <xsl:value-of select="status"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowServer = '1'">
        <td>
          <xsl:value-of select="server_name"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowLevel = '1'">
        <td>
          <xsl:value-of select="security_level"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowPrimarySet = '1'">
        <td>
          <xsl:value-of select="primary_name"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowSecondarySet = '1'">
        <td>
          <xsl:value-of select="secondary_name"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowVerifiedCount = '1'">
        <td style="text-align:right">
          <xsl:value-of select="verified_count"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowUnverifiedCount = '1'">
        <td style="text-align:right">
          <xsl:value-of select="unverified_count"/>
        </td>
      </xsl:if>
      <xsl:if test="$ShowGlobalId = '1'">
        <td>
          <xsl:value-of select="concat('@',global_name)"/>
        </td>
      </xsl:if>
    </tr>
  </xsl:template>

  <xsl:template match="supergroup">
    <xsl:element name="table">
      <xsl:attribute name="class">tablesorter</xsl:attribute>
      <xsl:attribute name="style">
        border: solid 1px #b00000;
        border-collapse: collapse;
      </xsl:attribute>
      <thead>
        <xsl:attribute name="style">
          background-image: url(http://www.axiomfiles.com/Images/Dynamic/B00000_000000_v_hi25.jpg);
          background-repeat: repeat-x;
          background-color: #b00000;
          cursor:pointer;
        </xsl:attribute>
        <tr>
          <xsl:if test="$ShowGameId = '1'">
            <th></th>
          </xsl:if>
          <xsl:if test="$ShowOrigin = '1'">
            <th></th>
          </xsl:if>
          <xsl:if test="$ShowArchetype = '1'">
            <th></th>
          </xsl:if>
          <th>
            Name
          </th>
          <xsl:if test="$ShowStatus = '1'">
            <th>
              Status
            </th>
          </xsl:if>
          <xsl:if test="$ShowServer = '1'">
            <th>
              Server
            </th>
          </xsl:if>
          <xsl:if test="$ShowLevel = '1'">
            <th>
              Level
            </th>
          </xsl:if>
          <xsl:if test="$ShowPrimarySet = '1'">
            <th>
              Primary Set
            </th>
          </xsl:if>
          <xsl:if test="$ShowSecondarySet = '1'">
            <th>
              Secondary Set
            </th>
          </xsl:if>
          <xsl:if test="$ShowVerifiedCount = '1'">
            <th>Badges</th>
          </xsl:if>
          <xsl:if test="$ShowUnverifiedCount = '1'">
            <th>
              Unv. Badges
            </th>
          </xsl:if>
          <xsl:if test="$ShowGlobalId = '1'">
            <th>
              Global Name
            </th>
          </xsl:if>
        </tr>
      </thead>
      <tbody>
        <xsl:choose>
          <xsl:when test="$FilterOnlineOnly='1'">
            <xsl:for-each select="character[status='Online']">
              <xsl:call-template name="character" />
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates />
          </xsl:otherwise>
        </xsl:choose>
      </tbody>
      <xsl:if test="$ShowCITFooter='1'">
        <tfoot>
          <tr>
            <td colspan="15">
              <div style="height:0.5em"></div>
            </td>
          </tr>
          <tr>
            <td colspan="15">
              <a href="http://cit.cohtitan.com/">
                <img src="http://cit.cohtitan.com/img/logo_amalgam_sub.png" alt="City Info Tracker"></img>
              </a>
            </td>
          </tr>
        </tfoot>
      </xsl:if>
    </xsl:element>
    <script>
      $(document).ready(function() {
      $('.tablesorter')
      .tablesorter()
      });
    </script>
  </xsl:template>

</xsl:stylesheet>




Steiner

  • Elite Boss
  • *****
  • Posts: 1,602
    • Steinerd.com
Re: XSLT Template for Supergroup Transform (guildportal)
« Reply #1 on: December 22, 2008, 03:27:36 PM »
Sweet, This is going in the Tutorial page I'm creating.
~Steinerd