Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How-to break a for-each loop in XSLT?

Tags:

How-to break a for-each loop in XSLT?

like image 828
Daniel Silveira Avatar asked Jan 22 '09 17:01

Daniel Silveira


People also ask

How do you break for-each in XSLT?

There is no such a thing as break in an XSLT for-each loop. xsl:if/@test is pretty much all you can do. The other way would be to include this condition within the for-each/@select.

What is Number () in XSLT?

Definition and Usage The <xsl:number> element is used to determine the integer position of the current node in the source. It is also used to format a number.

How do you write a while loop in XSLT?

You can format your XSLT stylesheet to go to a specific node, and then loop through the given node set. You create an XSLT loop with the <xsl:for-each> tag. The value of the select attribute in this tag is an XPath expression that allows you to specify the data element to loop through.

How do I change the value of a variable in XSLT?

Variables in XSLT are not really variables, as their values cannot be changed. They resemble constants from conventional programming languages. The only way in which a variable can be changed is by declaring it inside a for-each loop, in which case its value will be updated for every iteration.


1 Answers

XSLT is written in a very functional style, and in this style there is no equivalent of a break statement. What you can do is something like this:

<xsl:for-each select="...nodes...">     <xsl:if test="...some condition...">         ...body of loop...     </xsl:if> </xsl:for-each> 

That way the for-each will still iterate through all the nodes, but the body of the loop will only be executed if the condition is true.

like image 199
Greg Hewgill Avatar answered Oct 27 '22 03:10

Greg Hewgill