Fausto schrieb:
Also, I have read in an
article<http://www.ibm.com/developerworks/library/x-xalanextensions.html>that
XSLT processors should have some optimization on extension functions,
assuming these functions should not have any side effect and always return
the same value when some parameter is passed. This assumed, the optimization
would cache the results of last calls and their parameters, and our
functions wouldn't be called as many times we thought them would be called.

My questions are: does xalan have this optimization [...] ?

Apparently not:

17:30:31,43 C:\MILU\dev\XSL-Xalan
# more increment-via-extension.xsl /T1
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    version="1.0"
    xmlns:own="http://my.own.extension";
    exclude-result-prefixes="own">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="/*">
  <xsl:copy>
   <eins><xsl:value-of select="own:Increment.new()"/></eins>
   <zwei><xsl:value-of select="own:Increment.new()"/></zwei>
  </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

17:30:49,20 C:\MILU\dev\XSL-Xalan
# more urmel.xml
<Urmel/>

17:31:00,65 C:\MILU\dev\XSL-Xalan
# more my\own\extension\Increment.java
package my.own.extension;

public class Increment {
    private static int counter;
    public Increment() {
        counter++;
    }
    public String toString() {
        return Integer.toString( counter);
    }
}

Michael Ludwig

Reply via email to