<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xalan="http://xml.apache.org/xalan"
 		xmlns:set="http://exslt.org/sets"
 		xmlns:exslt="http://exslt.org/common"
                exclude-result-prefixes="xalan xs set">

<xsl:output method="html" indent="yes" encoding="UTF-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD Xhtml 1.0 Strict//EN" />

<xsl:variable name="items" select="document('Items.xml')/ITEMLIST"/>
<xsl:variable name="weapons" select="document('Weapons.xml')/WEAPONLIST"/>
<xsl:variable name="armor" select="document('Armours.xml')/ARMOURLIST"/>
<xsl:variable name="attachments" select="document('Attachments.xml')/ATTACHMENTLIST"/>
<xsl:variable name="itemclass" select="document('LookUp/ItemClass.xml')/JA2Data"/>
<xsl:variable name="mag" select="document('Magazines.xml')/MAGAZINELIST"/>
<xsl:variable name="ammo" select="document('AmmoTypes.xml')/AMMOTYPELIST"/>
<xsl:variable name="ammoStrings" select="document('AmmoStrings.xml')/AMMOLIST"/>


<!--
<xsl:template name="ja2:ShowStringIfNotEmpty">
  <xsl:param name="value" required="yes"/>
  <xsl:param name="str" required="yes"/>
  <xsl:if test="length($value) > 0">
    <xsl:value-of select="$value"/> <xsl:value-of select="$str"/>
  </xsl:if>
</xsl:template>
-->


<xsl:template match="/">

<html lang="en-us">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>Jagged Alliance 2 Weapon List</title>
</head>

<body>
<h1>Jagged Alliance 2 Item List</h1>

<!-- <xsl:for-each select="set:distinct(exslt:node-set($items/ITEM/usItemClass))"> -->
<xsl:for-each select="$itemclass/ItemClass">
  <xsl:variable name="itemClassId" select="id"/>
  
<xsl:if test="$itemClassId != 1">

<h2>Item group: <xsl:value-of select="$itemclass/ItemClass/name[../id=$itemClassId]"/></h2>

<table border="1">
 <thead>
   <tr>
     <th>Item</th> 
     <th>Weight</th> 
     <th>Price</th>
     <th>SF</th>
     <th>Cool-<br/>ness</th> 
     <th>Relia-<br/>bility</th> 
     <xsl:choose>
      <xsl:when test="($itemClassId >= 2) and ($itemClassId &lt;= 128)"> <!-- weapons --> 
       <th>Tons<br/>Of<br/>Guns</th>
       <th>Ammo</th>
       <th>Type</th>
       <th>Hands</th>
       <th>Acc</th>
       <th>Rng</th>
       <th>Dmg</th>
       <th>APs</th>
       <th>Shot<br/>Noise</th>
       <th>Hit<br/>Noise</th>
     </xsl:when>

      <xsl:when test="$itemClassId = 2048"> <!-- armor --> 
       <th>Class</th>
       <th>Protection</th>
       <th>Coverage</th>
       <th>Durability</th>
       <th>Aim penalty</th>
       <th>AP penalty</th>
       <th>Camo effect</th>
      </xsl:when>

      <xsl:when test="$itemClassId = 1024"> <!-- ammo --> 
       <th>Calibre</th>
       <th>Rounds</th>
       <th>Range<br/>bonus</th>
       <th>Before armor<br/>damage</th>
       <th>After armor<br/>damage</th>
       <th>Structure<br/>impact</th>
       <th>Armor<br/>impact</th>
      </xsl:when>

      <xsl:when test="$itemClassId = 32768"> <!-- face items --> 
       <th>Vision range<br/>bonus</th>
       <th>...at night</th>
       <th>...in cave</th>
       <th>...in<br/>daylight</th>
       <th>...in bright<br/>daylight</th>
       <th>Hearing range<br/>bonus</th>
      </xsl:when>

     </xsl:choose>
     <th>Attachments</th> 
   </tr>
 </thead>
 
 
 <tbody>
   <xsl:for-each select="$items/ITEM[usItemClass=$itemClassId]">
   <xsl:sort select="szItemName"/>

    <tr>
     <xsl:variable name="uiIdx" select="uiIndex"/>
     <xsl:variable name="ubIdx" select="ubClassIndex"/>
     <td><xsl:value-of select="szItemName"/></td>
     <xsl:variable name="wgt" select="ubWeight"/>
     <td align="center">
       <xsl:choose>
         <xsl:when test="$wgt > 0"><xsl:value-of select="$wgt div 10.0"/>kg</xsl:when>
         <xsl:otherwise></xsl:otherwise>
       </xsl:choose>
     </td>
     <xsl:variable name="price" select="usPrice"/>
     <td align="center">
       <xsl:choose>
         <xsl:when test="$price > 0">$<xsl:value-of select="$price"/></xsl:when>
         <xsl:otherwise></xsl:otherwise>
       </xsl:choose>
     </td>
     <xsl:variable name="sf" select="SciFi"/>
     <td align="center">
       <xsl:choose>
         <xsl:when test="$sf > 0">SF</xsl:when>
         <xsl:otherwise></xsl:otherwise>
       </xsl:choose>
     </td>
     <td align="center"><xsl:value-of select="ubCoolness"/></td>
     <td align="center"><xsl:value-of select="bReliability"/></td>
     
     <xsl:choose>
      <!-- WEAPONS -->
      <xsl:when test="($itemClassId >= 2) and ($itemClassId &lt;= 128)"> <!-- weapons --> 
       <xsl:variable name="TonOfGuns" select="BigGunList"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$TonOfGuns > 0">ToG</xsl:when>
           <xsl:otherwise></xsl:otherwise>
         </xsl:choose>
       </td>
       <xsl:variable name="aType" select="$weapons/WEAPON[uiIndex=$ubIdx]/ubCalibre"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$aType = '0'"></xsl:when>
           <xsl:when test="$aType > '0'">
             <xsl:value-of select="$ammoStrings/AMMO[uiIndex=$aType]/AmmoCaliber"/>
           </xsl:when>
           <xsl:otherwise></xsl:otherwise>
         </xsl:choose>
       </td>
       <xsl:variable name="wType" select="$weapons/WEAPON[uiIndex=$ubIdx]/ubWeaponType"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$wType = '0'">Other</xsl:when>
           <xsl:when test="$wType = '1'">Pistol</xsl:when>
           <xsl:when test="$wType = '2'">Mch.Pistol</xsl:when>
           <xsl:when test="$wType = '3'">SMG</xsl:when>
           <xsl:when test="$wType = '4'">Rifle</xsl:when>
           <xsl:when test="$wType = '5'">Sn.Rifle</xsl:when>
           <xsl:when test="$wType = '6'">As.Rifle</xsl:when>
           <xsl:when test="$wType = '7'">LMG</xsl:when>
           <xsl:when test="$wType = '8'">Shotgun</xsl:when>
           <xsl:otherwise>Other</xsl:otherwise>
         </xsl:choose>
       </td>
       <xsl:variable name="hands" select="TwoHanded"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$hands = '0'">n/a</xsl:when>
           <xsl:when test="$hands = '1'">two</xsl:when>
           <xsl:otherwise>one</xsl:otherwise>
         </xsl:choose>
       </td>
       <xsl:variable name="acc" select="$weapons/WEAPON[uiIndex=$ubIdx]/bAccuracy"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$acc > 0">+<xsl:value-of select="$acc"/>%</xsl:when>
           <xsl:when test="0 > $acc"><xsl:value-of select="$acc"/>%</xsl:when>
           <xsl:otherwise><xsl:value-of select="$acc"/></xsl:otherwise>
         </xsl:choose>
       </td>
       <xsl:variable name="rng" select="$weapons/WEAPON[uiIndex=$ubIdx]/usRange"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$rng > 0"><xsl:value-of select="$rng"/>m</xsl:when>
           <xsl:otherwise><xsl:value-of select="$rng"/></xsl:otherwise>
         </xsl:choose>
       </td>
       <td align="center"><xsl:value-of select="$weapons/WEAPON[uiIndex=$ubIdx]/ubImpact"/></td>
       <td align="center">
         <!-- <xsl:value-of select="(89 - (89 mod $weapons/WEAPON[uiIndex=$ubIdx]/ubShotsPer4Turns)) div $weapons/WEAPON[uiIndex=$ubIdx]/ubShotsPer4Turns"/> -->
         <xsl:value-of select="floor((16000 + $weapons/WEAPON[uiIndex=$ubIdx]/ubShotsPer4Turns * 90) div ($weapons/WEAPON[uiIndex=$ubIdx]/ubShotsPer4Turns * 180))"/>
       </td>
        <xsl:variable name="noise" select="$weapons/WEAPON[uiIndex=$ubIdx]/ubAttackVolume"/>
        <xsl:variable name="noiseReduction" select="PercentNoiseReduction"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$noise > 0">
             <xsl:value-of select="$noise"/>
             <xsl:choose>
              <xsl:when test="$noiseReduction > 0"><br/>(<xsl:value-of select="$noise * (100 - $noiseReduction) div 100"/>)</xsl:when>
              <xsl:otherwise></xsl:otherwise>
             </xsl:choose>
            </xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
          </xsl:choose>
        </td>
        <xsl:variable name="hitNoise" select="$weapons/WEAPON[uiIndex=$ubIdx]/ubHitVolume"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$hitNoise > 0"><xsl:value-of select="$hitNoise"/></xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
          </xsl:choose>
        </td>
      </xsl:when>
      
      <!-- ARMOR -->
      <xsl:when test="$itemClassId = 2048"> <!-- armor --> 
       <xsl:variable name="aClass" select="$armor/ARMOUR[uiIndex=$ubIdx]/ubArmourClass"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$aClass = '0'">Helmet</xsl:when>
           <xsl:when test="$aClass = '1'">Vest</xsl:when>
           <xsl:when test="$aClass = '2'">Legging</xsl:when>
           <xsl:when test="$aClass = '3'">Plate</xsl:when>
           <xsl:when test="$aClass = '4'">Monster</xsl:when>
           <xsl:when test="$aClass = '5'">Vehicle</xsl:when>
           <xsl:otherwise>Other</xsl:otherwise>
         </xsl:choose>
       </td>
       <td align="center"><xsl:value-of select="$armor/ARMOUR[uiIndex=$ubIdx]/ubProtection"/></td>
       <td align="center"><xsl:value-of select="$armor/ARMOUR[uiIndex=$ubIdx]/ubCoverage"/></td>
       <td align="center"><xsl:value-of select="$armor/ARMOUR[uiIndex=$ubIdx]/ubDegradePercent"/></td>
       <td align="center"><xsl:value-of select="AimBonus"/></td>
       <td align="center"><xsl:value-of select="APBonus"/></td>
       <td align="center"><xsl:value-of select="CamoBonus"/></td>
      </xsl:when>

      <!-- AMMO -->
      <xsl:when test="$itemClassId = 1024"> <!-- ammo -->
       <xsl:variable name="aType" select="$mag/MAGAZINE[uiIndex=$ubIdx]/ubCalibre"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="$aType = '0'"></xsl:when>
           <xsl:when test="$aType > '0'">
             <xsl:value-of select="$ammoStrings/AMMO[uiIndex=$aType]/AmmoCaliber"/>
           </xsl:when>
           <xsl:otherwise></xsl:otherwise>
         </xsl:choose>
       </td>

       <td align="center"><xsl:value-of select="$mag/MAGAZINE[uiIndex=$ubIdx]/ubMagSize"/></td>
       <xsl:variable name="range" select="RangeBonus"/>
       <td align="center">
         <xsl:choose>
           <xsl:when test="string-length($range)=0"></xsl:when>
           <xsl:when test="$range > 0">+<xsl:value-of select="$range"/>m</xsl:when>
           <xsl:when test="0 > $range"><xsl:value-of select="$range"/>m</xsl:when>
           <xsl:otherwise></xsl:otherwise>
         </xsl:choose>
       </td>
       <xsl:variable name="ammoClass" select="$mag/MAGAZINE[uiIndex=$ubIdx]/ubAmmoType"/>
       <td align="center">x <xsl:value-of select="floor(100*$ammo/AMMOTYPE[uiIndex=$ammoClass]/beforeArmourDamageMultiplier div $ammo/AMMOTYPE[uiIndex=$ammoClass]/beforeArmourDamageDivisor) div 100"/></td>
       <td align="center">x <xsl:value-of select="floor(100*$ammo/AMMOTYPE[uiIndex=$ammoClass]/afterArmourDamageMultiplier div $ammo/AMMOTYPE[uiIndex=$ammoClass]/afterArmourDamageDivisor) div 100"/></td>
       <td align="center">x <xsl:value-of select="floor(100*$ammo/AMMOTYPE[uiIndex=$ammoClass]/structureImpactReductionMultiplier div $ammo/AMMOTYPE[uiIndex=$ammoClass]/structureImpactReductionDivisor) div 100"/></td>
       <td align="center">x <xsl:value-of select="floor(100*$ammo/AMMOTYPE[uiIndex=$ammoClass]/armourImpactReductionMultiplier div $ammo/AMMOTYPE[uiIndex=$ammoClass]/armourImpactReductionDivisor) div 100"/></td>
      </xsl:when>

      <!-- FACE ITEMS -->
      <xsl:when test="$itemClassId = 32768"> <!-- face items --> 
       <td align="center"><xsl:value-of select="VisionRangeBonus"/></td>
       <td align="center"><xsl:value-of select="NightVisionRangeBonus"/></td>
       <td align="center"><xsl:value-of select="CaveVisionRangeBonus"/></td>
       <td align="center"><xsl:value-of select="DayVisionRangeBonus"/></td>
       <td align="center"><xsl:value-of select="BrightLightVisionRangeBonus"/></td>
       <td align="center"><xsl:value-of select="HearingRangeBonus"/></td>
      </xsl:when>

     </xsl:choose>

     <td>
      <xsl:for-each select="$attachments/ATTACHMENT[itemIndex=$uiIdx]">
	<xsl:variable name="aidx" select="attachmentIndex"/>      
	<xsl:value-of select="$items/ITEM[uiIndex=$aidx]/szItemName"/>
	<xsl:if test="position()!=last()">, </xsl:if>
      </xsl:for-each>
     </td>

    </tr>
    
   </xsl:for-each>
 </tbody> 
</table>

</xsl:if>

</xsl:for-each>


<!-- -->
<!-- Special area for attachments, otherwise they get lost in the misc. gear -->
<!-- -->
<hr />
<h2>Attachments, extra information</h2>

<table border="1">
 <thead>
   <tr>
     <th>Attachment</th> 
     <th>bonus<br/>to hit</th>
     <th>...burst</th>
     <th>...autofire</th>
     <th>AP reduction</th>
     <th>...for ready</th>
     <th>Aim bonus</th>
     <th>...min range</th>
     <th>Laser<br/>range</th>
     <th>Damage<br/>bonus</th>
     <th>Range<br/>bonus</th>
     <th>Vision range<br/>bonus</th>
     <th>...at night</th>
     <th>...in cave</th>
     <th>...in<br/>daylight</th>
     <th>...in bright<br/>daylight</th>
     <th>tunnel<br/>vision</th>
     <th>noise<br/>reduction</th>
     <th>hides<br/>flash</th>
   </tr>
 </thead>
 
 <tbody>
   <xsl:for-each select="$items/ITEM[(usItemClass = 268435456) and (Attachment = 1)]">
   <xsl:sort select="szItemName"/>
    <tr>
     <td><xsl:value-of select="szItemName"/></td>
     <td align="center">
       <xsl:variable name="toHit" select="ToHitBonus"/>
       <xsl:value-of select="$toHit"/>
       <!-- <xsl:value-of select="ja2:ShowStringIfNotEmpty($toHit,'%')"/> -->
       <!-- <xsl:value-of select="ToHitBonus"/> -->
     </td>
     <td align="center"><xsl:value-of select="BurstToHitBonus"/></td>
     <td align="center"><xsl:value-of select="AutoFireToHitBonus"/></td>
     <td align="center"><xsl:value-of select="PercentAPReduction"/></td>
     <td align="center"><xsl:value-of select="PercentReadyTimeAPReduction"/></td>       
     <td align="center"><xsl:value-of select="AimBonus"/></td>
     <td align="center"><xsl:value-of select="MinRangeForAimBonus"/></td>
     <td align="center"><xsl:value-of select="BestLaserRange"/></td>
     <td align="center"><xsl:value-of select="DamageBonus"/></td>       
     <xsl:variable name="range" select="RangeBonus"/>
     <td align="center">
       <xsl:choose>
         <xsl:when test="$range > 0">+<xsl:value-of select="$range"/>m</xsl:when>
         <xsl:when test="0 > $range"><xsl:value-of select="$range"/>m</xsl:when>
         <xsl:otherwise></xsl:otherwise>
       </xsl:choose>
     </td>
     <td align="center"><xsl:value-of select="VisionRangeBonus"/></td>
     <td align="center"><xsl:value-of select="NightVisionRangeBonus"/></td>
     <td align="center"><xsl:value-of select="CaveVisionRangeBonus"/></td>
     <td align="center"><xsl:value-of select="DayVisionRangeBonus"/></td>
     <td align="center"><xsl:value-of select="BrightLightVisionRangeBonus"/></td>
     <td align="center"><xsl:value-of select="PercentTunnelVision"/></td>
     <xsl:variable name="noiseReduction" select="PercentNoiseReduction"/>
     <td align="center">
       <xsl:choose>
         <xsl:when test="$noiseReduction > 0"><xsl:value-of select="$noiseReduction"/>%</xsl:when>
         <xsl:otherwise></xsl:otherwise>
       </xsl:choose>
     </td>
     <td align="center"><xsl:value-of select="HideMuzzleFlash"/></td>
    </tr>
   </xsl:for-each>
  </tbody> 
 </table>

 
  <!-- -->
  <!-- Special area for weapons, sorted by ammo type -->
  <!-- -->
  <hr />
  <h2>Weapons, sorted by ammo type</h2>
  
  <table border="1">
   <thead>
     <tr>
      <th>Item</th> 
      <th>Weight</th> 
      <th>Price</th>
      <th>SF</th>
      <th>Cool-<br/>ness</th> 
      <th>Relia-<br/>bility</th> 
      <th>Tons<br/>Of<br/>Guns</th>
 <!--     
      <th>Ammo</th>
 -->     
      <th>Type</th>
      <th>Hands</th>
      <th>Acc</th>
      <th>Rng</th>
      <th>Dmg</th>
      <th>APs</th>
       <th>Shot<br/>Noise</th>
       <th>Hit<br/>Noise</th>
      <th>Attachments</th> 
    </tr>
   </thead>
 
   <tbody>
    <xsl:for-each select="$ammoStrings/AMMO">
     <xsl:sort select="AmmoCaliber"/>
     <xsl:variable name="cal" select="uiIndex"/>
     <xsl:variable name="calName" select="AmmoCaliber"/>
     <xsl:if test="$cal != 0">
      <tr>
       <td colspan="15"><strong><xsl:value-of select="$calName"/></strong></td>
      </tr>
    <xsl:for-each select="$weapons/WEAPON[ubCalibre = $cal]">
    <xsl:sort select="ubWeaponType"/>
    <xsl:sort select="szWeaponName"/>
     <tr>
      <xsl:variable name="uiIdx" select="uiIndex"/>
      <td><xsl:value-of select="szWeaponName"/></td>
      <xsl:variable name="wgt" select="$items/ITEM[uiIndex=$uiIdx]/ubWeight"/>
      <td align="center">
        <xsl:choose>
          <xsl:when test="$wgt > 0"><xsl:value-of select="$wgt div 10.0"/>kg</xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
      </td>
      <xsl:variable name="price" select="$items/ITEM[uiIndex=$uiIdx]/usPrice"/>
      <td align="center">
        <xsl:choose>
          <xsl:when test="$price > 0">$<xsl:value-of select="$price"/></xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
      </td>
      <xsl:variable name="sf" select="$items/ITEM[uiIndex=$uiIdx]/SciFi"/>
      <td align="center">
        <xsl:choose>
          <xsl:when test="$sf > 0">SF</xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
      </td>
      <td align="center"><xsl:value-of select="$items/ITEM[uiIndex=$uiIdx]/ubCoolness"/></td>
      <td align="center"><xsl:value-of select="$items/ITEM[uiIndex=$uiIdx]/bReliability"/></td>
      
        <xsl:variable name="TonOfGuns" select="$items/ITEM[uiIndex=$uiIdx]/BigGunList"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$TonOfGuns > 0">ToG</xsl:when>
            <xsl:otherwise></xsl:otherwise>
          </xsl:choose>
        </td>
 <!--       
        <td align="center">
         <xsl:value-of select="$calName"/>
        </td>
 -->       
        <xsl:variable name="wType" select="ubWeaponType"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$wType = '0'">Other</xsl:when>
            <xsl:when test="$wType = '1'">Pistol</xsl:when>
            <xsl:when test="$wType = '2'">Mch.Pistol</xsl:when>
            <xsl:when test="$wType = '3'">SMG</xsl:when>
            <xsl:when test="$wType = '4'">Rifle</xsl:when>
            <xsl:when test="$wType = '5'">Sn.Rifle</xsl:when>
            <xsl:when test="$wType = '6'">As.Rifle</xsl:when>
            <xsl:when test="$wType = '7'">LMG</xsl:when>
            <xsl:when test="$wType = '8'">Shotgun</xsl:when>
            <xsl:otherwise>Other</xsl:otherwise>
          </xsl:choose>
        </td>
        <xsl:variable name="hands" select="$items/ITEM[uiIndex=$uiIdx]/TwoHanded"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$hands = '0'">n/a</xsl:when>
            <xsl:when test="$hands = '1'">two</xsl:when>
            <xsl:otherwise>one</xsl:otherwise>
          </xsl:choose>
        </td>
        <xsl:variable name="acc" select="bAccuracy"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$acc > 0">+<xsl:value-of select="$acc"/>%</xsl:when>
            <xsl:when test="0 > $acc"><xsl:value-of select="$acc"/>%</xsl:when>
            <xsl:otherwise><xsl:value-of select="$acc"/></xsl:otherwise>
          </xsl:choose>
        </td>
        <xsl:variable name="rng" select="usRange"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$rng > 0"><xsl:value-of select="$rng"/>m</xsl:when>
            <xsl:otherwise><xsl:value-of select="$rng"/></xsl:otherwise>
          </xsl:choose>
        </td>
        <td align="center"><xsl:value-of select="ubImpact"/></td>
        <td align="center">
         <!-- <xsl:value-of select="(89 - (89 mod ubShotsPer4Turns)) div ubShotsPer4Turns"/> / -->
         <xsl:value-of select="floor((16000 + ubShotsPer4Turns * 90) div (ubShotsPer4Turns * 180))"/>
        </td>
        <xsl:variable name="noise" select="ubAttackVolume"/>
        <xsl:variable name="noiseReduction" select="$items/ITEM[uiIndex=$uiIdx]/PercentNoiseReduction"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$noise > 0">
             <xsl:value-of select="$noise"/>
             <xsl:choose>
              <xsl:when test="$noiseReduction > 0"><br/>(<xsl:value-of select="$noise * (100 - $noiseReduction) div 100"/>)</xsl:when>
              <xsl:otherwise></xsl:otherwise>
             </xsl:choose>
            </xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
          </xsl:choose>
        </td>
        <xsl:variable name="hitNoise" select="ubHitVolume"/>
        <td align="center">
          <xsl:choose>
            <xsl:when test="$hitNoise > 0"><xsl:value-of select="$hitNoise"/></xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
          </xsl:choose>
        </td>
      
      <td>
       <xsl:for-each select="$attachments/ATTACHMENT[itemIndex=$uiIdx]">
 	<xsl:variable name="aidx" select="attachmentIndex"/>      
 	<xsl:value-of select="$items/ITEM[uiIndex=$aidx]/szItemName"/>
 	<xsl:if test="position()!=last()">, </xsl:if>
       </xsl:for-each>
      </td>
 
     </tr>
    </xsl:for-each>
    </xsl:if>
    </xsl:for-each>
  </tbody> 
 </table>

 

</body>
</html>

</xsl:template>

</xsl:stylesheet>
