Sunday 12 April 2015

How you can show xml data online utilising XSL

XML is a mark-up language coded in plain text which you can use to show data in a absolutely consistent way and also as planned via the internet regardless of internet browser type or other hardware and software being used.

Nevertheless, it’s worth noting that XML by itself that is to say pure xml, is not cross browser compatible, to achieve this you could make use of xsl to convert your xml data into html.

XSL, short for xml stylesheet language, in this context it could be used to change xml files or data in text or html files or perhaps new xml documents.

In this short article, we are going to examine parsing our XML file by using the Microsoft DOM object, to really make the best us of many of the examples That means that you need to have it set up on your server. Just install the IE explorer and you will be ready to go.

To get going, the first thing you ought to do is start up the DOM project, the code is as follows;

<%

 set xml = Server.CreateObject("Microsoft.XMLDOM")

%>

With the DOM running, you now are ready to load the xml document into your dom, to make this happen you employ the coding call xml.load.

To pull your data from your own xml file, you simply need to list the immediate path to your file, whether or not it is on your hard disk or on a webserver, for instance mywebsite.co.uk/myxmlfile.xml or c:/mydocuments//myxmlfile.xml

Having filled your xml data in to the dom, you are now ready to design your xsl document, using xsl.

To help make HTML by using XSL you simply produce out the values of the XML in between the HTML. This is very much similar to using ASP to publish out the values from a database in between HTML tags. Only the syntax is different. For example, if you were to create a variable to a page making it bold in ASP it could appear like:

<b><%=yourVar%></b>

In XSL it would look like:

<b><xsl:value-of select="elementName"></b>

XSL is composed in XML so this means all the syntax rules apply - Case Sensitive, Quotes around all attributes (including HTML), and all of the elements must have an finishing element (including HTML). This means that if you use <br> you must use </br>.

OK, so we got the practical ability to generate the value of an element to a page. This specific capacity will be worthless up to the point we've got the capability to navigate the XML elements. For instance, if you decide to use <xsl:value-of select="title"> with no other code, you'd get an error (or a blank screen). The reason behind this is that XML will allow elements using the same name this mean different things to co-exist in a document (assuming they are positioned differently).

Which means you must stipulate the exact location of the element you are trying to print to the page. As an example, the following could well be proper and would likely write out the title value (assuming you performed the header correctly:

<xsl:value-of select="item/book/title">

You can easily note that this operates rather like a directory framework - it's important to acquire the proper directory to obtain the value.

No comments:

Post a Comment