Understanding The For-each Element In XSLT
Extensible Stylesheet Language (XSL) is an XML technology which is used to transform XML data. XML file can be used to set the ground-rules for a gi...
Extensible Stylesheet Language (XSL) is an XML technology which is used to transform XML data. XML file can be used to set the ground-rules for a given body of data and to describe the data itself. XSL allows us to take that input XML data and convert it into information which can be displayed in a web browser window or opened with a text editor. It can also be used to create an XML file which is a modified version of an input XML file.
When displaying elements in a browser window, the XSL elements which enable looping through an XML tree and decision-making really come into their own. One of the key methods used in XSL for looping through XML elements is the “For-each” element. This uses the “select” attribute to specify which element is to be targeted in the loop. The “For-each” element has both an opening and a closing tag and any lines of code placed between the opening and closing tags will be repeated each time the element specified in the “select” attribute is encountered in the XML file.
For example, let’s say we have an input XML file containing a list of companies and the addresses of their websites. Let’s also say that the element which we will be targeting in the XSL “For-each” statement is called “company” and that, for each company element, we have a “name”, “telephone” and “website” element. Before beginning our “For-each” loop, we could output the opening tag of an HTML “ul” element (an unordered or bulleted list).
Inside the “For-each” loop, we could output an HTML “li” element and, between its opening and closing tags, output the contents of the “name” and “telephone” elements from the XML file. The data in the “website” element in the input XML could be used to convert the “name” into a clickable link.
As to the appearance of the data in the resulting HTML output, this would be controlled by a linked CSS file. CSS can be used to format the output in any way we desire, so our bulleted list can take on pretty much any appearance we desire.
The The writer of this article is a trainer and developer with , an independent computer training company offering in London and throughout the UK.
Related posts:
- XML And The Benefits Of Platform Independence Extensible Mark-up Language (XML) has very quickly established itself as...
- Overview of XML Technologies Core XML...
- Working With HTML and XHTML in Adobe Dreamweaver CS4 HTML is a markup language used to create web pages...
- Validation XML Files With XML Schema XML schema definition languages are derived from the recommendations of...
- Understanding The ASP.NET GridView Control The display of information from a database is a fairly...
Related posts brought to you by Yet Another Related Posts Plugin.