XSL Soldiers Fall In!

I explained yesterday that I was looking for new recruits in my quest to take over the world and I got no replies. (Not surprising when you realize I still have less than a handful of devoted readers and a handful of them have probably been intimidated by over the top stoopidity.) Now I’m out visiting some well known communities in an attempt to recruit what will be the most agile of assasins for my plot of world domination. Now is your time to jump on as a willing participant rather than later when you will be viewed as the enemy. My expectations are not abundant. The barrier to entry is low.

What is this all about anyway?

I never was any good at recruiting or giving good sales pitches. Getting to the point… I’ve been working on a new XML grammar to be used for generating XSL-FO templates. To be more concise, XSL-FO templates are XSLT stylesheets that generate FO syntax. I’m not sure if there’s an official name for such templates or if they are even considered differently from typical XSLT stylesheets but it seems to me that a distinction should be made. You see there’s raw FO syntax (which almost nobody ever codes by hand) and there’s XSLT stylesheets that generate the raw FO. I’m writing a stylesheet that generates the stylesheet that generates the raw FO. (Along those same lines, I wish I could take out a person to take out the garbage on Wednesday nights.) Got it? Good! Moving along to where I’m at… I’m getting stuck on unit testing. I’m not necessarily stuck but I’m not necessarily unit testing either.

Yo man, what?

Let me explain. I currently need a way to validate first the XSL-FO that I generate and secondly validate the FO that the generated XSL-FO creates. I’m doing a lot of manual work right now to acheive this. What I do is load a sample of my custom XML grammar (I call it SSML) into a TrAX transform with my SSMLStylesheet. (That’s what generates the XSL-FO.) I diff it against a golden copy of what I believe the output XSL-FO should look like. I’ve also been separately testing the golden copy to make sure it actually works and generates a PDF when run against FOP.

I desparately need a way to streamline the entire process. I want to enahnce the golden copy and have an automated test verify that the changes I make still generate valid FO syntax. I also want to verify the output of my SSMLStylesheet is valid XSLT before diff’ing it against my golden copy. I’m also having a little trouble with XMLUnit doing diffs. I’ve gotten spoiled
with Idea’s auto-diff on failed String assertions in junit tests, so when I see the messages generated by XMLUnit it takes a moment to decipher what’s actually wrong. What I’ve been doing is trapping the XMLDiff AssertionFailedException and doing an assertEquals on the two XML strings so I can take advantage of Idea’s diff. It’s clumsy but I can pick out the error a little better this way. It looks like this:

    public void assertXMLEqualWithDetailedDiff(String expectedXML, String actual) 
            throws SAXException, IOException, ParserConfigurationException
        Diff diff = new Diff(expectedXML, actual);
            assertTrue(new DetailedDiff(diff).toString(), diff.identical());
        catch(AssertionFailedError e)
            assertEquals(e.getMessage(), expectedXML, actual);

With that code nugget I get failures only if the XML is not similar in terms of XMLUnit but I still get the little diff hyperlink in Idea to compare the results. If you have never seen what a String diff looks like in an Idea unit test, here’s an example:
Screen shot in Idea with diff hyperlink
The problem here is that the generated stylesheets are not formatted (indented and such) so even with Idea’s string diff I have to squint, turn my head sideways and figure it out. What I do then is copy the generated stylesheet and paste it in a temp file and format it. That moves completely away from unit testing and is more of an eyeball test. I’m hurtin’ here. I want my cake and eat it too.

Tell me mo’ about dis’ cake…

Mmmmm… cake… aaaahhhhhhh…Oh yeah, my testing dreams!
I want to be able to run my unit test over the stylesheet and, when something errors out, get one of those cool Idea diff things where the lines all line up. I want to be sure that the generated stylesheet works without having to monkey around and test the results manually. I want the complete confidence that each stage of my processing is bug free. (I also want one of those cool little bluetooth ear piece thingies like what Jack Bauer wore in 24 but I have neither a cell phone nor an immediate need for it. I want it because it looks cool.) If you are slick enough with XSL or unit testing XML results please lend a brotha a hand. ‘Till next time, I’m 5000…

(While 5000 cannot possibly my age the excerise is left to the reder to interpret the intention which may be derived from context. By the way, 5,000 is just as whack as holla… it’s soooo old school but I can’t think of a better sign off unless I use something potentially trademarked like “Seacrest out!”)

2 thoughts on “XSL Soldiers Fall In!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s