January 29, 2006

"Working with Microsoft Visual Studio 2005" book

This is a book called "Working with Microsoft Visual Studio 2005" by Marc Young, Brian Johnson and Craig Skibo, which is an update of their "Inside Microsoft Visual Studio .NET 2003" book. Really great book explaining Visual Studio 2005 internals and ways to extend it. But you can't buy it ...

January 26, 2006

QOTD

Another alternative to purchasing a hexadecimal calculator is to obtain a TSR (Terminate and Stay Resident) program such as SideKick which contains a built-in calculator. However, unless you already have one of these programs, or you need some of the other features they offer, such programs are not a particularly ...

January 25, 2006

XSLT 2.0 and .NET unofficial survey ends January 31

"XSLT 2.0 in .NET" survey at the XML Lab site ends in a week.Vote now and get a chance to win the "XSLT 2.0" book by Mike Kay!When the survey ends one lucky survey taker from whatever part of the world choosen randomly will get the book. Note: you ...

January 24, 2006

exsl:object-type() XSLT extension function in .NET 2.0

Now that XslCompiledTransform in .NET 2.0 supports exsl:object-type() extension function I think a little intro is needed as this is really new function for Microsoft-oriented XSLT developers. ...

exsl:object-type() function brings a bit of reflection functionality into XSLT allowing dynamic type identification at runtime. That is using exsl:object-type() one can determine type of an object, e.g. a type of passed parameter value. In XSLT 1.0 type system that means 'string', 'number', 'boolean', 'node-set', 'RTF' or 'external':

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl"> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/"> <out> <xsl:variable name="node" select="/data"/> <xsl:variable name="string" select="'string'"/> <xsl:variable name="number" select="11"/> <xsl:variable name="rtf"> <foo/> <bar/> </xsl:variable> <xsl:variable name="boolean" select="true()"/> Node type: <xsl:value-of select="exsl:object-type($node)"/> String type: <xsl:value-of select="exsl:object-type($string)"/> Boolean type: <xsl:value-of select="exsl:object-type($boolean)"/> Number type: <xsl:value-of select="exsl:object-type($number)"/> RTF type: <xsl:value-of select="exsl:object-type($rtf)"/> </out> </xsl:template> </xsl:stylesheet> The result is: <out> Node type: node-set String type: string Boolean type: boolean Number type: number RTF type: RTF</out> Provided weakly typed nature of XSLT 1.0 this function can become really useful for employing defensive programming (e.g. to assert that a parameter passed to a named template contains actually a nodeset), testing or even debugging.

For a sample of defensive programming using exsl:object-type() function consider the following dummy stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl"> <xsl:template match="/"> <out> <xsl:variable name="tmp"> <foo/><bar/> </xsl:variable> <xsl:call-template name="util42"> <xsl:with-param name="nodes" select="$tmp"/> </xsl:call-template> </out> </xsl:template> <xsl:template name="util42"> <xsl:param name="nodes"/> <xsl:if test="exsl:object-type($nodes) != 'node-set'"> <xsl:message terminate="yes"> util42 template expects parameter $nodes to be a nodeset, not '<xsl:value-of select="exsl:object-type($nodes)"/>'!</xsl:message> </xsl:if> <!-- do some stuff --> <xsl:apply-templates select="$nodes"/> </xsl:template> </xsl:stylesheet> Here util42 template before doing any work asserts than actual parameter value passed is a nodeset, not anything else. If you comment out that <xsl:if> test, you'll get the following transformation error:
XslTransformException
---------------------
To use a result tree fragment in a path expression, first convert it to a node-set 
using the msxsl:node-set() function.
Well, as usual with automatic error messages - at least unclear. Now with object type check you should get this:
XslTransformException
---------------------
util42 template expects parameter $nodes to be a nodeset, not 'RTF'!
Definitely more meaningful and safe. And of course it's now up to template author whether to terminate transformation or to recover.

Pretty useful fiunction. And when it comes to QA - that's a godsend. As a matter of interest, AFAIK exsl:object-type() function was implemented to help Microsoft XML Team with XslCompiledTransform testing in the first place.

January 22, 2006

Yahoo! tests RSS ads

I've got an invitation to participate in Yahoo! Publisher Network Beta program, which seems to be another targeted ad system just like Google AdSense, but already supporting ads in RSS feeds. They support MovableType and WordPress. Alas I couldn't even login - it's currently USA only and USA tax information ...

January 19, 2006

XQuery Style Conventions

Creators of the XQDoc, a free tool for documenting XQuery modules have released XQuery Style Conventions. They claim the document to be to be based on experience and feedback from the XQuery development community. It does seem ok to me. In a perfect world every programmer would follow style conventions ...

January 17, 2006

How to give away 3 Visual Studio Team Suite/MSDN Premium Subscriptions: looking for ideas

As many other Microsoft MVPs I've been given 3 "Visual Studio 2005 Team Suite with MSDN Premium Subscriptions" redemption cards to share. So now I'm having hard time looking for smart ideas how to do so. One card I would give to Kevin Downs, the guy who runs NDoc if ...

January 15, 2006

Autumn grasshoppers

My wife's been chasing grasshoppers this fall: ...

Detecting version of Microsoft XSLT engine from within XSLT

Sometimes it's useful to detect which XSLT engine your XSLT stylersheet is being executed by, e.g. to shortcut processing using an engine-specific extension function or to workaround a bug in particlular engine. Now that Microsoft alone ships 3 different XSLT engines - MSXML3/MSXML4/MSXML5/MSXML6, XslTransform and XslCompiledTransform, detecting XSLT engine from ...

MSXML supports "ms:version" system property, which can be retrieved using standard XSLT system-property() function. The value returned is MSXML version - "3", "4", "5" and so on. XslTransform doesn't support "ms:version" property and returns empty string (just like any other non-Microsoft XSLT engine). But new XslCompiledTransform does support it and "returns a string representing the version of the assembly implementing XslCompiledTransform in the same format as returned by Assembly.ImageRuntimeVersion property ('v2.0.50727' for .NET Framework 2.0)."

This, along with standard 'xsl:vendor' property should give us enough information to differentiate between Microsoft XSLT engines. Here is a sample XSLT stylesheet that does the trick:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms"> <xsl:template match="/"> <p> This XSLT stylesheet is being executed using <xsl:choose> <xsl:when test="system-property('xsl:vendor') = 'Microsoft'"> <xsl:text>Microsoft </xsl:text> <xsl:variable name="ms-version" select="system-property('ms:version')"/> <xsl:choose> <xsl:when test="$ms-version = ''">XslTransform</xsl:when> <xsl:when test="starts-with($ms-version, 'v')">XslCompiledTransform</xsl:when> <xsl:otherwise> MSXML <xsl:value-of select="$ms-version" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> Unrecognized XSLT engine from '<xsl:value-of select="system-property('xsl:vendor')" />' </xsl:otherwise> </xsl:choose> </p> </xsl:template> </xsl:stylesheet>

Through a solid Microsoft Exchange server in-house or paying for Exchange email outsourcing you'll have access to a Microsoft Exchange server that lets you access email and shared calendars worldwide through Exchange 2007 hosting software.

January 11, 2006

Microsoft and EXSLT - secret breakthrough

There are two new killer but undocumented features in Microsoft .NET 2.0 pertaining to EXSLT. Anybody like me regularly digging in System.Xml assembly probably knows it, but general audience is still unaware. So I want to share these secrets. ...

Secret #1. Unexpected surprise. Microsoft's new XSLT processor (XslCompiledTransform) supports natively two EXSLT extension functions - exsl:node-set() and exsl:object-type(). That is technically speaking XslCompiledTransform supports EXSLT - Common module.

Moreover, as mentioned in the "Introducing XslCompiledTransform" article on the Microsoft XML Team's WebLog, the behaviour of Microsoft specific msxsl:node-set() extension function is aligned with the behavior of the same function in MSXML and exsl:node-set() - when being given something other than RTF it returns text node containing string value of the passed object. As a matter of interest msxsl:node-set() and exsl:node-set() in XslCompiledTransform is the same function.

Now that means that XslCompiledTransform joins Saxon, Xalan, libxslt and other mainstream XSLT processors natively supporting exsl:node-set() function and any XSLT stylesheet using it for manipulating temporary trees is now completely portable between .NET 2.0, Java and other platforms. That's a substantial relief for anybody doing serious XSLT development. And that makes lots of practical sense to keep XML processing portable.

Secret #2. Using XSLT extension objects in .NET 2.0 now doesn't require FullTrust. MSDN documentation says opposite, but this is just a documentation copy-n-paste bug.

This used to be a showstopper problem for using EXSLT.NET in a semi-trusted environments like ASP.NET or ClickOnce and I was complaining about it all the way. Now this isn't a problem anymore and you can use EXSLT extension functions in ASP.NET applications, e.g. via my free eXml Web server control.

That doesn't mean of course that security is compromised in any way. Code Access Security is still in place and XSLT extension functions in .NET 2.0 can only perform what is allowed for the code that runs XSLT transformation. And as 70+ EXSLT.NET functions doesn't do anything dangerous like accessing file system or remote resources, it's safe to use EXSLT.NET functions in ASP.NET even on minimal trust level. Also don't forget that XSLT extension objects don't come with XSLT stylesheets - they must be passed in code explicitly so they are safe.

That's way cool. I only wonder why such killer features are not documented. I can only guess that this is probably a consequence of the poor Microsoft middle management problem - be these features documented no doubts they would be cut at early stage. Now that .NET 2.0 is out I urge everybody to use exsl:node-set() and exsl:object-type() functions along with eXml Web server control to make it impossible to cut these features anymore :)

We should thank Microsoft XML Team for making it possible even in undocumented way. And we should say thank you to Dare for pushing EXSLT inside Microsoft despite he thinks he didn't succeed:

I know this because I've been in that position trying to get us to implement EXSLT and Schematron when I was on the XML team. Did I succeed? The lack of any implementations of either technology from Microsoft shows I didn't even come close.

A good Microsoft Exchange server maintained by staff knowledgeable about Microsoft Exchange is a useful tool to some business that require worldwide access to email that Exchange 2007 hosting excels at, be it through self-hosting or Exchange email outsourcing outside the company.

January 10, 2006

Quiz of XSLT 1.0 oddities by James Fuller

You say you know XSLT well? Try answer this quiz of XSLT 1.0 oddities by James Fuller. ...

Subject: [xsl] a bit of distraction ' quiz of XSLT 1.0 oddities' From: James Fuller <jim.fuller@xxxxxxxxxxxxxx> Date: Tue, 27 Dec 2005 11:04:03 +0100 a bit of distraction for those who must work. I am generating a little 'quiz of oddities' for XSLT 1.0, some of which I have bumped into from time to time....none are particularly mind blowing, though some may make one stop and think. Here are some of mine....(xsl:stylesheet elements have been stripped), any more good questions out there ? Answers sometime around new years. -------------------------------------------------------------- Whats the output XML <root> <test>1</test> <test>2</test> <test>3</test> <test>4</test> </root> XSLT <xsl:template match="root"> <xsl:apply-templates select="test"/> </xsl:template> <xsl:template match="*"> this template <xsl:value-of select="."/> </xsl:template> <xsl:template match="node()"> that template <xsl:value-of select="."/> </xsl:template> When matching templates are equivelent which one gets matched? -------------------------------------------------------------- What does the string-length() function return in the following xml / xslt snippet ? XML <doc> <a>Testing this</a> <a>and this too</a> </doc> XSLT <xsl:template match="/"> <out> <xsl:value-of select="string-length()"/><xsl:text> </xsl:text> <xsl:value-of select="string-length(doc/a)"/> </out> </xsl:template> ------------------------------------------------------------- Can a template be both named and match? for example is the following construction possible? <xsl:template name="my:book" match="book"> ------------------------------------------------------------- Does exclude-result-prefixes defined on an xsl:stylesheet element apply to subtrees included with xsl:include ? -------------------------------------------------------------- Is there any way of using apply-templates using a mode 'decided' at run time ? ------------------------------------------------------------- What does this do? <xsl:value-of select="name()"><a>some text</a></xsl:value-of> ------------------------------------------------------------- Can anyone show a clever use of the why one would use the floor() function specifically in XSLT 1.0 ? ------------------------------------------------------------- How does one arrive to this xml <?xml version="1.0" encoding="UTF-8"?> <out>doc #1: <bdd>http://example.com</bdd><ext>http://test.extension</ext> <jad>http://administrator.com</jad><java>http://xml.apache.org/xslt/java</java> <ped>http://tester.com</ped><xml>http://www.w3.org/XML/1998/namespace</xml> doc #2: <xml>http://www.w3.org/XML/1998/namespace</xml> </out> from this xml ? <?xml version="1.0"?> <docs> <doc x="x" y="y" z="z" xmlns:ext="http://test.extension"; xmlns:java="http://xml.apache.org/xslt/java"; xmlns:ped="http://tester.com"; xmlns:bdd="http://example.com"; xmlns:jad="http://administrator.com"/> <doc x="ax" y="ay" z="az"/> </docs> ------------------------------------------------------------- Is the following a valid declaration for xsl:variable? <xsl:template match="/"> <xsl:value-of select="$myvar"/> </xsl:template> <xsl:variable name="myvar" select="'test output'"/> -------------------------------------------------------------- Which XSLT processors fully support EXSLT node-set extension ? -------------------------------------------------------------- When there is no xsl:output element how does an XSLT processor determine that you want an html result ? -------------------------------------------------------------- How does FXSL calculate sin() ? -------------------------------------------------------------- Is there anyway to achieve a conditional inclusion (e.g. conditionally use xsl:include) ? -------------------------------------------------------------- I have a few more.....pls send your questions, will compile and perhaps ask DaveP to include in XSLT FAQ. cheers, Jim Fuller

15 years old C# MVP

This guy Matt Cassell is 15 years old and now he's got C# MVP award. Boy, I feel like a dinosaur now... ...

January 9, 2006

WordML2HTML with support for images stylesheet updated

Almost 2 years ago I published a post "Transforming WordML to HTML: Support for Images" showing how to hack Microsoft WordML2HTML stylesheet to support images. People kept telling me it doesn't support some weird image formats or header images. Moreover I realized it has a bug and didn't work with ...

Starting Word 2003 document with images in body and header:

Magic XSLT transformation:

nxslt2 test.xml wordml2html-.NET-script.xslt -o test.html
produces test.html and a directory containing decoded images:

Download the stylesheet at the XML Lab downloads page. Any comments are welcome.

Higher quality PDF to Word software will do more than just allow you to convert PDF to Word; you'll be able to do PDF conversion between Excel, Powerpoint, and other formats, such that converting PDF to Word is just the tip of the iceberg.

January 8, 2006

Trying out natural keyboard

I've never tried working with natural keyboards. Somehow I thought they are kinda unnatural :) Now I want to give it a try, may be this new Microsoft Natural Ergonomic Keyboard 4000: Seems like people love it. It's great to see the latest Microsoft keyboard with standard 2x3 home/end key ...

January 5, 2006

Beginning 2006

Happy New Year everyone, I hope you are not sick and depressive as I am. But I'm slowly recovering... Good news in the mailbox yesterday - I got Microsoft MVP Award again, third year in a row, 2004, 2005 and now 2006. In the "Windows Server System - XML" category ...