File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes How to structure a XML using XSLT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to structure a XML using XSLT" Watch "How to structure a XML using XSLT" New topic

How to structure a XML using XSLT

Kaushik Baral

Joined: Aug 08, 2009
Posts: 27

I have a xml as below. In the xml below the <Code> node is mandatory and will always appear.

I want to tranform the above xml as, The Field_Type node for <Field_Information> may or may not be there.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036

What you have are chunks of text formatted as XML but NOT a complete XML document because there is no document root.

XSLT or any other XML processing tool will want to see a complete legal XML document.

If you dont have a complete document as input, you could always treat this as a plain text reading, parsing and writing problem.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Another way to make that input document into well-formed XML would be to surround it with start and end tags to act as the root element.

Anyway, once you have valid XML as your input, your next step in writing your XSLT program is to identify rules which map parts of the input to parts of the output. You are going to have to have a rule which refers to every part of the output document, but not necessarily a rule which refers to every part of the input document (as some parts of the input might be ignored). It's also better if those rules don't depend on context, because that makes it easier to write templates which map input to output, but that isn't always possible.
I agree. Here's the link:
subject: How to structure a XML using XSLT
It's not a secret anymore!