FGOTO: Easy way to overcome DXL-XSLT pitfalls with namespacing
I recently whined about what I perceived to be a flaw in the NotesXSLTransformer class. Well, tonight I found an excuse to use the new FGOTO ("firm grasp of the obvious") tag I proposed.
The reason I've been so dissatisfied with NotesXSLTransformer in the past is that, when I've had occasion to want to use it, DXL has nearly always been involved. And, for the life of me, I'd been unable to discern why XPath expressions that work just fine for other XML sources wouldn't match any elements in DXL. After all, XSL doesn't care how the XML was generated... but it does care about namespaces.
When exporting any note or note collection (or entire database) to DXL, the root element always includes an xmlns attribute, set to http://www.lotus.com/dxl. There is (currently) no way to prevent or modify this behavior. Without that attribute, a for-each with a select of "database/document" against a DXL export of an entire database would grab every document in the database. With that attribute, it returns nothing. Because this isn't considered an error condition, it doesn't tell you anything went wrong... you just don't get the data you're expecting. However, if you include a xmlns:dxl attribute set to the same URL in your stylesheet, and set your for-each select to "dxl:database/dxl:document", voila: you get precisely what you wanted.
Perhaps worthy of note is that the namespace doesn't have to be "dxl"... it can be "junk" (yes, I've tested this) - or anything else, as long as the suffix you specify in the namespace attribute in your stylesheet matches the element prefix you use in all XPath expressions. In retrospect, this makes perfect sense, but somehow I overlooked this subtlety, so I thought I'd admit my oversight in case it helps any of you who have struggled with the same issue. Here's a very basic example of a stylesheet that can be applied to an export of an entire database to print out a table of information (UNID, NoteID, and Form) for each document:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dxl='http://www.lotus.com/dxl'>
Click here to see the HTML that results.