Skip to main content.

Creating XSL Character Sheets

I got into creating character sheets for RPGXplorer as soon as the XML Workshop section was added. XSL was something I had always wanted to learn, but I never had anything practical to try working with it. So I dove in head first. The first thing I made was the DMG II stat block which took me roughly 3 weeks to piece together, and had half of the information that it does right now. Once everyone started to see what could be done with XML Workshop and XSL, they started wanting more, and a real character sheet. Anurien got permission to use a popular eTools character sheet, then got me to actually write it. The end result is what is now referred to as the 3.5 Classic character sheet. The Spell List sheets were created immediately after by breaking out the spell list section of the Classic sheet into a stand-alone XSL sheet. I've since taken what I have learned and made the 3.5 Revised sheet, and made a few others by request - the Combat Block and Character Card sheets.

For those of you who are interested, here is how I go about creating a new XSL sheet for RPGXplorer.

There are a few fundamental things you'll need to know to get started yourself. HTML, XML, XSLT, and XPATH are the skills/technologies you'll be working with. HTML is about the only absolute must. The rest you can pick up as you go along.

I knew a little about XML, almost nothing about XPATH, and didn't know XSLT at all when I first started attempting to put the sheets together. The best way to get the hang of anything is to just start using it and see what does and doesn't work. You won't ruin anything by trying, and you won't learn anything if you don't try. I found Google to be my best friend throughout the learning process. For quick information about these technologies, I'd recommend checking out w3schools.com.

XML: http://www.w3schools.com/xml/default.asp
XSLT: http://www.w3schools.com/xsl/default.asp
XPath: http://www.w3schools.com/xpath/default.asp

The first step is to figure out how exactly I want the sheet to look. Most of the sheets I have done have been modeled after a sheet that currently exists, such as the DMG II stat block, the revised character sheet from the Wizard's site, and so on, so it's just a matter of acquiring a copy of that sheet. Easy enough.

Next, I create an HTML version of the sheet. You can use any application that will let you create an HTML page. Personally, I use Visual Studio 2003 and write everything by hand. I prefer to have total control over everything and write clean HTML code which will be easier to take apart later on, rather than trying to patch up the HTML code written by some WYSIWIG editor. This is by far the longest step of the creation process.

Once the HTML file is done, I start crafting the XSL file. I begin by copy the HTML code and pasting it into the XSL file. I don't want to change the HTML file since I often refer back to it during the process since bits and pieces can go missing or formatting can change when I'm tearing out and replacing chunks of code. Once the HTML code is in there, I put in the opening and closing block of XSL code - the sections that define that this is an XSL file and enclose the HTML code in a template. Next, I get the easy stuff out of the way. Things like character name, alignment, etc. that don't involve any sort of math or repetition. These are typically one line of XSL code that just replaces a piece of text from in the HTML section.

I then move onto the stats - putting in the base stats themselves, the modifier bonus, and the breakdown of how that number was reached (base stat + magic modifier, etc.). That's the easy stuff out of the way.

Now I move onto the Skills and Feats sections. These are fairly basic loops that just run through everything it finds.

Weapons is where it starts to become tricky with a lot of conditional work. The ranged distance table appears for any weapon with a range increment, and each range and attack bonus are dynamically calculated. Conditional checks are also needed to determine if an off-hand weapon is being used so that this off-hand weapon info can be displayed, as well as if a shield is equipped.

When the weapons are done, I move onto the spells. This is a bit of a complex process, since the spells must be group by level and class, the spell DCs are dynamically calculated, and the number of spells known, spells per day, and base spell save DC sections are populated.

After completing the spells portion, I immediately move onto the psionic powers section. Thankfully the XML structure is almost identical, so it's just a matter of copying and pasting the spells piece, then change a few small words.

The inventory piece is usually the biggest hassle since it needs to be formatted into two columns. I've struggled with this bit for quite some time to finally get it behaving properly. The template that creates the resulting sheet itself only ever looks at the containers your character carries. The sheet passes the container information to another XSL template which is responsible for figuring out the actual items. The template reads through every item in the container, sorts it, then spits out the entire thing as an HTML table.

Finally I put in the Turn Undead and Rage pieces. I have split the bulk these into separate XML files whose sole task is to crunch numbers and store them into variables, isolating everything from the actual XSL sheet. Each piece only exposes just the final numbers that the XSL sheet needs to display. Since these are common and cumbersome pieces, it made sense to break them out into individual files. This way the Turn Undead or Rage calculation code can be updated once and cascade down to multiple sheets. It makes the XSL sheets much smaller and means I have to write and update a lot less code.

The end result is a brand new character sheet.

Since any new sheet I create will be using roughly the same information, I usually just copy blocks of XSL code from other sheets and paste them into the new one I'm working on and make minor tweaks to get them to fit. Code re-use is your friend! The intial version of each sheet takes me about 2 - 3 weeks worth of evenings to put together from start to finish. Then comes all of the updates from people who catch silly problems or put in requests for additional things... :)

If you want to try creating your own XSLT character sheets, I strongly encourage you to. All you really need is a text editor and some time. Check out the tutorials I listed above for details on how to use the technologies, and feel free to examine the code in any of my XSL sheets. They're by no means perfect, but having a working example you can refer is always helpful. I often referred to other XSL files to see how they got bits and pieces to work.

Happy coding!