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.
Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report
August 27, 2015
12:00 PM CDT
DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.
Free to Linux Journal readers.Register Now!
|Secure Server Deployments in Hostile Territory, Part II||Jul 29, 2015|
|Hacking a Safe with Bash||Jul 28, 2015|
|KDE Reveals Plasma Mobile||Jul 28, 2015|
|Huge Package Overhaul for Debian and Ubuntu||Jul 23, 2015|
|diff -u: What's New in Kernel Development||Jul 22, 2015|
|Shashlik - a Tasty New Android Simulator||Jul 21, 2015|
- Secure Server Deployments in Hostile Territory, Part II
- Hacking a Safe with Bash
- Huge Package Overhaul for Debian and Ubuntu
- KDE Reveals Plasma Mobile
- The Controversy Behind Canonical's Intellectual Property Policy
- Shashlik - a Tasty New Android Simulator
- Home Automation with Raspberry Pi
- Embed Linux in Monitoring and Control Systems
- diff -u: What's New in Kernel Development
- General Relativity in Python