The problem

org.apache.xml.dtm.DTMException: No more DTM IDs are available.

The reason

The Document Table Model (DTM) is Xalan's document model and uses the DTM IDs for representing objects. If you have big documents and heavy transformations the system can run out of DTM IDs (even if there are 2 ^ 16). Some bugs on this issue were already fixed: buglist.
But especially the version 2.2.D11 delivered with Sun's JDK 1.4 was susceptible to runing out of IDs. With more recent releases it's much more difficult to get the exception, but still possible.

The solution

First make sure that you do use the version you expect to use. You can do this simply by running a transformation using the environment check stylesheet. If in the output another version is shown as expected (especially 2.2.D11), you have a problem ;-)

It's not as easy to solve as you may think, because it's not a simple classpath issue. You must force the JVM to load your version of the classes before the JDK's one. Read more about it in the Xalan FAQ and at Sylvain's excellent explanation of the infamous EndorsedLibsProblem.
In short you have the following options:


If you use the correct Xalan version at the end, but the error still occurs, simplify and optimize your stylesheets. XPath expressions like //* or <xsl:number level="any"/> force Xalan to load/store the whole document in the memory. With big documents (in the sample 2 MB were mentioned) this can lead to the exception. In this sample <xsl:number/> could simply be replaced by <xsl:value-of select="position()"/>.

Hope this helps to avoid DTMException for you in the future :-)

See also

NoMoreDtmIdError (last edited 2009-09-20 23:42:12 by localhost)