permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Unit Testing XSL-FO generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Unit Testing XSL-FO generation" Watch "Unit Testing XSL-FO generation" New topic
Author

Unit Testing XSL-FO generation

Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
I've been working on a complicated project where I'm building a simple XSL-FO generator. It's a fun project and I've been blogging about it on my site. I'm now having some trouble working with unit tests and I'm wondering if there are any XSL gurus out there that can help me. I need a way to verify genrated XSLT and FO syntax after generation. I also need an easy and comprehensive way of doing XML diffs in my unit tests. I'm using XMLUnit but I want error feedback that is easier to decipher. I have a kludgy work around that gives me the benefits of the Idea visual string diff in unit tests with the less restrictive comparison funcationality found in XMLUnit. While my workaround helps it's a hack and I'm having a small problem with it too. I'm really looking for some XSL/XML die-hards that can give me some guideance. Are any of you out there good with validating XML in unit tests? Help!


Holla at me...<br /><a href="http://codeforfun.wordpress.com" target="_blank" rel="nofollow">http://codeforfun.wordpress.com</a>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Sorry, I haven't ever got that deep into XSLT testing. But just a comment -- if you think for a bit about all the possible issues involved in XML diff processing, you may agree with me that it's going to be pretty difficult to achieve both of "easy" and "comprehensive".
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
Originally posted by Paul Clapham:
Sorry, I haven't ever got that deep into XSLT testing. But just a comment -- if you think for a bit about all the possible issues involved in XML diff processing, you may agree with me that it's going to be pretty difficult to achieve both of "easy" and "comprehensive".


That's ok Paul,

I've been thinking some. My problem isn't necessarily related to unit testing the stylsheets. Instead my issue is composed of a few sub-issues. For one, I need to figure out how to get Xalan to pretty format the results including line breaks and indentation. That would be a huge help. That would give me an "easy and comprehensive" way to pick out what's missing or wrong on the transform. After that I need a way to validate the generated XSLT. Since there's no DTD that I know of for XSLT I can't quickly code an isValidXSL method to do this for me. The alternative, I suppose, is pushing the generated XSLT through Xalan and seeing what comes out. That brings me to my third problem. I need a way to validate FO syntax. If I could push my genrated XSL through Xalan and then validate the result then I would be golden. So in all my problem is really two smaller problems, XML pretty formatting, and an FO validation issue. Solving both of these would put me on track.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12784
    
    5
I just did a google search for "xml fo dtd" and found a LOAD of relevant hits, many of which are concerned with validation. Note that Java 1.5 has a new javax.xml.validation package that you might find useful.
Bill
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
Thanx Bill,

That really helps. I didn't know about the javax.xml.validation stuff. Apparently you can construct a Schema instance from a factory using a Source and ask the Schema for a validator. I did the google search and found an XSL-FO schema from Render-X. Hoping that it's standards compliant, I believe that's just what the doc ordered. I'm trying it now and I'll post back on my progress. Thanx again!
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
One other thing. Could someone help me get my XMLStream from Xalan's transform handler formatted with line breaks and indenting? That would be the fat piece of the pie that my momma won't let me eat.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Do you know about this?
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
[/qb]<hr></blockquote>
Thanx a bundle Paul,

No I don't know of that one. Which API is that on? javax.xml.transformer.sax.TransformerHandler has no such method. Niether does javax.xml.transformer.sax.SAXTransformerFactory. Is that an XMLUnit thing? By the way, I'm having trouble getting XMLUnit to ignore whitespace on the diff. Here's my code:


Here's the expected XML:



Here's the actual, or returned value in writer:


I'm getting desparate here. Help!

[ June 21, 2006: Message edited by: Clifton Craig ]

[ June 21, 2006: Message edited by: Clifton Craig ]
[ June 21, 2006: Message edited by: Clifton Craig ]
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
Crud! That last post threw off the format of the forum. I'm thinking of editing it and trying to wrap the XML or something. Anyhow I see the the method call is on the Transformer in XMLUnit. I haven't used that much. (Duh!) I'll give it a whirl and get back to you. Thanx again...
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
Paul,

You're a life saver! I was getting ready to give up. I'm still puzzled by my above code exmple but when I changed it to use the XMLUnit Transform object my whitespace issues went away. There was a very valid and stoopid reason I was insisting on using the TrAX API to do the transform. I was trying to emulate exactly how the transforms are done in production. I notice I get slightly different results when I do transforms this way and it's this subtle difference I'm trying to nail down. That seems to be the root of all my pain. Maybe someone can explain to me why things work differently when I do transforms via the XMLFilter interface as opposed to other means?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unit Testing XSL-FO generation