GeeCON Prague 2014*
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
Author

How to structure a XML using XSLT

Kaushik Baral
Greenhorn

Joined: Aug 08, 2009
Posts: 23
Hi,

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
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5


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.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
GeeCON Prague 2014
 
subject: How to structure a XML using XSLT