• 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

Please point me in the right direction with XSL transformation

 
Ranch Hand
Posts: 117
Mac Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still have about 7 chapters to go to get a better understanding of XSLT, but I've done basic XML->HTML transformations already. I have a nice HTML/CSS template that I'd like to use for my project, but since an XSL file is XML, then the parser will be picky - and rightly so. HTML has its quirks (ok, a lot of them), and since it does, how can I make sure the parser actually parses everything while ignoring all the HTML in a file?

Having something like this works great:



But what if it's just a normal file with attributes and CSS, tags which are not closed, etc? Surely there must be a way and this is where I'm stuck with my project.

Oh, by the way - I'm using Saxon Home Edition for XSLT. Unfortunately it's version 6.5.5 as I just downloaded the Ubuntu package, but will probably upgrade it tomorrow to 9.3.

 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I remember right, the correct approach is to make sure tags are closed. Imagine you're writing XHTML - make sure everything is well formed (CSS isn't a problem - it's in a <style> tag and should be plain text other than that). Then, the important part is the <xsl:output method="html"/> line. That tells the transformer to output HTML. So you put in a <br/> and it will output <br>, for instance.
 
Paul Mrozik
Ranch Hand
Posts: 117
Mac Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Matthew. I suppose I need to convert the HTML file to XHTML.
 
Marshal
Posts: 28193
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
I'm not sure I understand what you mean by "the HTML file" now. Do you have an HTML file which is going to be transformed by that XSLT? If so, yes, it has to be well-formed XML, but that isn't the usual process. Usually people just start with XML which doesn't have to be HTML in any way, and transform that into HTML.

Or if you're producing an HTML file from that XSLT, as your example shows, then what Matthew said is correct. Generate output with matching open and close tags and so on, and it's the transformer's job to produce real HTML. You don't have to post-process it.
 
Paul Mrozik
Ranch Hand
Posts: 117
Mac Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Do you have an HTML file which is going to be transformed by that XSLT? If so, yes, it has to be well-formed XML, but that isn't the usual process. Usually people just start with XML which doesn't have to be HTML in any way, and transform that into HTML.



Yes, exactly. I have a nice HTML/CSS template and I need XSLT to insert some text from an XML file into it. I did the following to remedy the problem:

1. Used tidyhtml to clean up the file, available at http://tidy.sourceforge.net/ but I downloaded it via macports.
2. Removed the remaining errors until it validated here: http://validator.w3.org/check
3. Got rid of the following line:



which caused a Transformation failed: org.xml.sax.SAXException: Scanner State 24 not Recognized error and drove me nuts.

Of course the HTML file was changed to .xsl and appropriate headers were added.

...and it worked!

Now I need to learn more XSLT and figure out how to use conditional statements, but I'm one step ahead.

Thanks again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic