• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

A XSLT Question

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am now trying to create a new xml document with a xslt. The problem is that I have to create such a xml structure:



out of this xml Source:



Is it possible to build a "List" with xslt or should I access the XML Source with java and build a new DOM?
 
Marshal
Posts: 28298
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to write Java, then you should write Java. But I warn you that DOM programs are ugly and brittle and hard to maintain when the requirements change.

XSLT is not Java, and it is not like Java. I don't know why you thought you need a list but that is not how you do things in XSLT. What you should do instead is to describe how and when you would create one of those <child> elements, based on the contents of the input file. Then you write XSLT code that does that.

Give that a try. Why do you have an element <child number="2"> and where does the data come from in the input document?
 
Alex Philippi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I only want to handle this in java if there is no way to realise it with xslt.
The <child number="2"/> is the transformed result of <position number="2"><parentNumber>1<...../>.

Could I first use (in XSLT) <xsl:apply-templates ... /> to write all <position/> without a parent number to the result xml file and then use again <xsl:apply-templates ... /> to hang all <position> tags with a parentNumber as new <child number="X"/> node under the according <position/> node?
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your job can be done by xslt only.

However, it makes no sense to me. I don't see any reason for me to do it.
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic