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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Google's Abacus Project: It's All about Trust
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Seeing Red and Getting Sleep
- Fancy Tricks for Changing Numeric Base
- Secure Desktops with Qubes: Introduction
- Working with Command Arguments
- Secure Desktops with Qubes: Installation
- CentOS 6.8 Released
- Linux Mint 18
- The Italian Army Switches to LibreOffice
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide