Transform And Display

A common task when working with XML documents is to transform an XML document with an XSL Transform document (also referred to as a XSLT style sheet or document). The XSLT document has information about how to format the data contained in the XML document. The XSLT document is described in XML like syntax. The specification for how to properly write an XSLT document can be found from the World Wide Web Consortium (

The purpose of doing transformations is to either create a new XML data source, format XML into a presentation markup language like HTML (HyperText Markup Language) or WML (Wireless Markup Language), or to do both. The xml server control <ASP:XML> makes performing transformations simple. To work with the xml control, you need to create a server form on an ASP.NET Web page. You must set two important attributes on the control. The first, documentsource, specifies the location of the XML document;the second, transformsource, indicates the location of the XSLT document. Add an id attribute and give the control a unique name so that you can work with the control in code.


% Untitled Notepad

File Edit Foimat Help




igoal>Travel to all seven continents</goal>

cgoal>Travel to Asia, including Japan and China</goal>

igoal>Travel to Europe, including England. France, Spain, and ltaly</goal>

igoal>Travel to all 50 US states</goal>

¿goal>Go to all the US National Parks </goal>

igoal>Walk across the Golden Gate bridge</goal>

?goal>Tourthe United States in a motor home</goal>

igoal>Climb Half-Dome at Yosemite National Park</goal>

igoal>Hike the Grand Canyon</goal>

igoal>Climb Mount Everest</goal>

igoal>Watch the sunrise from the top of Mount Fuji</goal>

igoal>Walk on the Great Wall of China</goal>

=goal>Run with the bulls at Pamplona</goal>

igoal>Drink a Guinness in an Irish pub </goal>

cgoal>Take a tour of London in a double-decker bus</goal>

=goal>Visit the Louvre and see the Mona Lisa</goal>

igoal>Attend Christmas mass at the Vatican</goal>

cgoal>Climb to the top of the Eiffel Tower</goal>

D Open and review the XML document that you want to transform.

% Untitled Notepad

File Edit Foimat Help

<xsl:stylesheetversion="1.0" xmlns:xsl-' «xsitemplate match-7goals">

<xsl apply-templates select-'goal-categoiy"h </xsl:template>

«xsitemplate match-'goal-category"-<P=>

<xsl element name-'H3">

<xsl.attribute name-'name"><xsl.value-of select-'name'

<xsl value-of select-'name" l> </xsl.element>

<xsl.apply-templates select-'goal'/> </xsl:template> <xsl:template match="goal">

0 Open and review the style sheet that is going to be used for the transformation.


You can do transformations programmatically. This gives you a chance to ensure that the transformation executes without errors. The following code transforms an XML document using a style sheet.


<%@ Import Namespace="System.xml" %>

<%@ Import Namespace="System.xml.xsl" %>

<SCRIPT LANGUAGE="C#" RUNAT="Server"> void Page_Load(Object sender, EventArgs e) {

XmlDocument xmldocumentGoals = new XmlDocument(); xmldocumentGoals.Load(Server.MapPath("goals.xml")); XslTransform xsltransformGoals = new XslTransform(); xsltransformGoals.Load(Server.MapPath("goals.xsl")); xmlGoals.Documant = xmldocumentGoals; xmlGoals.Transform = xsltransformGoals;

<FONT FACE="Verdana"> <FORM RUNAT="Server"> <ASP:XML ID="xmlGoals"

RUNAT="Server" />



This produces an HTML page that is a result of transforming goals in an XML document to HTML.

^ http://localhostyASPXML.aspK - Microsoft Internet Explorer

File Edit View Favorites Tools Help

0 Open

GenericTemplate.aspx from the Code Templates directory.

Q Add an <ASP:XML> tag and set its document source equal to the filename of the style sheet and the transform source equal to the XML document.

^ http://localhostyASPXML.aspK - Microsoft Internet Explorer

File Edit View Favorites Tools Help

4 Search Hfr | Favorites s http://localhost/AS PXML.aspx


Travel to all seven continents Travel to Asia, including Japan and China Travel to Europe, including England, France, Spain, arid Italy Travel to all 50 US states Go to all the US National Parks Walk across the Golden Gate bridge Tour the United States In a motor home Climb Half-Dome at Yosemlte National Park Hike the Grand Canyon Climb Mount Everest

Watch the sunrise from the top of Mount Fuj Walk on the Great Wall of China Run with the bulls at Pamplona Drink a Guinness In an Irish pub Take a tour of London in a double-decker bus Visit the Louvre and see the Mona Lisa Attend Christmas mass at the Vatican

0 Save the file and request the file from the Web server.

■ The XML document is transformed and output as HTML to the Web browser.




Web Services are units of application logic that provide data and services to other applications. Web Services are the next generation for programming Internet-based applications. Web Services combine the best aspects of component-based development and the Web. Applications can access Web Services through standard protocols and data formats like HTTP, XML, and SOAP.

ASP.NET Web Services provide the simplest way to implement Web Services. ASP.NET Web Services automatically generate Web Services Description Language, WSDL, and Web Services Discovery, Disco, files for your Web Services. You can use ASP.NET Web Services to implement a Web Service listener that accesses a business façade implemented as a managed class using any compliant .NET language. The .NET Framework SDK also provides tools to generate proxy classes that client applications can use to access Web Services.

A Web Service interface is defined strictly in terms of the messages the Web Service accepts and generates. In ASP.NET, Web Services are implemented with Web Methods that have input parameters and a return value. Consumers of ASP.NET Web Services can be implemented on any platform in any programming language, as long as they can create and consume the messages defined for the Web Service interface.


Web Services enable you to expose business logic and data over the internet. The protocols for accessing Web Services are open standards which make them available for consumption or production by any platform.

One of the large benefits of Web Services is the ability to pull data or apply business logic from many disparate systems and roll them into one application. For example, you can have a Web Service Client that accesses data from several servers' Web Services. This is advantageous for rolling up several data sources in your organization or for combining Web Services from different companies to create an application that leverages the "best in breed" in services that are provided on the Web.

As seen in the diagram, a user's browser can access a Web server's data in one of two ways. One way is the traditional way via an Active Server Page (ASPX) which is a presentation layer that can connect to business services that obtain data from a SQL data store. The other way is by accessing Web Services through a Web Service Client that has the potential to access one to many Web Services on one to many Web servers. This provides new capabilities in distributed computing.

Another benefit to Web Services is security. Exposing Web Services over HTTP, where the communication port can be explicitly set, allows for better control over security. The security issues are easier to control than Distributed Component Object Model (DCOM) access, which is over the range of ports that are allocated for Remote Procedure Calls (RPC). Also, for HTTP access over a single port, there are many well-established products that can provide control over port access and HTTP commands in packets.



Web Browser


Web Server zT



Web Server

Web Service Client


Listener t *

Business Facade Layer

Data Access Layer


Web Service High Level Architecture


ASP.NET Web Services support service requests using SOAP over HTTP, as well as HTTP GET or POST.

The use of XML is central to the architecture of the .NET Platform, and Web Services is no exception. The most feature-rich access is through Simple Object Access Protocol (SOAP). SOAP is a lightweight XML protocol that defines the two way communication that occurs between Web Service Clients and Servers. For Microsoft-based Web Services, the SOAP specification defines a set of rules for how to use XML to represent data, define message envelops — requests and responses — bindings to the HTTP protocol, and RPC over HTTP.

Although SOAP is the preferred way to access Web Services, you can also easily access a Service with an HTTP GET or POST. With the HTTP GET, you call a Web Service with parameters by providing a URL with a query string that holds the parameters. For example, you can call the Web Service with the following URL, http://server/ WebService.asmx/ WebMethod?name=value. Where server is the Web server path to the where the Web Service is located, WebService.asmx is the Web Services file, WebMethod is the desired Web Method on the Web Service, and ?name=value is the parameter for the Web Method.

Was this article helpful?

0 0

Post a comment