I need to create an XSLT 2.0 stylesheet which processes the [full periodic table](http://www.w3.org/XML/Binary/2005/03/test-data/Over100K/periodic.xml), sorts the atoms (only their names) into the groups based on their state (i.e. `STATE` attribute of `ATOM` element) into a text file. 

I did something but there are `<ATOM>` elements without `STATE` attributes. Those elements must appear in the result document as well.

```
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:template match="PERIODIC_TABLE">
      <xsl:for-each-group select="ATOM" group-by="@STATE" >
        <xsl:text> **    </xsl:text>
        <xsl:value-of select="current-grouping-key()"/>
        <xsl:text>
</xsl:text>
        <xsl:for-each select="current-group()">
          <xsl:sort select="NAME"/>
          <xsl:value-of select="NAME"/>
          <xsl:text>
</xsl:text>
        </xsl:for-each>
        <xsl:text>
</xsl:text>
      </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

```