• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unit Testing XSL-FO generation

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know about this?
 
Clifton Craig
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[/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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic