XSL-1047: (Error) Invalid instantiation...

I was getting the following error: “XSL-1047: (Error) Invalid instantiation of ‘xsl:sort’ in ‘xsl:for-each-group’ context.” while trying to use an xslt stylesheet containing the following construction:

<xsl :for-each-group select="Employee" group-by="Department">
  <xsl :sort select="HireDate" order="ascending" />
  ...
</xsl>

It took me a while to figure out what was wrong. I need to use a newer version of the xml parser. The problem was gone after upgrading the xml parser from version 9.0.4 to version 10.1.0.4.2.