This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

output xml structure problem  RSS feed

 
Ashish Nandan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am a newbie in XSL. I have transformed an xml to another xml using XSL Transformation. But instead of creating parent node and filling child node one by one in it. It is creating parent node every time it finds a child node.

Following is my xml file

And following is my xsl file



and following is the output xml



Now I am not able to create one parent node <Content> and add all the <ContentNo> node in it.
Kindly help
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first of all your XSLT is more complicated than it needs to be (even though it appears very simple). It is equivalent to this:


But anyway, your complaint is that for each IndexEntry element you create a new Content element? Well, yeah. That's exactly what the posted code does. (Maybe the simple version displays that more clearly than the complicated version?)

So to solve this problem, you need to come up with a specification which describes when you want to generate a Content element and when you want to generate a ContentNo element. Something like "For each X in the source I want to generate Y". You are going to have more than one template because you will have different rules for when you generate the two elements. Give it a try and see what you come up with.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!