Transformation and Remote Object Access

Creating structured documents and providing a means to link to and from them gives developers a wide range of abilities. However, structures are not always in a format you can process, and the method in which you transmit this data could be inconsistent with other enterprises. These are common issues that arise when implementing XML-based solutions and they need to be addressed for compatibility and flexibility reasons.

In the following two subsections we will cover a few standards, such as XSLT and SOAP, that help ease the pain these situations present. These are both complete, in W3C standards terms, and you will find applications already leveraging their power.

Extensible Stylesheet Language Transformations

XSLT, which we have covered in part in earlier chapters, is a language that allows you to transform one document schema into another. This is tremendously powerful when you use XML in the enterprise because it allows you to accept various documents structures, by transforming them into a structure that you natively support. The process is simple. Accept another document structure, apply the appropriate XSLT style sheet, and transform the document into a schema you can utilize in your processing.

XSLT is a useful approach for transforming your content markup so you can publish to multiple devices. If you define your content within an XML language, applying an XSLT style sheet to transform the document into XHTML, WML, or any other device-specific markup or other text format is easy. This allows you to create content once and, through the application of transformations, publish it anywhere.

The best way to learn and understand XSLT is through an example. Suppose we want to take the structured-valid.xml document we created earlier and transform it into valid XHTML. Let's rename it structured-trans.xml so as not to get confused. To do this we will not only need to include the header and body elements of the document (<html>, <head>, <body>, and so forth.), but we must also transform our <entry>, <company>, and <name> elements into valid XHTML elements. As a refresher, here is Listing A-10, our structured-trans.xml document:

Listing A-10 structured-trans.xml: An instance document of our entry.dtd schema.

 <?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE entry SYSTEM "entry.dtd"> <entry type = "employee"> <company> <name>Some Company, Inc</name> </company> <name>Allen Wyke</name> </entry> 

Once the input document has been created we must create an XSLT file that contains the appropriate mapping from our data model defined in entry.dtd to XHTML. For this example we will include the company name in the <title> as well as in the <body> of our document. The body of the document will include a <p> element with our transformed text. Listing A-11 is our XSLT document.

Listing A-11 transform.xsl: The transformation document.

 <?xml version="1.0"?> <xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title><xsl:value-of select="//entry/company/name"/></title> </head> <body> <h1>User Information</h1> <p> <strong> Company Name: </strong> <xsl:value-of select="//entry/company/name"/> <br /> <strong> Employee Name: </strong> <xsl:value-of select="//entry/name"/> </p> </body> </html> </xsl:template> </xsl:stylesheet> 

If you take a close look at this style sheet you will notice it`s fairly simple. The <xsl:value-of> element is used to specify the element, including structure, that you are referencing. For instance, in the <title> element the style sheet basically says that the <name> child element of the <company> element, which itself is a child element of <entry>, should be contained between the beginning and ending <title> elements.

Once the style sheet has been defined, all you have to do, assuming the XSLT style sheet is in the same directory, is include the following line in your structured-trans.xml document just under the <?xml version = "1.0" encoding = "UTF-8"?> declaration. This tells the parser that when the structured-trans.xml document is loaded it should apply the transform.xsl style sheet while processing.

 <?xml-stylesheet type="text/xsl" href="transform.xsl"?> 

If we load the structured-trans.xml example in Microsoft Internet Explorer (with MSXML version 3 or later) you should see something like Figure A-2.

Figure A-2 Results of applying our transformation to structured-trans.xml and creating an XHTML document.

The topic of XSLT, as you might imagine, is much broader than this simple example. We used XSLT in several of our chapter projects, so refer to them for details.

If you want more information on the XSLT Recommendation, check out http://www.w3.org/TR/xslt.

The Simple Object Access Protocol

SOAP is a protocol for exchanging data in truly distributed and decentralized networks. It not only contains information on how to process its payload, but also a set of encoding rules for expression instances of application-defined datatypes and a procedure for representing remote procedure calls and the return of the results. We like to think of SOAP as the United Parcel Service of digital data. It not only contains the data, but also the instructions for what to do with it and how to return the results of any processing that occurred.

Because SOAP is a major component of Microsoft's .NET initiative, we dedicated all of Chapter 14 to covering it and how it works. If you are hungry for more information on SOAP, you can read up on the most recent version standard at http://www.w3.org/TR/SOAP.



XML Programming
XML Programming Bible
ISBN: 0764538292
EAN: 2147483647
Year: 2002
Pages: 134

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