<!--
This XSL Transform is used to parse the Wowguru (WG) XML files and scrape fields for use
in the XSDKP web framework. All unrequired fields are automatically ignored and the fields
that are needed get scraped and renamed.
Copyright 2008 Crackin' Wise / ZSDKP (http://www.crackinwise.com)
Author: Nick Forysinski
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="IgnoreNodes">
id
bond
texture
quality
class
requiredSkill
requiredFaction
requiredRace
description
level
itemlevel
durability
set
container
tooltip
translations
link
dps
</xsl:variable>
<xsl:variable name="TextNodes">
name
slot
</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="item">
<item>
<xsl:apply-templates select="*" />
</item>
</xsl:template>
<!--
The following functions are used to rename specific nodes from WG
to align them with the ZSDKP database. These functions should not be
modified unless the WG XML structure changes.
-->
<xsl:template match="subclass">
<item_type>
<xsl:value-of select="." />
</item_type>
</xsl:template>
<xsl:template match="armor">
<armor_class>
<xsl:value-of select="." />
</armor_class>
</xsl:template>
<xsl:template match="fire">
<resist_fire>
<xsl:value-of select="." />
</resist_fire>
</xsl:template>
<xsl:template match="frost">
<resist_frost>
<xsl:value-of select="." />
</resist_frost>
</xsl:template>
<xsl:template match="shadow">
<resist_shadow>
<xsl:value-of select="." />
</resist_shadow>
</xsl:template>
<xsl:template match="nature">
<resist_nature>
<xsl:value-of select="." />
</resist_nature>
</xsl:template>
<xsl:template match="arcane">
<resist_arcane>
<xsl:value-of select="." />
</resist_arcane>
</xsl:template>
<xsl:template match="requiredClass">
<class_restrictions>
<xsl:value-of select="." />
</class_restrictions>
</xsl:template>
<xsl:template match="range">
<lowend>
<xsl:value-of select="substring-before(.,'-')" />
</lowend>
<topend>
<xsl:value-of select="substring-after(.,'-')" />
</topend>
</xsl:template>
<!-- bug fix for when wg has damage tags on items with no damage value -->
<xsl:template match="damage">
<xsl:choose>
<xsl:when test="*">
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- end bug fix -->
<xsl:template match="stat">
<xsl:param name="statValue">
<xsl:value-of select="." />
</xsl:param>
<xsl:choose>
<xsl:when test="contains($statValue, 'Stamina')">
<stamina>
<xsl:apply-templates select="." mode="text" />
</stamina>
</xsl:when>
<xsl:when test="contains($statValue, 'Agility')">
<agility>
<xsl:apply-templates select="." mode="text" />
</agility>
</xsl:when>
<xsl:when test="contains($statValue, 'Spirit')">
<spirit>
<xsl:apply-templates select="." mode="text" />
</spirit>
</xsl:when>
<xsl:when test="contains($statValue, 'Strength')">
<strength>
<xsl:apply-templates select="." mode="text" />
</strength>
</xsl:when>
<xsl:when test="contains($statValue, 'Intellect')">
<intellect>
<xsl:apply-templates select="." mode="text" />
</intellect>
</xsl:when>
<xsl:when test="contains($statValue, 'Spell Critical Strike Rating')">
<crit_spell>
<xsl:apply-templates select="." mode="text" />
</crit_spell>
</xsl:when>
<xsl:when test="contains($statValue, 'Spell Hit Rating')">
<hit_spell>
<xsl:apply-templates select="." mode="text" />
</hit_spell>
</xsl:when>
<xsl:when test="contains($statValue, 'Spell Haste Rating')">
<hit_spell>
<xsl:apply-templates select="." mode="text" />
</hit_spell>
</xsl:when>
<xsl:when test="contains($statValue, 'Critical Strike Rating')">
<crit_melee>
<xsl:apply-templates select="." mode="text" />
</crit_melee>
</xsl:when>
<xsl:when test="contains($statValue, 'Hit Rating')">
<hit_melee>
<xsl:apply-templates select="." mode="text" />
</hit_melee>
</xsl:when>
<xsl:when test="contains($statValue, 'Resilience Rating')">
<resilience>
<xsl:apply-templates select="." mode="text" />
</resilience>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="spell">
<xsl:param name="spellValue">
<xsl:value-of select="." />
</xsl:param>
<xsl:choose>
<xsl:when test="contains($spellValue, 'attack power')">
<attack_power>
<xsl:apply-templates select="." mode="text" />
</attack_power>
</xsl:when>
<xsl:when test="contains($spellValue, 'damage and healing done by magical spells and effects')">
<damage_all>
<xsl:apply-templates select="." mode="text" />
</damage_all>
</xsl:when>
<xsl:when test="contains($spellValue, 'Your attacks ignore')">
<armor_pen>
<xsl:value-of select="substring-before(substring-after($spellValue,'ignore '), 'of')" />
</armor_pen>
</xsl:when>
<xsl:when test="contains($spellValue, 'mana per 5 sec')">
<regen_mana>
<xsl:value-of select="substring-before(substring-after($spellValue,'Restores '), 'mana')" />
</regen_mana>
</xsl:when>
<xsl:when test="contains($spellValue, 'health per 5 sec')">
<regen_health>
<xsl:value-of select="substring-before(substring-after($spellValue,'Restores '), 'health')" />
</regen_health>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- END SPECIFIC NODE RENAMES -->
<xsl:template match="*">
<xsl:choose>
<xsl:when test="contains($IgnoreNodes, name())"></xsl:when>
<xsl:when test="./*">
<xsl:apply-templates />
</xsl:when>
<xsl:when test="contains($TextNodes, name())">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="." mode="text" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="text">
<xsl:value-of select="number(translate(text(),'1234567890.:_ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','1234567890.'))"/>
</xsl:template>
</xsl:stylesheet>