View Single Post
Old 11-01-2017, 10:28 AM   #1
Liantefaron
 
Liantefaron's Avatar
 
Join Date: Dec 2005
Location: Giessen/Hessen/Germany
Default (Ab-?)Using GCA files as HTML table reference/shopping list

Hi guys,

I had an idea I'd like to share with you, namely, to display the existing GCA data files' equipment sections as a sortable, filterable shopping list (like in this screenshot).


Since this uses existing data (.GDF data sheets) and mechanisms (a .GCE export sheet), I'm confident that it wouldn't violate SJGames online policy... possibly as long as one has a valid GCA4 license to get at the "official" GDF files and actually use a GCE export sheet on them.

What you need:
  • GCA4 to process GCA files with a GCE sheet
  • A text editor (I use Notepad++ for XML highlighting)
  • Optionally Excel (or LibO Calc) to easily modify the XML
  • The example XSL sheet below to tell your browser to display the XML nicely
  • (optionally) the list.js JavaScript library, which adds sorting and filtering to XML/HTML tables

Here's how it works:
  1. Install a GCE export sheet that will render GDF data as XML. I have (mis-)used Spyke's Fantasy Grounds export filter, renamed it to "xml export equipment.gce" and deleted/commented out all sections following line 65 except the "Call PrintEquipment()" directive.
  2. Open a blank character in GCA4 with your data files of choice loaded and add all equipment to him (or her, or whatever).
  3. Use the export sheet to create your XML version of the equipment entries.
  4. Optional: Open the XML file in Excel and hide/delete columns you won't need, then save back as XML.
  5. Optional: Localize the XML for your non-English-speaking players by opening the XML in Excel, adding a new nameDE (or nameFR, nameES, etc.) column next to the 'name' column and save again as XML.
  6. Use a text editor to add <?xml-stylesheet type="text/xsl" href="GURPSequipment.xsl"?> as a new line after the opening <xml ...> tag. This will tell your browser to look for the specified XSL file to display the XML file.
  7. Use an XSL file to output the XML as HTML, so that your browser can render it in a way that doesn't look awful. Two examples follow, one for a bland English-only table and one for a localized table that uses the list.js library and some CSS to improve the look.
  8. Put the XML file, XSL file and optionally the list.js / list.min.js files in the same directory and open the XML file with your browser.
  9. Quickly search for equipment, look up relevant stats or the item's page reference for the full information. Bam!

Example XSL Sheet for a bland, English-only HTML table:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
	<html>
	<body>
	<h1>GURPS Equipment (XSLT Conversion from GCA Files)</h1>
	<p><a href="index.php">Back to Index</a></p>
		<table border="1" cellspacing="0" cellpadding="2" color="#DDDDDD" style="border:1px solid #ddd;">
			<tr>
				<th>Item</th>
				<th>Cost</th>
				<th>Weight</th>
				<th>LC</th>
				<th>TL</th>
				<th>Page</th>
				<th>Other Info</th>
			</tr>
			<xsl:apply-templates/>
		</table>
	</body>
	</html>
</xsl:template>

<xsl:template match="equipment">
	<xsl:for-each select="*"> <!-- take all descendants of equipment (ID tags) -->
		<tr>
			<!--<td><xsl:value-of select="local-name()"/></td>-->
			<td><xsl:value-of select="./name"/></td>
			<td><xsl:value-of select="./basecost"/> <xsl:text>$</xsl:text> </td>
			<td><xsl:value-of select="./baseweight"/> <xsl:text>lbs.</xsl:text> </td>
			<td>
				<xsl:choose>
					<xsl:when test="./lc != ''">
						<xsl:value-of select="./lc"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>4</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="./tl != ''">
						<xsl:value-of select="./tl"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>3</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</td>
			<td><xsl:value-of select="./page"/></td>
			<td style="font-size:0.8rem">
				<xsl:choose>
					<xsl:when test="./damage != ''">
						<xsl:text>Dam: </xsl:text> <xsl:value-of select="./mode"/>
						<xsl:text> </xsl:text> <xsl:value-of select="./damage"/>
						<xsl:text> </xsl:text> <xsl:value-of select="./damtype"/>
						<xsl:text> / R: </xsl:text> <xsl:value-of select="./reach"/>
						<xsl:text> Parry: </xsl:text> <xsl:value-of select="./parry"/>
						<xsl:text> MinST: </xsl:text> <xsl:value-of select="./minst"/>
						<xsl:text> / Acc: </xsl:text> <xsl:value-of select="./acc"/>
						<xsl:text> D: </xsl:text> <xsl:value-of select="./rangehalfdam"/>
						<xsl:text> Max: </xsl:text> <xsl:value-of select="./rangemax"/>
						<xsl:text> RoF: </xsl:text> <xsl:value-of select="./rof"/>
						<xsl:text> Shots: </xsl:text> <xsl:value-of select="./shots"/>
						<xsl:text> Blk: </xsl:text> <xsl:value-of select="./bulk"/><br/>
					</xsl:when>
				</xsl:choose>

				<xsl:choose>
					<xsl:when test="./dr != ''">
					<xsl:text>DR: </xsl:text> <xsl:value-of select="./dr"/>
					<xsl:text> </xsl:text><xsl:value-of select="./location"/><br/>
					</xsl:when>
				</xsl:choose>

				<xsl:choose>
					<xsl:when test="./skillused != ''">
					<xsl:text>Skill: </xsl:text> <xsl:value-of select="./skillused"/> <xsl:text> / </xsl:text>
					</xsl:when>
				</xsl:choose>
				<xsl:choose>
					<xsl:when test="./notes != ''">
					<xsl:text> Notes: </xsl:text> <xsl:value-of select="./notes"/> <br/>
					</xsl:when>
				</xsl:choose>
				<xsl:choose>
					<xsl:when test="./description != ''">
					<xsl:text> Desc: </xsl:text> <xsl:value-of select="./description"/> <br/>
					</xsl:when>
				</xsl:choose>
				<xsl:text> Cat: </xsl:text> <xsl:value-of select="./cat"/> <br/>
			</td>
		</tr>
	</xsl:for-each>
</xsl:template>

<!-- do nothing for unmatched text or attribute nodes -->
<xsl:template match="text()|@*"/>

</xsl:stylesheet>
Cheers,
Christopher
__________________
Liantefaron - Hunter of Spiders
Woodelven Ranger

Real Name: Christopher.
steinmetze.org (with my GCA-datafiles) has perished in 2012. Try an archive.org version if you need them.

Last edited by Liantefaron; 11-01-2017 at 11:17 AM.
Liantefaron is offline   Reply With Quote