File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XSL problem 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 "XSL problem" Watch "XSL problem" New topic
Author

XSL problem

Aby Krishna
Greenhorn

Joined: Jul 10, 2010
Posts: 14
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
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Moving to XML forum.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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

Joined: Sep 29, 2008
Posts: 12617

Agreed-XSLT is more functional than people realize, and a lot of issues arise because of it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSL problem