• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to structure a XML using XSLT

 
Kaushik Baral
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic