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:  

Using regular expressions through XSLT 2.0

How XSLT 2.0 will change your world

XSLT 2.0 is nearing release, and when it arrives and receives substantial processor support, your life will be a lot easier. The MindMap team has been getting a jump on things by looking over the early drafts of the XSLT 2.0 specification (see Resources).

XSLT 2.0 will take the hassle out of quite a few things that the MindMap team has found somewhat frustrating with XSLT 1.0, particularly string management. XSLT 2.0 provides support for regular expressions, which are a pattern-based method of searching for specific strings of text found in other languages with powerful string manipulation capabilities like Perl.

However, you shouldn't use XSLT 2.0 in a production environment quite yet. It's hard to say when the specification will be finalized, and it could still change substantially. The current working draft is in Last Call, which means this is the last opportunity for public comment, but this has been a slow-moving specification, so final delivery might not happen before the second half of 2004. After that, it will take some time for the language to mature and for XSLT processors to work out the bugs (and I expect plenty of them because the architecture of the language experienced some core changes, especially with regards to data typing).

So what do you need to experiment with XSLT 2.0 today? Saxon, an XSLT processor developed by Michael Kay, provides an immediate opportunity for testing basic features of XSLT 2.0 (see Resources for the latest version.)


Using regular expressions

The replace template that you saw earlier in the tutorial was a fairly simple one, but extremely complex string replacement routines require extremely complex templates. One of the requirements for XSLT 2.0 was to ease the pain in that area. In addition, reality has surfaced: Sites with huge traffic flows should avoid heavy XSLT processing anyway (and let a database do the work whenever it can), because XSLT has proven to be expensive on heavily trafficked sites. Whether XSLT 2.0 will change that remains to be seen, but clearly this statement is much easier to build than the template required in XSLT 1.0:

      <p>
         <xsl:value-of select="replace(., '(Host)', 'Machine')"/>
      </p>

The replace() function is new in XSLT 2.0, and takes three arguments:

  • The input string you want to base your search on
  • A regular expression to use for singling out the specific characters you want to replace
  • The text with which you wish to replace the characters in the second argument

8 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.