BYTE.com > Tangled in the Threads > 2002 > April
XSLT Explorations
By Jon Udell
April 1, 2002
(XSLT Explorations
: Page 1 of 1 )
The Protean Power of Textual Transformation
When I started developing for the Web, I was astonished to see how easily I could conjure applications seemingly out of thin air, by transforming patterns of text into other patterns of text. I'm still amazed by this phenomenon, though perhaps it shouldn't be so surprising. Life itself springs from a textual data structure (DNA), which transformative processes turn into other textual data structures (proteins). A programming language designed expressly to transform structured text is therefore, by definition, a really powerful tool. So despite my reservations about Extensible Stylesheet Transformations (XSLT), which to my mind awkwardly straddles the worlds of procedural and declarative programming, I find myself using it more and more often for things I used to do in parser-equipped scripting languages such as Perl or Python.
In his End Tag column for XML Magazine, Adam Bosworth former Microsoft XML evangelist and now BEA Systems' VP of Engineering called for a post-XSLT solution:
We need a language that can natively support XML as a data type and yet can gracefully integrate with the world of objects (Java or otherwise) and can take advantage of the self-describing nature of XML by supporting querying of its own variables. This language as used by humans will look like a programming language, not an XML grammar.
This sounds good to me. But I lack the imagination to see clearly what that language should be. If it's going to exist, we'll have to bootstrap our way into it. Using XSLT for all it's worth is probably the best way to do that. In that spirit, here are some things I've done lately with XSLT, and some reflections on doing them.
The Muench Method Is the Schwartzian Transform of XSLT
I recently had to transform a dataset like this:
<recordset>
<record>
<id>153</id>
<label>USA</label>
</record>
<record>
<id>155</id>
<label>USA
</label>
</record>
<record>
<id>156</id>
<label>VENEZUELA</label>
</record>
</recordset>
Into this result:
USA 2
VENEZUELA 1
Here is the XSLT solution:
<?xml version="1.0
Page 1 of 1
BYTE.com > Tangled in the Threads > 2002 > April
|