• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

XML Transform

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to transform (with javax.xml.transform.Transformer) an XML structure that I create programmaticly (with org.xml.sax.ContentHandler), and this works perfectly I can write the XML out to a file and validate that it is created correctly. I then read an XSLT file in and attempt to transform the XML structure with it. The result does not have any of the XML data in it.

If I take the XML and add the xml-stylesheet instruction pointing to the XSLT file. I then open the XML file through a processor (I used Firefox) and the result is correct, it contains the transformation and the data from the XML. Which means that the XSLT is correct.

In the code sample below the doc.getSourceForDocument() is what builds the XML structure and [I]xslt[I] is the full path to the XSLT file used.



Thanks for any and all help.
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have managed to get this to work, unfortunately it is not the most desirable way of doing things. I am writing the XML structure out to a temp file and then reading it back in and using that. This has some obvious performance issues, but at least it works.
 
Marshal
Posts: 25677
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, now I think I see your problem. Your Source object contains an input stream. (You can't tell that by looking at your posted code.) The first transformation consumes all the data in that input stream and leaves its cursor positioned at end of file. The second transformation starts from there and then (of course) there's no more data to read.

So, using a File object as your source works because reading from it is repeatable. Perhaps the real fix should be to make doc.getSourceForDocument() return something that can be read repeatedly. Or perhaps the fix is as simple as this:

Again, it's not possible to say for sure without seeing what doc.getSourceForDocument() does.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic