It appears to me that the version of Xalan that ships with JDK 6 (and 7) does not process comments in the input file, as specified by `<xsl:template match="comment()" ...>...`

Given the following input file, dangling.xml

```
<?xml version="1.0" ?>
<dangling xmlns:dt="urn:uuid:e2973380-8daf-11e3-a5d8-0002a5d5c51b">
   <!--  This is a comment. -->
   <foobar x="y">A bar where I drink foo beer,
           after debugging XSLT in hell all day.</foobar>
</dangling>

```

and the stylesheet identity\_sans\_dt.xsl

```
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:dt="urn:uuid:e2973380-8daf-11e3-a5d8-0002a5d5c51b">

<xsl:output method="xml"
            encoding="UTF-8"
            indent="yes" 
            omit-xml-declaration="yes"
            />

   <xsl:template match="/ | attribute::* | comment()">
     <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
   </xsl:template>
   <xsl:template match="*">
      <xsl:element name="{name()}">
         <xsl:apply-templates select="@*|node()"/>
      </xsl:element>
   </xsl:template>
</xsl:stylesheet>

```

I get the following output using libxml's xsltproc

```
<dangling>
   <!--  This is a comment. -->
   <foobar x="y">A bar where I drink foo beer,
           after debugging XSLT in hell all day.</foobar>
</dangling>

```

However, when I run the same thing through a Java program that applies the same stylesheet using a SAX TransformerHandler, I get this.

```
<dangling>

   <foobar x="y">A bar where I drink foo beer,
           after debugging XSLT in hell all day.</foobar>
</dangling>

```

Am I doing something wrong that is causing what technical specifications euphemistically call "unpredictable results?" Or does there appear to be a Xalan bug responsible for the omission of the comment in the Java version?

While not directly related to the question on comment() handling, here is the background for this exercise. dangling.xml is the result of some previous processing that had stripped out all of the elements in the dt namespace and their children. For some reason, the dt namespace declaration was left behind. In addition, the xml declaration was causing some problems. (This was because some downstream code was manipulating this as a string, and just plopping it into the middle of another string of XML text. Don't bother telling me how horrible this is; I know. Don't bother telling those responsible for said code; I have already.) So I spent an inordinate amount of time trying to get rid of these two annoying artifacts, but keep everything else.

No, dangling.xml isn't the REAL file, just a proxy for debugging. :-) 

So if there is a completely better approach that sidesteps the whole problem, I'd be interested in knowing about that, too.

Thank you in advance.