You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/04/25 15:00:38 UTC
[Bug 1496] New - TransformerImpl.setParameter should only remember user parameters, not dynamic parameters
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1496
*** shadow/1496 Wed Apr 25 06:00:38 2001
--- shadow/1496.tmp.623 Wed Apr 25 06:00:38 2001
***************
*** 0 ****
--- 1,77 ----
+ +============================================================================+
+ | TransformerImpl.setParameter should only remember user parameters, not dyn |
+ +----------------------------------------------------------------------------+
+ | Bug #: 1496 Product: XalanJ2 |
+ | Status: NEW Version: 2.0.1 |
+ | Resolution: Platform: All |
+ | Severity: Normal OS/Version: Other |
+ | Priority: Medium Component: org.apache.xalan.transf |
+ +----------------------------------------------------------------------------+
+ | Assigned To: xalan-dev@xml.apache.org |
+ | Reported By: Alex.Blewitt@ioshq.com |
+ | CC list: Cc: |
+ +----------------------------------------------------------------------------+
+ | URL: |
+ +============================================================================+
+ | DESCRIPTION |
+ I have an XSL file that declares a variable, which is computed based on an
+ element of the document it is processing. If I use the same Transformer to
+ process another document, the parameter is not re-evaluated with the new value.
+
+ <xsl:stylesheet>
+ <xsl:param name="title" select="/Title/node()">
+
+ <xsl:template match="/">
+ <HTML><HEAD><TITLE><xsl:value-of select="$title"/></TITLE></HEAD><xsl:apply-
+ templates/></HTML>
+ </xsl:template>
+ </xsl:stylesheet>
+
+ If I create a Transformer, and then run it on:
+
+ doc1.xml:
+ <Title>Doc1</Title>
+
+ doc2.xml:
+ <Title>Doc2</Title>
+
+ then the outputs are:
+
+ out1.html:
+ <HTML><HEAD><TITLE>Doc1</TITLE></HEAD></HTML>
+
+ out2.html:
+ <HTML><HEAD><TITLE>Doc2</TITLE></HEAD></HTML>
+
+ It appears that the routine evaluating the parameter is using 'setParameter' to
+ store the value, which is then cached (and hence, not re-evaluated) for the
+ second document.
+
+ IMHO it is useful to store *user* set parameters via the transformer, but I do
+ not believe that the same parameters should be used to store the *computed*
+ parameters in such a way.
+
+ The effect can be fixed by calling 'clearParameters()' on the Transformer
+ object between each call; however, storing user parameters is still a bonus.
+
+ The following will fix the problem by clearing the parameter list between calls:
+
+ public class NewTransformer extends TransformerImpl {
+ private Map userParams = new HashMap();
+ public void setParameter(String param, String value) {
+ userParams.put(param,value);
+ }
+ public void transform(Source source) {
+ super.clearParameters();
+ Iterator i = userParams.iterator();
+ while(i.hasNext()) {
+ Object name = i.next();
+ Object value = userParams.get(name);
+ super.setParameter(name,value);
+ }
+ super.transform(source);
+ }
+ }
+
+ This can be used to give the impression to the user that his parameters are
+ being cached, but allow the parameters to be evaluated each time.