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 , an independent computer training company offering at their central London training centre.
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 in London and throughout the UK.
Extensible Markup Language (XML) is a specification by the Worldwide Web Consortium (W3C) for creating markup languages such as XHTML. The XML specification is being used in an increasingly wide range of applications for exchanging data between different environments, platforms and media. One of the main reasons for its rapidly growing popularity is its flexibility. It allows developers to define their own hierarchy of tags which reflect the structure of their data. In addition to the core XML specification, a number of other technologies have been developed for working with XML projects.
XML Schema
Closely linked with XML documents, we have XML schema. XML schema documents and schema languages are used to validate and document XML markup languages. They allow developers to explicitly lay down the syntactical and structural ground rules for particular classes of XML documents. A number of schema languages have been developed but perhaps the two most important are those defined by the W3C: Document Type Definition (DTD) which was built into the original XML specification and the more XML schema language developed a few years later.
XSL, XSLT AND XSL-FO
XML also offers technologies for transforming XML documents. Extensible Stylesheet language (XSL) comprises two parts: XSL Transformations (XSLT) and XSL Formatting Objects (XSL-FO). XSLT stylesheets are essentially XML documents which transform a given class of XML document (referred to as the source tree) into a different class of XML document (referred to as the output tree). XSLT documents can be compared to CSS documents but are much more powerful. XSL-FO documents are written in XML and control the formatting layout in an output document in a very detailed manner. It allows the definition of layout masters from which are derived page sequences for generating the final document pages. Flow objects are then used to bind data to the various regions of pages.
XPath, XLink, XPointer and XQuery
XPath, XML Linking Language (XLink), and XML Pointer Language (XPointer) are all provide solutions for linking and addressing when working with XML documents. XPath is a declarative language which uses expressions that resemble the directory paths used to describe locations in computer file systems. XPath expressions are used in XSLT documents to address specific nodes within the hierarchy of the XML source document.
XLink is essentially a method of creating hyperlinks within XML documents. It overcomes some of the limitations of the hyperlinks used in XHTML, such as the fact that each hyperlink has only one source and one destination. XPointer allows you to create links which point to very specific points within the hierarchy of an XML document by including XPath expressions in its syntax. XQuery is designed to query XML data in much the same way that SQL is used to query databases. It uses XPath expressions to extract elements and attributes within the structure of an XML document.
Author is a developer and trainer with , a UK IT training company offering in London and throughout the UK.