Flashkard Printed Output

Enough with the slick GUIs and super-fancy applications--let's get back to the do-it-yourself aesthetic.

I tested the PostScript part with some sample data, and it worked fine. So, on to the next step, which is translating the XML from FlashKard into what is needed to drive the PostScript code. Two pieces are needed here. First, I need the XSL that I have to write. Second, I need a program to read the XSL and the XML files from FlashKard and then output the PostScript to send to the printer.

The easy part was finding the program; xsltproc is exactly this program. One thing down. It now was time to write something in a language I had never seen before. But, could it be worse than writing in an RPN language?

As it turns out, there really isn't much to do. After some XSL boilerplate (<xsl:stylesheet ...>), I needed to define the output format to be text, as HTML is the default. What text means is "anything else". This is done with

<xsl:output method="text">

The first thing I want to output is the PostScript program itself. This is done by including it immediately after a <xsl:template match="/"> tag. The match of / matches the whole XML, so it is processed at the start of the file. Note that I have put the %!PS on the same line as the XSL tag. This is necessary so that the printer can see this as the beginning of the first line of data. Otherwise, the print spooler thinks this is more text and prints rather than interprets the PostScript.

There is one other XSL tag before the matching </xsl:template> tag, which is <xsl:apply-templates/>. This tells xsltproc that any other matching template is to be applied here.

One other template has a match expression of match="e". This matches the block describing an individual card, and it is explained in a comment to the FlashKard article. Within that block is an o block for the original language entry and a t block for the translation. Using the value-of feature, I grab these values, put them in parenthesis and follow them with either front or back.

That's it folks. Assuming the XSL in in ks.xsl, entering the command

xsltproc ks.xsl creatures.kvtml | lpr

gives you your first set of flashcards.

As I mentioned before, this is a proof of concept. Generalizing the PostScript, dealing with line folding and writing a shell script wrapper for this command line would clean things up and make a useful program.

Copyright (c) 2004, Phil Hughes. Originally published in Linux Gazette issue 98. Copyright (c) 2004, Specialized Systems Consultants, Inc.

Phil Hughes, Group Publisher of SSC, likes to get his hands dirty every now and then. But, you won't find him driving a car with an automatic transmission or using Emacs.


Phil Hughes

One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix