java DOM vs. xsl

R

Ryan Gaffuri

I have been skimming through xsl. why would you want to use it? It
seems extremely difficult to maintain and archaic. does it have
functionality that you can't do with a java DOM object or something
like xerxes?
 
W

Will Hartung

Ryan Gaffuri said:
I have been skimming through xsl. why would you want to use it? It
seems extremely difficult to maintain and archaic. does it have
functionality that you can't do with a java DOM object or something
like xerxes?

While XSL can be difficult to grasp at first, it's a very powerful
transformation tool. You can do a lot of stuff with little code compared to
crawling the DOM tree yourself.

XSL makes it very practical to essentially not have to worry about the
specific XML that comes into your site.

When you're trying to work with customer data, you both need to agree on a
specific format for that data.

In our case, our team is pretty savvy with things like XML and XSL etc.,
where as many of our customers (who's specialty is their domain, rather than
computers and data processing) don't have as much expertise. So, they are
able to export data using high level tools provided by their vendor, but
which may not exactly meet our import specifications. So, we simply write an
XSL script that converts from their XML format to our XML, and then our XML
loader does the rest.

This kind of filtering is reasonably easy to write save for the most obscene
of circustances (and we never see those as we can direct the customers to
create an XML document that is Close Enough for our purposes).

But the XSL is more compact and mostly easier to use than walking the DOM
ourselves, AND as XSL processing gets better and "smarter", so do our
scripts.

XSL is just Yet Another high level abstraction over a specific domain, and
it's almost always better to work at that high level than not.

And with the Java XSL processors where we can add in our own processing
using Java Classes, it makes it even more powerful. For example, our XSL
scripts not only convert the custom XSL to our internal XML format, but post
messages to JMS queues to move the processing forward.

It's not a Silver Bullet, but it's a great tool worth learning if you work
with XML a lot.

Regards,

Will Hartung
([email protected])
 
D

Donald Roby

I have been skimming through xsl. why would you want to use it? It seems
extremely difficult to maintain and archaic. does it have functionality
that you can't do with a java DOM object or something like xerxes?

XSL can do nothing that couldn't be done in pure Java (or most any
language you choose), but it can do many things more easily and with more
concise and succinct code than you could do them in Java with DOM objects
or SAX parsing.

I don't think it's particularly any more difficult to maintain, as long as
the original developer and the maintainer know XSL well, but it is an
additional language, and using it effectively sometimes means thinking in
a slightly different way than a Java developer might be used to.

Archaic? I can't quite conceive of why you would think this at all.

As an example, in a recent project, I've used a combination of XSL and SAX
to load data from an Excel spreadsheet saved as XML into Java objects. The
SpreadsheetML format produced by the save contained *alot* of extra
formatting stuff that I didn't need. Using XSL to extract only the
desired data into a simpler form of XML, and then using SAX to parse the
result and create the Java objects was much easier than loading the entire
thing into a DOM object and trying to pull out the important stuff. It
almost certainly also has a smaller memory footprint. While SAX parsing
could certainly do the same without the XSL and keep the small memory
footprint, I think the code would be less clear and thus harder to
maintain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top