‘sgml’ Tagged Posts

Using Looping Syntax In XSLT

Extensible Stylesheet Language (XSL) is an XML-related technology which is used to transform XML data. XML file are used to set the ground-rules for...

 

Extensible Stylesheet Language (XSL) is an XML-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. XSL 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 XML file.

When displaying XML 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 elements in an XML file is the the “For-each” element. This requires the “select” attribute to specify which element is to be used in the loop. The “For-each” element normally requires both an opening and a closing tag and any lines of markup 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 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, within each company element, we have a “name”, “telephone” and “website” element. Before beginning 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 output an HTML “li” element and, between the opening and closing tag, output the contents of the “name” and “telephone” elements from the XML file. The data in the “website” could 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.

The author is a training consultant with Macresource Computer Training, an independent computer training company offering XML, XSLT, XPATH, XQuery and XSL-FO training courses at their central London training centre.

XML Offers Neutral And Platform Independent Encapsulation Of Your Data

 

Extensible Mark-up Language (XML) has quickly established itself as a viable technology with a huge range of real-world applications. One of the key reasons for its importance and wide acceptance is that it offers a working solution to one of the key problems faced by software developers and computer users alike: the exchange of incompatible data. Each software environment produces its own unique type of binary file which only it can understand. Once data is exported in XML format, it becomes a known quantity, independent of the environment in which it was originated.

The PDF format is another example of a platform-independent format which has gained worldwide acceptance. Once a document is saved in PDF format, its format is set in stone, it can viewed and printed with its layout and formatting intact, without the need for the software which created the original document. However, where the PDF format concerns itself mainly with the presentation of information, XML is used to describe and encapsulate the information itself.

Though XML itself is still fairly new, the idea behind is over thirty years old. In the 1970s, Standard Generalized Markup Language (SGML) was developed in an attempt to create an application-independent method of describing and storing data. SGML is a text-based language which relies on the concept of adding mark-up to data which describes the data itself. An SGML document contains both the original data and a lexicon of rules defining the structure of that data. SGML is a fairly complex language and, unlike XML, has never gained wide popularity. In the early 1990s, SGML was used to develop and specify the rules of HyperText Markup Language (HTML) and in the late 1990s, SGML was again called upon, this time as the basis for the creation of XML. In a lot of ways XML is basically a restricted form of SGML.

XML has already proved itself an excellent medium for storing, describing and transporting data, particularly over the web. It offers flexibility, clarity and simplicity. An XML document looks similar to an HTML document and consists of the same human-readable tags. However, the tags used to markup an HTML document are pre-defined: only a limited set of tags can legitimately be used. XML allows you to create a markup language and define the tags which are legitimate for your data. It does this using a schema document, which can itself be an XML document. The schema document specifies the vocabulary and grammar which may be used within the XML document which contains your data.

The fact that, when creating and generating XML documents, you can invent all the rules, means that you never have to force your data into a container which was not designed to hold it. You design tags which reflect the nature of your data; you create a schema document which defines the hierarchical structure of your information; and you specify the type of information each element within your document is permitted to contain. In short, if you end up with an XML documents which is unsuitable for holding your information, you have only yourself to blame!

Author’s company runs public courses in web design 3.5 in London and throughout the UK.