Search

Top Ten List

Of all my ramblings, people seem to find the following the most interesting:
  1. Pimp My Fields
  2. Using the WebBrowser control to view attachments inline
  3. Purty charts in Domino
  4. My approach to DbLookup and DbColumn in Javascript
  5. Mind Map of Database Design
  6. Design Catalog - version control for Domino
  7. Workaround for LotusScript event binding
  8. Clickable URL's in Notes view columns
  9. Every time you use window.open, God kills a kitten
  10. Create, edit, and delete without agents via AJAX

« Props | Main| Nerd King? »

FGOTO: Easy way to overcome DXL-XSLT pitfalls with namespacing

Category domino fgoto
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'>
<xsl:template match="/">
<html>
<head>
<title>Document List</title>
</head>
<body>
<center>
<table>
<tr>
<th><b>UNID</b></th>
<th><b>NoteID</b></th>
<th><b>Form</b></th>
</tr>
<xsl:for-each select="dxl:database/dxl:document">
<tr>
<xsl:for-each select="dxl:noteinfo">
<td><xsl:value-of select="@unid"/></td>
<td><xsl:value-of select="@noteid"/></td>
</xsl:for-each>
<td><xsl:value-of select="@form"/></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Click here to see the HTML that results.

Comments

Gravatar Image1 - Yes it's tricky alright. Sorry I disn't read the other post more carefully as I could have provided that pice of the puzzle for you... Emoticon

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Contact Me

Hire Me

Elsewhere

What the Quote?

"Next week we're gonna powder-puff Monkey Butt."

Lawson Hise

"I'm sure one of these days you'll get a break.... just don't hold your breath, I don't think you'd look good in blue"

Steven Rodgers

"It's kind of like a Purple Nurple, but with less pain"

Steven Rodgers

"Microsoft is as simple as the church. You cannot be a little bit Catholic."

Volker Weber

"It involves a flank, a beachhead, and a claymore. Solve for X."

Steven Rodgers

Apparel

Lotus Rocks

I write the code that makes the young girls cry

Current Terror Alert Level

Assorted Linkage

ClustrMap