XSLT Stylesheet: NotesDocument to JSON
Category domino
The newest addition to the Downloads is an XSLT stylesheet that converts the DXL output of a NotesDocument to JSON.
Back in May, I announced an OpenNTF project that Nathan and I are working on called "Decepticon". To recap, it's a utility that allows your server to support "pseudo" URL commands, such as ReadDocument, ReadFormDesign, ReadAgentDesign, etc.... for every database on your server, without requiring any design changes to those databases. Just as ReadViewEntries renders DXL representing the contents of a view, each of these new URL commands renders DXL representing the content of a document or design element. It also caches that DXL, so if the data being requested has previously been requested and hasn't been modified since, the server doesn't have to export the DXL again... it just returns the cached data.
So, hooray, that's nifty. But the real power (and the reason for its namesake) is that it can also transform the DXL server-side. Toss in a querystring parameter of "&stylesheet=whatever", where "whatever" matches the name of a stylesheet that you've added to the transform templates section of Decepticon, and the server morphs the DXL accordingly prior to sending it to the browser. In the case of this new stylesheet, "/folder/db.nsf/view/dockey/readdocument&stylesheet=documenttojson" (or "db.nsf/0/unid") returns JSON that includes a document's UNID, NoteID, created/modified date, and all of its field values (except MIME or rich text). For example, you can view this blog entry as JSON. An AJAX request that retrieves that URL can eval the response as, say, "doc", and then you can grab a field value via "doc.items['Subject'].values[0]", or its UNID simply as "doc.unid".
So what? Well, ReadViewEntries has been around since 6, but we had to wait until 7.0.2 for OutputFormat=JSON. Which is understandable not only because enhancements to Domino from IBM are bound to take a while in order to allow for thorough product testing and such, but it also really hasn't been that long that JSON has been in widespread use. So we had to wait years for this option. Yet with Decepticon, I can throw together a stylesheet over a weekend that allows any document in any database on my server to be retrieved in JSON format. But ultimately JSON is beside the point... this stylesheet sits atop a framework that allows DXL to become pretty much anything. Did you like the database design mind map? Create a Decepticon stylesheet that spits out node tags for the design data you want mapped, then point the applet's source to "/anydb.nsf/readdatabasedesign&stylesheet=mindmap". Or, if you're particularly ambitious (tee hee), how about "/anydb.nsf/0/unid/readdocument&stylesheet=ODF"... see the possibilities here?
The newest addition to the Downloads is an XSLT stylesheet that converts the DXL output of a NotesDocument to JSON.
Back in May, I announced an OpenNTF project that Nathan and I are working on called "Decepticon". To recap, it's a utility that allows your server to support "pseudo" URL commands, such as ReadDocument, ReadFormDesign, ReadAgentDesign, etc.... for every database on your server, without requiring any design changes to those databases. Just as ReadViewEntries renders DXL representing the contents of a view, each of these new URL commands renders DXL representing the content of a document or design element. It also caches that DXL, so if the data being requested has previously been requested and hasn't been modified since, the server doesn't have to export the DXL again... it just returns the cached data.
So, hooray, that's nifty. But the real power (and the reason for its namesake) is that it can also transform the DXL server-side. Toss in a querystring parameter of "&stylesheet=whatever", where "whatever" matches the name of a stylesheet that you've added to the transform templates section of Decepticon, and the server morphs the DXL accordingly prior to sending it to the browser. In the case of this new stylesheet, "/folder/db.nsf/view/dockey/readdocument&stylesheet=documenttojson" (or "db.nsf/0/unid") returns JSON that includes a document's UNID, NoteID, created/modified date, and all of its field values (except MIME or rich text). For example, you can view this blog entry as JSON. An AJAX request that retrieves that URL can eval the response as, say, "doc", and then you can grab a field value via "doc.items['Subject'].values[0]", or its UNID simply as "doc.unid".
So what? Well, ReadViewEntries has been around since 6, but we had to wait until 7.0.2 for OutputFormat=JSON. Which is understandable not only because enhancements to Domino from IBM are bound to take a while in order to allow for thorough product testing and such, but it also really hasn't been that long that JSON has been in widespread use. So we had to wait years for this option. Yet with Decepticon, I can throw together a stylesheet over a weekend that allows any document in any database on my server to be retrieved in JSON format. But ultimately JSON is beside the point... this stylesheet sits atop a framework that allows DXL to become pretty much anything. Did you like the database design mind map? Create a Decepticon stylesheet that spits out node tags for the design data you want mapped, then point the applet's source to "/anydb.nsf/readdatabasedesign&stylesheet=mindmap". Or, if you're particularly ambitious (tee hee), how about "/anydb.nsf/0/unid/readdocument&stylesheet=ODF"... see the possibilities here?

Comments
Posted by Rich Waters At 10:54:12 AM On 09/24/2007 | - Website - |
Posted by Tim Tripcony At 12:37:23 PM On 09/24/2007 | - Website - |