Board logo

subject: The Beginners Guide To Utilizing Xslt [print this page]


XSLT stands for extensible stylesheet language transformations, and it is an tremendously supple and beneficial solution that claims many advantages especially when applied to tackle the suitable dilemmas.

To be able to get you started, all you need is the correct overview to the essence of XSLT to allow you get started out, and once you do, you undoubtedly wont look back, it will absolutely turn into one of the most useful tools in your programming tool bet.

And so why ought to an individual use XSLT and what can it do? In very basic terms, XSLT is a transformation dependent formatter which will allow you to transform structured XML documents straight into several other output formats, for example into HTML or CSV and so on.

For the purposes of this post we are going to peek at the potential of XSLT to change or alter XML records into HTML. We are going to use an XML file to illustrate the attributes of a product (e.g. the Name, Short Description, Long Description, Downloads, Licensing Options, System Requirements, etc.) and a series of XSLT files to display them.

Right, firstly lets make our own extremely uncomplicated XML document for a product, and you can construct it up from there. Just for the time being, all we will deal with is the product title, version, and short description. You can certainly add more later on should you feel brave enough.

[product code="Spt001"]

[title]htmltrans[/title]

[version]2.0[/version]

[short_desc]

The product spt001 enables transformation of regular text to html and vice versa

[/short_desc]

[/product]

So thats our basic XML document all set up, now were definitely all set to work with XSLT and carry out some standard functions

Now that we have got the essential XML document set up, let's look at what we are able to do through XSLT.

XSLT, just like nearly all other XML-based formats, is rather fastidious about its structure. Your simple XSLT document looks like this:

[?xml version="1.0" encoding="UTF-8" ?]

[xsl:stylesheet

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"]

[xsl:output method="html" /]

[xsl:template match="/"]

Rules go in here...

[/xsl:template]

[/xsl:stylesheet]

So the above example is a rather basic and common xslt file, anyone can observe we have declared the XSLT stylesheet and version. In the fourth line we have also informed the parser to output the result as HTML.

Observe we also have got a xsl:template element declared in the 5th row.

Bear in mind that XSLT is a rules-based language, so in accordance with the regulations, the parser will go through the xml file and apply the appropriate rules(template) to the relevant elements (the match).

Okay, that is it for now, as promised, we dealt with the basics of XSLT, as a result now you will be able to make your own file and produce the contents of an HTML file.

I should in addition point out that one of the primary strong points of XSLT is the capability to generate multiple views on the same xml file. For instance, a single product.xml file that stores the product information, downloads, screenshots, and more may be utilized for a product summary page, the downloads list, a screenshot gallery, and more. The principal benefit of this strategy is that adding or adjusting a product would not necessarily mean any presentation changes--only data ones, which is a sizable gain and certainly time and cost saving for any company.

by: John Hargreaves




welcome to loan (http://www.yloan.com/) Powered by Discuz! 5.5.0