Flashkard Printed Output
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
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.
- New Products
- Readers' Choice Awards 2014
- Handling the workloads of the Future
- Android Candy: Google Keep
- How Can We Get Business to Care about Freedom, Openness and Interoperability?
- Days Between Dates?
- diff -u: What's New in Kernel Development
- December 2014 Issue of Linux Journal: Readers' Choice
- The Awesome Program You Never Should Use
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane