Archive for February, 2007

Exploiting FrameMaker MIF as XML, Reading Bookfiles

Sunday, February 25th, 2007

[Read this for an introduction to what I'm talking about].

Now that we’ve got our FrameMaker documents in XML, how can we exploit their new format? One of the first things I did was to create new ways of reading (eventually changing) the simple data stored within them. This isn’t all that earth-shattering, but when you consider how difficult it is to find and change some values in the FrameMaker UI this is a big win. Where to start? Bookfiles.

To be able to apply stylesheets or data-collection tools to books (rather than individual files), I need to be able to collect a books components. So, convert your bookfile to MX (yeah, it works on bookfiles as well as chapter files), and search through it for one of the filenames you know is a part of the book (you’ll probably want to pretty-print the XML first). I get something like this:

  <BookComponent>
    <FileName>`&lt;c\&gt;ch01'</FileName>
    <Unique>27107</Unique>
    <StartPageSide>StartRightSide</StartPageSide>
    <PageNumbering>Restart</PageNumbering>
    <PgfNumbering>Continue</PgfNumbering>
    <PageNumPrefix>`'</PageNumPrefix>
    <PageNumSuffix>`'</PageNumSuffix>
    <DefaultPrint>Yes</DefaultPrint>
    <DefaultApply>Yes</DefaultApply>
  </BookComponent>

MX in this case has a pretty comprehensible structure, so we’ll need to grab a BookComponent/FileName, do a little text processing to remove the funky characters, and potentially append our MX file extension (I chose “.mx”). Here’s a very simple stylesheet to do just that:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@*|node()">
    <xsl:apply-templates/>
  </xsl:template>  

  <xsl:template match="/">
    <xsl:element name="components">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="//BookComponent/FileName">
    <xsl:param name="extension" select="'.mx'"/>
    <xsl:variable name="str-after">
      <xsl:value-of select="substring-after(., '>')"/>
    </xsl:variable>
    <xsl:element name="component">
      <xsl:value-of select="substring($str-after,
                                      1,
                                      string-length($str-after) - 1)"/>
      <xsl:value-of select="$extension"/>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>

When you run that on a MX bookfile, you should see an output like this (note that the file extension is customizable above):

<?xml version="1.0"?>
<components>
  <component>svcTOC.fm.mx</component>
  <component>foreword.mx</component>
  <component>ch00.mx</component>
  <component>ch01.mx</component>
  <component>ch02.mx</component>
  <component>ch03.mx</component>
  <component>ch04.mx</component>
  <component>ch05.mx</component>
  <component>ch06.mx</component>
  <component>ch07.mx</component>
  <component>ch08.mx</component>
  <component>ch09.mx</component>
  <component>appa.mx</component>
  <component>appb.mx</component>
  <component>appc.mx</component>
  <component>appd.mx</component>
  <component>appe.mx</component>
  <component>svcIX.fm.mx</component>
  <component>svcAPL.fm.mx</component>
  <component>svcLOR.fm.mx</component>
</components>

That’ll give us a nice structure to direct other processes to the individual component files.

The code is also available here or darcs get http://kfahlgren.com/code/mx/.

Ruby and the Atom Publishing Protocol

Saturday, February 24th, 2007

I gave a short talk at the first North Bay Ruby Users Group last Thursday (Feb 15, 2007) about my recent work implementing an Atom Publishing Protocol library in Ruby. Here’s the presentation:

Thumbnail of my Ruby APP talk

North Bay Ruby Users Group: First Meeting This Thursday

Monday, February 12th, 2007

I’m pleased to re-announce a new Ruby Users Group for folks north of San Francisco (or who like to go to Sebastopol, CA): the North Bay Ruby Users Group.

Our first meeting is this week; February 15th, 2007 at 7:00pm. O’Reilly has graciously offered us a place to meet, so we’ll be holding the meetings at O’Reilly HQ in Sebastopol, CA (directions).

Meetings are on the third Thursday of each month. If you’re interested in learning more, please sign up for the mailing list.

Our first meeting will feature Rob Orsini and myself, kicking things off by discussing how O’Reilly uses Ruby to make good things happen.

Please RSVP on the mailing list so we know how much pizza to buy. We hope to seeing you there!

Language Designers Should Listen to Psychologists

Saturday, February 10th, 2007

There are a ton of interesting take-aways from The
Landscape of Parallel Computing Research: A View from Berkeley
, a nice, readable introduction to what a multidisciplinary
group of Berkeley researchers think might be the future of parallel computing. I’d like to share just one that really got me thinking (from page 35):

It is striking, however, that research from
psychology has had almost no impact, despite the obvious
fact that the success of these models will be strongly
affected by the human beings whouse them. Testing
methods derived from the psychology research community
have been used to great effect for HCI, but are sorely
lacking in language design and software engineering. For
example, there is a rich theory investigating the causes of
human errors, which is well known in the human-computer
interface community, but apparently it has not penetrated
the programming model and language design community.

We believe that integrating research on human psychology
and problem solving into the broad problem of designing,
programming, debugging, and maintaining complex parallel
systems will be critical to developing broadly successful
parallel programming models and environments.

via Tim Bray

Exploiting FrameMaker MIF as XML, Back into MIF

Saturday, February 3rd, 2007

[Read this for an introduction to what I'm talking about].

The first step of doing anything useful with MX is the ability to get back out into MIF. Thankfully, this is an entirely trivial job in XSLT.

[This code thanks to my boss, Andrew Savikas.]

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- author: Andrew Savikas, O'Reilly Media -->

  <xsl:output method="text" encoding="ascii"/>
  <xsl:strip-space elements="_facet"/>

  <xsl:template match="/|MIF_ROOT">
    <xsl:apply-templates/>
  </xsl:template>

<!-- This template needs to remain flush left for correct output -->
<xsl:template match="_facet">
<xsl:text>
</xsl:text>
<xsl:apply-templates/>
</xsl:template>

  <xsl:template match="*">
    <xsl:text>&lt;</xsl:text>
      <xsl:value-of select="name()"/>
    <xsl:text> </xsl:text>
    <xsl:apply-templates/>
    <xsl:text>&gt;</xsl:text>
    <xsl:text> </xsl:text>
  </xsl:template>

</xsl:stylesheet>

The code is also available here or darcs get http://kfahlgren.com/code/mx/.

Exploiting FrameMaker MIF as XML, Introduction

Saturday, February 3rd, 2007

My O’Reilly colleague Andy Bruno has just written a pair of posts on converting FrameMaker’s MIF (link may be old/die) format into XML (henceforth ‘MX’). I’ll be writing a few posts outlining the ways in which we’ve leveraged MX at O’Reilly.

[Update: Series continues here with getting back into MIF, and reading bookfiles.]

(more…)

Amazon Scrape -> SVG Graph in Ruby

Thursday, February 1st, 2007

I just spent a few minutes enjoying Mongrel and SVG::Graph while helping Rob visualize his Amazon Sales Rank for his book.

The code is available here with a running (maybe) example here. If all goes well, that should show you an SVG graph (thanks, Firefox) showing the changes in sales rank over time.

Rob’s code to generate the scrape is here.

Picture:
Rob Sales Rank

[Update: darcs get http://kfahlgren.com/code/]