O'Reilly logo

Dreamweaver CS5: The Missing Manual by David Sawyer McFarland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Advanced XSLT Tricks

XSLT is a complex language with lots of bells and whistles—and just as many pitfalls. It’s all too easy to head ambitiously into Code view and, with just a few keystrokes, completely break your XSLT style sheet. But since Dreamweaver’s XSLT tools take you only so far, you’ll undoubtedly find yourself wanting to dip into the code. Here are a couple of examples to help your explorations go a little more smoothly.

Sorting Data in a Repeat Region

The Repeat Region feature normally works by spitting out data it retrieves from an XML document in the order it appears in the XML file. In the case of an RSS feed, that’s usually OK, since RSS feed usually sort items in chronological order, with the most recent feed first. But what if you want information sorted another way, or you have an XML file with other kinds of data, like the employee listing on Inserting a Repeat Region? In that example, you might want employees listed in alphabetical order. Dreamweaver doesn’t have a tool that lets you do this. Fortunately, adding the code yourself is pretty easy:

  1. Click inside a repeat region and then click the “Code” or “Split” button in the document window’s toolbar.

    Alternatively, you can choose View→Code or View→“Code and Design”. Doing so drops you into the scary world of XSLT code.

  2. Locate the beginning of the repeat region.

    You’re looking for something like this: <xsl:for-each select="company-Info/employeeList/employee">, where the stuff in quotes after “select” is the XPath expression ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required