Re: [xsl] possible nested loops

Subject: Re: [xsl] possible nested loops
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Wed, 15 Feb 2006 09:38:42 +1100
garry@xxxxxxxxxxxxxxxxxxx wrote:

I wonder if someone could point me in the right direction to solve my
problem. I need to transform an xml file to html. I have tried to make a
stylesheet but none of my efforts have been successful.
The xml has around 800 pupil records (<pupil>) so I want to iterate over
each pupil node. Within each pupil node there are other nodes which
repeat, so for each pupil I need to iterate over child nodes of which
there may be none or many of each type. I suspect a nested loop of some
sort may help but I have not been able to implement one, any ideas?

It would help if we had a copy of your stylesheet (at least of what you have done) and some more information on the xml. ie an example snippet. By the language you are using, I suspect you have a fundamental lack of understanding of how XSLT works. There is no real concept of "iteration" in XSLT. Instead, what you do is use a template to find a match and do some action to this matching node. This action may include selecting values, storing values in a variable for later use, processing then selecting values or processing each child node or calling another template to process each child node. There are probably other operations that I have not included, but for simple conversion to HTML, this is probably only things you need to worry about. Have another look at some tutorials (the w3cschool tutorials are good for beginners). Pay close attention to <xsl:attribute>, <xsl:for-each> and <xsl:apply-templates>, I suspect that this is all you require to do what you need (assuming your data is well strucutred).



Current Thread