Share Pastebin
Guest
Public paste!

fourth

By: a guest | Sep 5th, 2008 | Syntax: XML | Size: 6.31 KB | Hits: 60 | Expires: Never
Copy text to clipboard
  1. <!--
  2.  This XSL Transform is used to parse the Wowguru (WG) XML files and scrape fields for use
  3.  in the XSDKP web framework. All unrequired fields are automatically ignored and the fields
  4.  that are needed get scraped and renamed.
  5.  
  6.  Copyright 2008 Crackin' Wise / ZSDKP (http://www.crackinwise.com)
  7.  Author: Nick Forysinski
  8. -->
  9. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  10.   <xsl:output  method="xml" indent="yes"/>
  11.  
  12.   <xsl:variable name="IgnoreNodes">
  13.         id
  14.         bond
  15.         texture
  16.         quality
  17.         class
  18.         requiredSkill
  19.         requiredFaction
  20.         requiredRace
  21.         description
  22.         level
  23.         itemlevel
  24.         durability
  25.         set
  26.         container
  27.         tooltip
  28.         translations
  29.         link
  30.         dps
  31.   </xsl:variable>
  32.   <xsl:variable name="TextNodes">
  33.         name  
  34.         slot
  35.   </xsl:variable>
  36.  
  37.   <xsl:template match="/">
  38.     <xsl:apply-templates />
  39.   </xsl:template>
  40.  
  41.   <xsl:template match="item">
  42.     <item>
  43.       <xsl:apply-templates select="*" />
  44.     </item>
  45.   </xsl:template>
  46.  
  47.   <!--
  48.    The following functions are used to rename specific nodes from WG
  49.    to align them with the ZSDKP database. These functions should not be
  50.    modified unless the WG XML structure changes.
  51.   -->
  52.   <xsl:template match="subclass">
  53.         <item_type>
  54.                 <xsl:value-of select="." />
  55.         </item_type>
  56.   </xsl:template>
  57.   <xsl:template match="armor">
  58.         <armor_class>
  59.                 <xsl:value-of select="." />
  60.         </armor_class>
  61.   </xsl:template>
  62.   <xsl:template match="fire">
  63.         <resist_fire>
  64.                 <xsl:value-of select="." />
  65.         </resist_fire>
  66.   </xsl:template>
  67.   <xsl:template match="frost">
  68.         <resist_frost>
  69.                 <xsl:value-of select="." />
  70.         </resist_frost>
  71.   </xsl:template>
  72.   <xsl:template match="shadow">
  73.         <resist_shadow>
  74.                 <xsl:value-of select="." />
  75.         </resist_shadow>
  76.   </xsl:template>
  77.   <xsl:template match="nature">
  78.         <resist_nature>
  79.                 <xsl:value-of select="." />
  80.         </resist_nature>
  81.   </xsl:template>
  82.   <xsl:template match="arcane">
  83.         <resist_arcane>
  84.                 <xsl:value-of select="." />
  85.         </resist_arcane>
  86.   </xsl:template>
  87.   <xsl:template match="requiredClass">
  88.         <class_restrictions>
  89.                 <xsl:value-of select="." />
  90.         </class_restrictions>
  91.   </xsl:template>
  92.   <xsl:template match="range">
  93.         <lowend>
  94.                 <xsl:value-of select="substring-before(.,'-')" />
  95.         </lowend>
  96.         <topend>
  97.                 <xsl:value-of select="substring-after(.,'-')" />
  98.         </topend>
  99.   </xsl:template>
  100.   <!-- bug fix for when wg has damage tags on items with no damage value -->
  101.   <xsl:template match="damage">
  102.         <xsl:choose>
  103.                 <xsl:when test="*">
  104.                         <xsl:apply-templates />
  105.                 </xsl:when>
  106.                 <xsl:otherwise></xsl:otherwise>
  107.         </xsl:choose>
  108.   </xsl:template>
  109.   <!-- end bug fix -->
  110.   <xsl:template match="stat">
  111.         <xsl:param name="statValue">
  112.                 <xsl:value-of select="." />
  113.         </xsl:param>
  114.         <xsl:choose>
  115.                 <xsl:when test="contains($statValue, 'Stamina')">
  116.                         <stamina>
  117.                                 <xsl:apply-templates select="." mode="text" />
  118.                         </stamina>
  119.                 </xsl:when>
  120.                 <xsl:when test="contains($statValue, 'Agility')">
  121.                         <agility>
  122.                                 <xsl:apply-templates select="." mode="text" />
  123.                         </agility>
  124.                 </xsl:when>
  125.                 <xsl:when test="contains($statValue, 'Spirit')">
  126.                         <spirit>
  127.                                 <xsl:apply-templates select="." mode="text" />
  128.                         </spirit>
  129.                 </xsl:when>
  130.                 <xsl:when test="contains($statValue, 'Strength')">
  131.                         <strength>
  132.                                 <xsl:apply-templates select="." mode="text" />
  133.                         </strength>
  134.                 </xsl:when>
  135.                 <xsl:when test="contains($statValue, 'Intellect')">
  136.                         <intellect>
  137.                                 <xsl:apply-templates select="." mode="text" />
  138.                         </intellect>
  139.                 </xsl:when>
  140.                 <xsl:when test="contains($statValue, 'Spell Critical Strike Rating')">
  141.                         <crit_spell>
  142.                                 <xsl:apply-templates select="." mode="text" />
  143.                         </crit_spell>
  144.                 </xsl:when>
  145.                 <xsl:when test="contains($statValue, 'Spell Hit Rating')">
  146.                         <hit_spell>
  147.                                 <xsl:apply-templates select="." mode="text" />
  148.                         </hit_spell>
  149.                 </xsl:when>
  150.                 <xsl:when test="contains($statValue, 'Spell Haste Rating')">
  151.                         <hit_spell>
  152.                                 <xsl:apply-templates select="." mode="text" />
  153.                         </hit_spell>
  154.                 </xsl:when>
  155.                 <xsl:when test="contains($statValue, 'Critical Strike Rating')">
  156.                         <crit_melee>
  157.                                 <xsl:apply-templates select="." mode="text" />
  158.                         </crit_melee>
  159.                 </xsl:when>
  160.                 <xsl:when test="contains($statValue, 'Hit Rating')">
  161.                         <hit_melee>
  162.                                 <xsl:apply-templates select="." mode="text" />
  163.                         </hit_melee>
  164.                 </xsl:when>
  165.                 <xsl:when test="contains($statValue, 'Resilience Rating')">
  166.                         <resilience>
  167.                                 <xsl:apply-templates select="." mode="text" />
  168.                         </resilience>
  169.                 </xsl:when>
  170.         </xsl:choose>
  171.   </xsl:template>
  172.   <xsl:template match="spell">
  173.         <xsl:param name="spellValue">
  174.                 <xsl:value-of select="." />
  175.         </xsl:param>
  176.         <xsl:choose>
  177.                 <xsl:when test="contains($spellValue, 'attack power')">
  178.                         <attack_power>
  179.                                 <xsl:apply-templates select="." mode="text" />
  180.                         </attack_power>
  181.                 </xsl:when>
  182.                 <xsl:when test="contains($spellValue, 'damage and healing done by magical spells and effects')">
  183.                         <damage_all>
  184.                                 <xsl:apply-templates select="." mode="text" />
  185.                         </damage_all>
  186.                 </xsl:when>
  187.                 <xsl:when test="contains($spellValue, 'Your attacks ignore')">
  188.                         <armor_pen>
  189.                                 <xsl:value-of select="substring-before(substring-after($spellValue,'ignore '), 'of')" />
  190.                         </armor_pen>
  191.                 </xsl:when>
  192.                 <xsl:when test="contains($spellValue, 'mana per 5 sec')">
  193.                         <regen_mana>
  194.                                 <xsl:value-of select="substring-before(substring-after($spellValue,'Restores '), 'mana')" />
  195.                         </regen_mana>
  196.                 </xsl:when>
  197.                 <xsl:when test="contains($spellValue, 'health per 5 sec')">
  198.                         <regen_health>
  199.                                 <xsl:value-of select="substring-before(substring-after($spellValue,'Restores '), 'health')" />
  200.                         </regen_health>
  201.                 </xsl:when>
  202.         </xsl:choose>
  203.   </xsl:template>
  204.   <!-- END SPECIFIC NODE RENAMES -->
  205.  
  206.   <xsl:template match="*">
  207.     <xsl:choose>
  208.       <xsl:when test="contains($IgnoreNodes, name())"></xsl:when>
  209.       <xsl:when test="./*">
  210.         <xsl:apply-templates />
  211.       </xsl:when>
  212.       <xsl:when test="contains($TextNodes, name())">
  213.                 <xsl:copy-of select="."/>
  214.       </xsl:when>
  215.       <xsl:otherwise>
  216.         <xsl:copy>
  217.           <xsl:apply-templates select="." mode="text" />
  218.         </xsl:copy>
  219.       </xsl:otherwise>
  220.     </xsl:choose>
  221.   </xsl:template>
  222.  
  223.   <xsl:template match="*" mode="text">
  224.     <xsl:value-of select="number(translate(text(),'1234567890.:_ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','1234567890.'))"/>
  225.   </xsl:template>
  226.  
  227. </xsl:stylesheet>