Help - Search - Members - Calendar
Full Version: XSL for NSCRG - suggestions
Dumpshock Forums > Discussion > Community Projects
Pages: 1, 2
KeyMasterOfGozer
Ok, I made some farther improvement (in my opinion) of my XSLT design.

I made the armour display only the worn armour, and put the "not carried" armour in the regular not carried eqipment list. Also, the Armor section had the column with the weight of the items headed by "No.", so I chnaged that to "kg" and since the "Car" column became redundant, I switched it for the "Book" page number.

Next step is to do the total final armour calculationss from what is worn. I'm not sure how to do that in xslt language, but I'll try to figure it out.

Latest version is:
http://oldforest.net/srchars/SR3-CharacterMG.xsl

I still have heard nothing about how this design could be improved by anyone. Let us know, so we can make things better!
-Mike G
KeyMasterOfGozer
LOL, not that anyone cares, but I have spend the morning and afternoon further refining my design.

Besides Getting rid of some Redundant fields, I added "book.page" references to every item possible.

Changes:

1) I separated the Weapons into "Carried" and "Not Carried" to be able to add "Qty" and "Book" fields to that grid.

2) Since we now have some more detailed Vehicle information in the XML (Thanks McMackie!), I added a better display for the Vehicles.

3) In my last update, I separated the "Worn" weapons and clothing from the "Not Carried". I figured out how to calculate out the Totaled armor rating to add at the bottom of the grid. Here is the code snipet if you guys want to use it for your own templates.
CODE
  <xsl:variable name="max-bal">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/ballistic">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position()=1">
  <xsl:value-of select="." />
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="next-bal">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/ballistic">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position()=2">
  <xsl:value-of select="." />
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="max-imp">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/impact">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position()=1">
  <xsl:value-of select="." />
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="next-imp">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/impact">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position()=2">
  <xsl:value-of select="." />
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
       <TR>
           <TD class="bold divide">Totals</TD>
          <TD class="center divide">
               <xsl:value-of select="$max-bal + ($next-bal div 2)"/>
              /
              <xsl:value-of select="$max-imp + ($next-imp div 2)"/>
          </TD>
    <TD class="center divide"><xsl:value-of select="sum(equipmentlist/armorlist/armor[contains(carried,'yes')]/mass)"/></TD>
    <TD class="center divide"> </TD>
</TR>


4) I added an "Encumbrance" Attribute to the Attributes section, so I could see how close the char is to his carried items weight limit.

5) I changed the "style.css" file that came with Michal K's orginal file. Several people didn't like the "box" grid style, so I changed it to have a more subtile grid style.


So, let me know if any of these changes helped or hurt.

Latest version is:
http://oldforest.net/srchars/SR3-CharacterMG.xsl
http://oldforest.net/srchars/style.css
KeyMasterOfGozer
Ok, I discovered one bug. If you didn't have at least 2 pieces of armor marked "carried=yes", then it would break tha calculations. I added some code to cover that problem and also if the rating was marked "-". Hopefully this covers all bases. Let me know of any other buggs, and you can still donwload from the links above.

Here is the new code snippet if anyone is interested.

CODE
<xsl:variable name="max-bal">
  <xsl:if test="equipmentlist/armorlist/armor[contains(carried,'yes')]/ballistic">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/ballistic">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position()=1">
         <xsl:if test=". != '-'">
            <xsl:value-of select="." />
  </xsl:if>
         <xsl:if test=". = '-'">
            0
  </xsl:if>
      </xsl:if>
    </xsl:for-each>
  </xsl:if>
  <xsl:if test="not(equipmentlist/armorlist/armor[contains(carried,'yes')]/ballistic)">
    0
  </xsl:if>
</xsl:variable>
<xsl:variable name="next-bal">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/ballistic">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="last() &lt; 2">
         0
      </xsl:if>
      <xsl:if test="position()=2">
         <xsl:if test=". != '-'">
            <xsl:value-of select="." />
  </xsl:if>
         <xsl:if test=". = '-'">
            0
  </xsl:if>
      </xsl:if>
    </xsl:for-each>
</xsl:variable>
<xsl:variable name="max-imp">
  <xsl:if test="equipmentlist/armorlist/armor[contains(carried,'yes')]/impact">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/impact">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position()=1">
         <xsl:if test=". != '-'">
            <xsl:value-of select="." />
  </xsl:if>
         <xsl:if test=". = '-'">
            0
  </xsl:if>
      </xsl:if>
    </xsl:for-each>
  </xsl:if>
  <xsl:if test="not(equipmentlist/armorlist/armor[contains(carried,'yes')]/impact)">
    0
  </xsl:if>
</xsl:variable>
<xsl:variable name="next-imp">
    <xsl:for-each select="equipmentlist/armorlist/armor[contains(carried,'yes')]/impact">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="last() &lt; 2">
         0
      </xsl:if>
      <xsl:if test="position()=2">
         <xsl:if test=". != '-'">
            <xsl:value-of select="." />
  </xsl:if>
         <xsl:if test=". = '-'">
            0
  </xsl:if>
      </xsl:if>
    </xsl:for-each>
</xsl:variable>
       <TR>
           <TD class="bold divide">Totals</TD>
          <TD class="center divide">
               <xsl:value-of select="$max-bal + ($next-bal div 2)"/>
              /
              <xsl:value-of select="$max-imp + ($next-imp div 2)"/>
          </TD>
    <TD class="center divide"><xsl:value-of select="sum(equipmentlist/armorlist/armor[contains(carried,'yes')]/mass)"/></TD>
    <TD class="center divide"> </TD>
</TR>

KeyMasterOfGozer
Myself and my friends have been having a lot of trouble with NSRCG when it comes to tweaking a New character. It seems that sometimes when taking stuff away and adding other things, one gets often double charged or not charged at all. Sorry to McMackie that I can't provided any specific details about problems. I just know that when finished and we add up the things by hand, the Karma doesn't add up, or the newyen doesn't add up right.

Anyway, to combat our distrust, I have started making an XSLT that shows us the cost of all the different parts and does Sums for costs and Karma.

Here is the XSLT:
http://www.oldforest.net/srchars/NSRCG-FactChecker.xsl

Some things to note:
1) Karma for the Attributes is tallied and summed just to right of the Attributes.
2) The Active Skills' Karma are tallied and summed in the 3rd section.
3) The Newyen costs for everything except Decks and Software is tallied and summed in the 2nd section called "Cost Counts".
4) THe NSRCG XML file does not contain costs for Decks or Softwares

This is a work in Progress, and it is UGLY right now, but it might help you test NSRCG chars to make sure they really did turn out correct.
KeyMasterOfGozer
In the process of making my Sums I discovered that XSLT is not designed to do complex things like this. smile.gif

Try summing cost * quantity when quantity is only given sometimes. smile.gif

Here is the Template I made to complete that task:
CODE
<xsl:template name="TotalCost">
 <xsl:param name="Items"/>
 <xsl:param name="RunningTotal"/>
 <xsl:choose>
  <xsl:when test="not($Items)">
   <xsl:copy-of select="$RunningTotal"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:variable name="CurrentTotal">
     <xsl:if test="$Items[1]/quantity">
       <xsl:value-of select="$RunningTotal + ($Items[1]/quantity * $Items[1]/cost)"/>
     </xsl:if>
     <xsl:if test="not($Items[1]/quantity)">
       <xsl:value-of select="$RunningTotal + $Items[1]/cost"/>
     </xsl:if>
    </xsl:variable>
  <xsl:call-template name="TotalCost">
   <xsl:with-param name="Items" select="$Items[position()>1]"/>
   <xsl:with-param name="RunningTotal" select="$CurrentTotal"/>
  </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>


Well, this only begins the complexity of calculating Karma, which is recursive and has difference multipliers at any given level depending on Attribs of the char.
Here are a few of the crazy Templates I made to get the Karma magic to happen. (Incidentally, Hats Off to McMackie; as complex as this stuff is, his prog is a miracle!)
CODE
<!-- Calculate the Karma needed to for a particular Attribute Value. -->
<xsl:template name="AttrVal">
 <xsl:param name="Attr"/>
 <xsl:param name="RaceMin"/>
 <xsl:param name="RunningTotal"/>
 <xsl:choose>
   <xsl:when test="$Attr = $RaceMin + 1 or $Attr = 1">
     <xsl:copy-of select="$RunningTotal"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:call-template name="AttrVal">
       <xsl:with-param name="Attr" select="$Attr - 1"/>
       <xsl:with-param name="RaceMin" select="$RaceMin"/>
       <xsl:with-param name="RunningTotal" select="$RunningTotal + (2 * $Attr)"/>
     </xsl:call-template>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<!-- Given an Attribute Node, this returns the Total Karma Needed -->
<xsl:template name="AttrKarma">
 <xsl:param name="Attrib"/>
 <xsl:variable name="Natural" select="$Attrib/natural"/>
 <xsl:variable name="Init" select="$Attrib/initial"/>
 <xsl:variable name="Karma">
   <xsl:call-template name="AttrVal">
     <xsl:with-param name="Attr" select="$Natural"/>
     <xsl:with-param name="RaceMin" select="$Natural - $Init"/>
     <xsl:with-param name="RunningTotal" select="0"/>
   </xsl:call-template>
 </xsl:variable>
 <xsl:value-of select="$Karma"/>
</xsl:template>

<!-- Determine the Value of a particular Attribute from it's Abbreviation -->
<xsl:template name="StatVal">
 <xsl:param name="Stat"/>
 <xsl:param name="Attribs"/>
 <xsl:choose>
   <xsl:when test="$Stat = 'BOD'"><xsl:value-of select="$Attribs[contains(name,'body')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'QCK'"><xsl:value-of select="$Attribs[contains(name,'quickness')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'STR'"><xsl:value-of select="$Attribs[contains(name,'strength')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'INT'"><xsl:value-of select="$Attribs[contains(name,'intelligence')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'CHA'"><xsl:value-of select="$Attribs[contains(name,'charisma')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'WIL'"><xsl:value-of select="$Attribs[contains(name,'willpower')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'MAG'"><xsl:value-of select="$Attribs[contains(name,'magic')]/max"/></xsl:when>
   <xsl:when test="$Stat = 'REA'"><xsl:value-of select="$Attribs[contains(name,'reaction')]/max"/></xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="0"/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<!-- For a Particular Skill's Karma Cost based on it's rating -->
<xsl:template name="KarmaBuild">
 <xsl:param name="Rating"/>
 <xsl:param name="Attrib"/>
 <xsl:param name="Attribs"/>
 <xsl:param name="RunTotal"/>
 <xsl:choose>
   <xsl:when test="$Rating = 1">
     <xsl:value-of select="$RunTotal + 1"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:variable name="AttribVal">
       <xsl:call-template name="StatVal">
         <xsl:with-param name="Stat" select="$Attrib"/>
         <xsl:with-param name="Attribs" select="$Attribs"/>
       </xsl:call-template>
     </xsl:variable>
     <xsl:variable name="AttribMult">
       <xsl:choose>
         <xsl:when test="$Rating &lt;= $AttribVal"><xsl:value-of select="1.5"/></xsl:when>
         <xsl:when test="$Rating &gt; $AttribVal and $Rating &lt;= (1.5 * $AttribVal)"><xsl:value-of select="2.0"/></xsl:when>
         <xsl:when test="$Rating &gt; (1.5 * $AttribVal)"><xsl:value-of select="2.5"/></xsl:when>
</xsl:choose>
     </xsl:variable>
     <xsl:variable name="CurrentTotal" select="$RunTotal + floor($AttribMult * $Rating)"/>
     <xsl:call-template name="KarmaBuild">
       <xsl:with-param name="Rating" select="$Rating - 1"/>
       <xsl:with-param name="Attrib" select="$Attrib"/>
       <xsl:with-param name="Attribs" select="$Attribs"/>
       <xsl:with-param name="RunTotal" select="$CurrentTotal"/>
     </xsl:call-template>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<!-- A Total of Karma for ALL Skills -->
<xsl:template name="TotalSkillKarma">
 <xsl:param name="Skills"/>
 <xsl:param name="Attribs"/>
 <xsl:param name="RunningTotal"/>
 <xsl:choose>
  <xsl:when test="not($Skills)">
   <xsl:copy-of select="$RunningTotal"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:variable name="Karma">
      <xsl:call-template name="KarmaBuild">
        <xsl:with-param name="Rating" select="$Skills[1]/rating"/>
        <xsl:with-param name="Attrib" select="$Skills[1]/linkedattribute"/>
        <xsl:with-param name="Attribs" select="$Attribs"/>
        <xsl:with-param name="RunTotal" select="0"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="CurrentTotal" select="$RunningTotal + $Karma"/>
  <xsl:call-template name="TotalSkillKarma">
   <xsl:with-param name="Skills" select="$Skills[position() > 1]"/>
   <xsl:with-param name="Attribs" select="$Attribs"/>
   <xsl:with-param name="RunningTotal" select="$CurrentTotal"/>
  </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>
bit_buckethead
Does anyone know why the XML files do not display correctly in browsers other that IE? Specifically, the biography section displays the HTML formatting information in Netscape 7.2 and Mozilla 1.72. Any help would be appreciated.
KeyMasterOfGozer
this is the xslt code snipet responsible for that:
CODE
<xsl:value-of disable-output-escaping="yes" select="biography"/>

You could try to get rid of the disable-output-escaping="yes" part, but that should be neccessary incase there is any non-XML HTML in that biography part.
bit_buckethead
Tried removing "disable-output-escaping='yes'" but the only thing that happened was that IE6 then displayed the HTML coding the same way as Netscape and Mozilla.
KeyMasterOfGozer
What OS are you using for Netscape and Mozilla?

I checked in the xslt specification and the disable-output-escaping is appropriate, so I'm not sure what xml engine the Mozilla type browsers are using, but I would have expected them to be closer to correct than MS's, but I guess it is not as complete.
bit_buckethead
I have two machines, a laptop running Windows 95 and a desktop running Windows 98.
I am using Windows 95 for Mozilla 1.7.2 and Windows 98 for Netscape 7.2, Mozilla 1.7.2 and IE6 SP1. Both Mozilla and Netscape exhibit the same behavior independent of OS. I am starting to wonder if it isn't something the Gecko rendering engine. Has anyone tried either of these programs in Win XP?
Scarecrow237
I am using XP and have Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) as my browser. The Biography section does indeed post incorrectly here as others have said. It posts correctly in IE. on my machine.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Dumpshock Forums © 2001-2012