Search

What the Quote?

"Breastmilk makes everything cooler!"

Mike Koenig

"Eyeballs, blogs, branding.... Help!!!"

Eric Romo

"I want my MTV, dammit, but you don't hear me bitching... oh wait, that was me bitching."

Steven Rodgers

« 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

Gravatar Image2 - Thanks for this post. It helped solve a problem that was bugging me for several days. Once I figured out that I had a namespace issue this was the easiest explanation(with respect to domino development) that I found. Emoticon

Gravatar Image3 - Glad I could be of assistance, Jim.

Post A Comment

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