Combining the XML DOM and XSL

XSL can be used to transform XML documents into HTML web pages. XSL allows format definitions, data filtering, manipulation, sorting, and use of output template definitions. Templates can be used to display the XML document (or parts thereof) in specific ways. Multiple templates can even be used to display separate parts and subsets of an XML document in different ways. It is also possible to combine the adaptability of the XML DOM, and the formatting capabilities of XSL to produce more flexibility in the application of XML document data. This section covers a simple example just to demonstrate .

All files are stored on the server side in a web server computer called sql2000server.

The term server side implies the back-end servers. When you connect over the Internet to a web site, your computer connects to other computers. Those other computers are servers of one type or another, and can be web servers ( servicing the web), database servers (providing database access), or other types of servers. The computer you use to connect to the Internet, running a browser, is known as a client- side computer.

There is an XML document ( population.xml ), an XSL style sheet ( population.xsl ), and an ASP script ( population.asp ). This is the XML document:

   <?xml version="1.0"?> <?xml:stylesheet type="text/xsl" href="population.xsl" ?>  <populationInThousands>    <world>       <areas>          <area region="Global">             <years>                <year time="1998">5,901,054</year>                <year time="2025">7,823,703</year>                <year time="2050">8,909,095</year>             </years>          </area>          <area region="FirstWorld">             <years>                <year time="1998">1,182,184</year>                <year time="2025">1,214,890</year>                <year time="2050">1,155,403</year>             </years>          </area>          <area region="Second World">             <years>                <year time="1998">4,718,869</year>                <year time="2025">6,608,813</year>                <year time="2050">7,753,693</year>             </years>          </area>          <area region="Third World">             <years>                <year time="1998">614,919</year>                <year time="2025">1,092,623</year>                <year time="2050">1,494,925</year>             </years>          </area>       </areas>    </world> </populationInThousands>   

Next is the XSL style sheet script, as applied to the preceding XML document:

   <?xml version="1.0"?> <HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <HEAD><TITLE>Regional Global Population in Thousands</TITLE></HEAD> <BODY> <CENTER><FORM><TABLE CELLPADDING="5" CELLSPACING="1" BORDER="1"> <TH BGCOLOR="silver">Region</TH><TH BGCOLOR="silver">1998</TH> <TH BGCOLOR="silver">2025</TH><TH BGCOLOR="silver">2050</TH> <xsl:for-each select="populationInThousands/world/areas/area"><TR>    <TD><xsl:value-of select="@region"/></TD>    <xsl:for-each select="years/year">    <TD>       <xsl:element name="INPUT">       <xsl:attribute name="TYPE">text</xsl:attribute>       <xsl:attribute name="NAME"><xsl:value-of select="@time"/></xsl:attribute>       <xsl:attribute name="VALUE"><xsl:value-of select="."/></xsl:attribute>       <xsl:attribute name="SIZE">10</xsl:attribute>       </xsl:element>    </TD>    </xsl:for-each></TR> </xsl:for-each> </TABLE></FORM></CENTER></BODY></HTML>   

Finally, there is a server side using Active Server Pages (ASP) and VBScript (a Microsoft counterpart to JavaScript). ASP is a scripting language that executes on a server, and thus has direct access to everything on that server and everything that server has access to. For obvious security reasons, end users running an application through a browser over the Internet do not have direct access to database servers and web servers in general. End- user access is strictly controlled, particularly for OLTP databases. The controlling software is often custom-written application code.

   <% @LANGUAGE = VBScript %> <% Option Explicit %> <HTML><HEAD><TITLE>The XML DOM and XSL</TITLE></HEAD> <BODY BGCOLOR="#FFFFFF"> <%    Dim XMLDoc, XSLDoc    Set XMLDoc = Server.CreateObject ("Microsoft.XMLDOM")    Set XSLDoc = Server.CreateObject ("Microsoft.XMLDOM")    XMLDoc.async = false    XMLDoc.load (Server.MapPath("population.xml"))    XSLDoc.async = false    XSLDoc.load (Server.MapPath("population.xsl"))    Response.Write (XMLDoc.transformNode (XSLDoc))  %> </BODY></HTML>   

Figure 3-14 shows the result of the preceding script.

image from book
Figure 3-14: Applying XSL to the XML DOM, using ASP on a web server


Beginning XML Databases
Beginning XML Databases (Wrox Beginning Guides)
ISBN: 0471791202
EAN: 2147483647
Year: 2006
Pages: 183
Authors: Gavin Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net