May 30, 2007

Smart trick - exslt:node-set() in Internet Explorer

I found this gem in David Carlisle's blog. Smart Javascript trick allows to mask msxsl:node-set() extension function as exsl:node-set() and so you can easily write crossbrowser XSLT stylesheets using exsl:node-set() functionality. Opera 9, Internet Explorer 6-7 and Firefox 3 are covered, but sadly Firefox 2 is out of the game. Julian ...

March 28, 2007

How to register automatically HTTP handler required by a Web server control

In ASP.NET when you building a server control that includes an HTTP handler you have this problem - the HTTP handler has to be registered in Web.config. That means it's not enough that your customer developer drops control on her Web form and sets up its properties. One more step is ...

November 23, 2006

Muenchian grouping perf in .NET 2.0 (XslCompiledTransform)

Back in 2005 I was writing about speeding up Muenchian grouping in .NET 1.X. I was comparing three variants of the Muenchian grouping (using generate-id(), count() and set:distinct()). The conclusion was that XslTransform class in .NET 1.X really sucks when grouping using generate-id(), performs better with count() and the best ...

November 19, 2006

Reporting XSLT compilation errors in .NET

Reporting errors in XSLT stylesheets is a task that almost nobody gets done right. Including me - error reporting in nxslt sucks in a big way. Probably that's because I'm just lazy bastard. But also lets face it - XslCompiledTransform API doesn't help here. Whenever there are XSLT loading (compilation) errors ...

November 16, 2006

How to get line number for a node in XSLT

It's surprisingly easy in .NET 2.0. Obviously it can't be done with pure XSLT, but an extension function returning line number for a node takes literally two lines. The trick is to use XPathDocument, not XmlDocument to store source XML to be transformed. The key is IXmlLineInfo interface. Every XPathNavigator over XPathDocument ...

November 5, 2006

XPath, apostrophes and quotes

When working with XPath be it in XSLT or C# or Javascript, apostrophes and quotes in string literals is the most annoying thing that drives people crazy. Classical example is selections like "foo[bar="Tom's BBQ"]. This one actually can be written correctly as source.selectNodes("foo[bar=\"Tom's BBQ\"]"), but what if your string is ...

October 20, 2004

On pretty-printing XML documents using MSXML

Yeah, I know it's an old problem and all are tired of this one, but it's still newsgroups' hit. Sometimes XSLT is the off-shelf solution (not really perf-friendly though), but <xsl:output indent="yes"/> is just ignored in MSXML. In .NET one can leverage XmlTextWriter's formatting capabilities, but what in MSXML? Well ...

July 28, 2004

Tell me who are you and what are you processing

This is small trick for newbies looking for a way to get URI of a source XML and the stylesheet from within XSLT stylesheet. ...

July 25, 2004

Breadth-first tree traversal in XSLT

As a matter of interest - how would you implement breadth-first tree traversal in XSLT? Traditional algorithm is based on using a queue and hence isn't particularly suitable here. Probably it's feasible to emulate a queue with temporary trees, but I think that's going to be quite ineffective. Being not ...

February 9, 2004

On Making XML Namespaced On The Fly

This interesting trick has been discussed in microsoft.public.dotnet.xml newsgroup recently. When one has a no-namespaced XML document, such as <?xml version="1.0"?> <foo> <bar>Blah</bar> </foo> there is a trick in .NET, which allows to read such document as if it has some default namespace: <?xml version="1.0"?> <foo xmlns="http://foo.com"> <bar>Blah</bar> </foo> ...

February 5, 2004

XML Tips and Tricks. Conditional XPath expressions

I'm introducing another category in my blog - XML Tips and Tricks, where I'm going to post some XML, XPath, XSLT, XML Schema, XQuery etc tips and tricks. I know, many of my readers being real XML gurus know all this stuff (I encourage to correct me when I'm wrong ...