XSLT: Transforming Your XML Data

xslt for dummies
Chapter 1 - Introducing the X-Team
XSLT For Dummies
by Richard Wagner
Hungry Minds 2002

The third member of the X-Team is XSL Transformations (XSLT). XSLT is analogous to that high-priced rookie on a professional sports team that unseats the veteran player: XSL was supposed to be the killer technology to enable XML to achieve widespread adoption, but XSLTs ability to convert XML data into any wanted output has proven so compelling that it essentially swallowed up XSL. In fact, when people today talk about XSL, theyre almost always referring to XSLT.

 Technical Stuff   XSL is actually composed of two independent parts : XSLT for transforming XML from one structure to another; and XSL Formatting Objects and Formatting Properties for formatting XML documents.

The key reason for all this enthusiasm in support of XSLT is that XML documents often need to serve multiple audiences. The XML needs to be formatted so that it can be viewed in a Web browser, and the same XML may need to be tweaked to conform to a new trading partners own XML structure. See Figure 1-3 for an illustration of this relationship.

Figure 1-3: XSLT transforms XML into a variety of outputs.

To illustrate , suppose that I want to change the XML definition of a customer from the original format of

 <customer> <id>101</id> <name>Rick Blaine</name> <city>Manchester</city> <state>NH</state> <zip>02522</zip> </customer> 

into this:

 <customer id="101"> <fullname>Rick Blaine</fullname> <address city="Manchester" state="NH" zipcode="02522"/> </customer> 

Before XSLT came along, Id have to dust off my programming software, bury myself in a cave for a day, and write a program to do this migration process. However, with XSLT, I can transform the data from one XML format to another nearly instantly, with no true programming required.

 Tip   XSLT is not a programming language as such. In fact, when written out, it doesnt even look anything like C++, Java, or Visual Basic. Like its XSL parent, XSLT rules and templates are defined by using XML.

Most programming languages transform data structures through blood, sweat, and tears. In contrast, XSLT does this work in what can best be described as transforming by example you provide an example of what kind of information youd like to see, and XSLT does the rest. For example, the following XSLT snippet changes the name element to fullname in the output document.

 <xsl:template match="name"> <fullname> <xsl:apply-templates/> </fullname> </xsl:template> 

(I get into the specifics of how XSLT template rules work in Chapter 4.)

However, as powerful as XSLT is, it needs help to do its transformational magic from our last X-Team member: XPath. XPath specializes in picking out the specific nuggets of information from one XML document in order for XSLT to fit it neatly into another one.

2000-2002    Feedback

XSLT For Dummies
XSLT for Dummies
ISBN: 0764536516
EAN: 2147483647
Year: 2002
Pages: 148

Similar book on Amazon

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