Iteration Using For-each In XSLT
Extensible Stylesheet Language (XSL) is a related technology which is used to transform XML data. XML file are used to set the ground-rules for a given body of data and to describe the data itself. It allows us to take that 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 original data file.
When displaying elements in a browser window, the elements which allow us to loop through an XML tree and carry out decision-making really come into their own. One of the key methods used for looping through all occurrences of a given XML element is the "For-each" element. This uses the "select" attribute to specify which element is to be used in the loop. The "For-each" element uses 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, suppose we have a file containing a list of companies and the addresses of their websites. Suppose, as well, that the element which we will be targeting in the "For-each" statement is called "company" and that, within each company element, we have a "name", "telephone" and "website" element. Before starting our "For-each" loop, we could place the opening tag of an HTML "ul" element (an unordered or bulleted list).
Inside the "For-each" loop, we could then output an HTML "li" element and, between the opening and closing "li" tags, output the contents of the "name" and "telephone" elements from the XML file. The data in the "website" could then be used to convert the "name" into a clickable link.
As for 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 like, so our bulleted list can take on pretty much any appearance we desire.
When displaying elements in a browser window, the elements which allow us to loop through an XML tree and carry out decision-making really come into their own. One of the key methods used for looping through all occurrences of a given XML element is the "For-each" element. This uses the "select" attribute to specify which element is to be used in the loop. The "For-each" element uses 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, suppose we have a file containing a list of companies and the addresses of their websites. Suppose, as well, that the element which we will be targeting in the "For-each" statement is called "company" and that, within each company element, we have a "name", "telephone" and "website" element. Before starting our "For-each" loop, we could place the opening tag of an HTML "ul" element (an unordered or bulleted list).
Inside the "For-each" loop, we could then output an HTML "li" element and, between the opening and closing "li" tags, output the contents of the "name" and "telephone" elements from the XML file. The data in the "website" could then be used to convert the "name" into a clickable link.
As for 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 like, so our bulleted list can take on pretty much any appearance we desire.
About the Author:
If you would like to learn more about InDesign JavaScript and XML scripting training courses, visit Macresource Computer Training, a UK IT training company offering InDesign JavaScript and XML scripting training courses at their central London training centre.
You are receiving this because you signed up for it on 2011-10-03 from IP 203.109.66.181
To fine-tune your selection of which articles to receive, just login here
using your username:
To unsubscribe please use the following link:
Unsubscribe
No comments:
Post a Comment