This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSL problem

 
Aby Krishna
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure which is the right forum for a xsl related question (though still programming in Java).

But have a question about it: "How to traverse a recursive nodeset(depth unknown) in XSL ? say you have ?"
What i am trying to do is simply traverse the xml via xsl and creating xhtml out of it. However, the issue i have is, <xsl:for-each > works till just 1 level deep. How do i get recursive child nodes with the same name?

Any help is appreciated.

Thanks.
 
Henry Wong
author
Marshal
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aby Krishna wrote:I am not sure which is the right forum for a xsl related question (though still programming in Java).


Not sure what you mean by "still programming in Java". You are trying to use xsl to traverse the xml -- how is this not programming in xsl?

Henry
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to XML forum.
 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you process a document recursively in XSLT? Well, if you choose to use <xsl:for-each> then it's going to be difficult. What you should do instead is this:

(1) Create a template which matches <name> elements.

(2) Make sure it includes a call to <xsl:apply-templates>, so that it calls all templates that match its child nodes.

(3) Arrange it so that processing the root element also calls <xsl:apply-templates>, so that the <name> elements at the highest level are matched.

In general use <xsl:template match="X"> to process node X and <xsl:apply-templates> to process children of matched nodes. Forget about <xsl:for-each> and other procedural programming ideas in XSLT.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed-XSLT is more functional than people realize, and a lot of issues arise because of it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic