Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Analyze with XSLT, Part 1: Analyze non-XML data with XSLT

Create string parsing routines to convert documents into XML elements

Chuck White (chuck@tumeric.net), XSLT consultant and Web engineer, Freelance Developer
Chuck White, a Studio B author, has been working with XML since before its official inception in February, 1998. He was co-author of Mastering XML Premium Edition (with Linda Burman and the W3C's XML Activity Lead, Liam Quin) and author of Mastering XSLT, both from Sybex Books. His latest books are Developing Killer Web Apps with Dreamweaver MX & C# (also for Sybex Books) and HTML, XHTML, and CSS Bible, 3rd Edition for Wiley, for which he is co-author with Steve Schafer. Chuck is currently working with the XSL Team at eBay as a project consultant and Web engineer.

Summary:  This tutorial explores how to create string parsing routines in XSLT so that you can tokenize straight, non-XML text, thus turning that text into a series of XML elements. Specifically, this tutorial examines how to convert such documents as weblogs and Web configuration files into XML for improved readability and programmatic access.

View more content in this series

Date:  16 Dec 2003
Level:  Introductory PDF:  A4 and Letter (106 KB | 28 pages)Get Adobe® Reader®

Activity:  6417 views
Comments:  

Summary and XSLT tricks of the trade

Summary: The MindMap team has only just begun

Actually, that's not true. The MindMap team really has gone deep into the processing power of XSLT, but you've only just begun to get a peek at what they're up to. For them, doing some string manipulation tasks was just the beginning. It was this encounter with XSLT that convinced them of the language's power, so it's only fitting that you start by taking a look at their earliest endeavors. Starting with a routine host configuration text file that consists of some data about the machines on their network, they've been able to convert it into an XML file. This gives them programmatic access to each host machine on different layers, depending on their needs.

You can do the same thing. If you're running a large Web site, for example, you can manage builds by writing configuration specs for specific branches of a source control system that refer to specific elements representing different machines.

In this tutorial, you've had just a cursory glimpse at how you can use XML as an analysis tool. You saw how the MindMap team set up a text file for analysis, and you were given an idea of what might come next in terms of examining the resulting XML's elements. In the next tutorial, you'll see how the MindMap team extends this concept much further as you explore XSLT as an analysis tool.

Next, I'll offer a couple of bonus XSLT tricks of the trade.


XSLT tricks of the trade

Remember that straight text-only files cannot be processed by an XSLT processor. This is because an XSLT processor works with an XML parser, which first looks at your input to be sure it is well-formed XML. The other thing to remember about your input string is that it may contain characters like < and >, or &. Don't wrap them in CDATA elements, a mistake I see frequently. (Okay, it's not really a mistake, it's just not good practice.) Get those things converted somehow. A good Perl interpreter is a handy thing to have, and if you're working on small-scale projects you can always use Emacs or a similar text processing program.

You can get pretty wild and crazy with parameters. In fact, you can come awfully close to mimicking the changing of variable values that many XSLT newbies automatically seek out when first experimenting with XSLT by cascading parameter values among recursive template calls. By changing the value of the string as it passes through each parameter (and let's be clear here: The string value is not actually passing through by a variable; the XSLT processor is simply reading a different part of the source tree depending on when a template is called -- XSLT is completely side-effect-free), you can manipulate strings and output what you want.

9 of 12 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138216
TutorialTitle=Analyze with XSLT, Part 1: Analyze non-XML data with XSLT
publish-date=12162003
author1-email=chuck@tumeric.net
author1-email-cc=dwxed@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.