Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
to transform or not to transform
Old 04-23-2008, 06:48 AM to transform or not to transform
Novice Talker

Posts: 12
Name: Matthew Benton
Trades: 0
I've got a news page which is being sent out as an email to our organisation from a java application (which I'm coding). But we don't want the top and left navigation divs.

My boss muttered something about using an XSL transform to select the divs we do want, but I reckon he thinks I'm starting with a load of XML data, (which I'm not, the app is dealing with existing html code). So does applying a transform to an html page to produce another html page make sense? Or do I have to do a load of string manipulation in Java (potentially messy). Or maybe there's a better way?

Thanks in advance!
matt
mattnotfat is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-23-2008, 07:38 AM Re: to transform or not to transform
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
XSL cannot be applied to HTML.
It can only work on XML, but can output HTML.

I have no past experience in Java, but try to look for a DOM parser.
It allows you to instantiate a tree of the page, and then you should be able to exrtact what is useful for you, and re-create a simple html with an XSL processor.
Here is a PHP dom parser reference:
http://www.php.net/manual/en/domdocument.loadhtml.php

PS:
I just found this via google:
http://java.sun.com/j2se/1.5.0/docs/.../Document.html
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-23-2008, 07:48 AM Re: to transform or not to transform
Novice Talker

Posts: 12
Name: Matthew Benton
Trades: 0
Ah, thanks tripy. A Dom passer sounds more appropriate for this
mattnotfat is offline
Reply With Quote
View Public Profile
 
Old 04-23-2008, 11:32 AM Re: to transform or not to transform
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Quote:
Originally Posted by tripy View Post
XSL cannot be applied to HTML.
But, it can be applied to XHTML

Quote:
Originally Posted by tripy View Post
I have no past experience in Java, but try to look for a DOM parser.
It allows you to instantiate a tree of the page, and then you should be able to exrtact what is useful for you, and re-create a simple html with an XSL processor.
Since version 1.4 all standard java installs come with both a parser and xsl transformer.

For HTML, one option could be to use jTidy to get a DOM object. This can be fed to a transformer, manipulated or just written out.

For your particular case, try jTidy to create a DOM, then remove the nodes corresponding to the divs you don't want, then just output the DOM object as XHTML.

Of note, jTidy is also pretty good at dealing with bad markup.
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to to transform or not to transform
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47747 seconds with 12 queries