Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2140

Re-use the same transformer with stylesheet containing xsl:key doesn't work correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.6
    • 2.7
    • XSLTC
    • None
    • windows jdk 1.4.2_06 xsltc
    • PatchAvailable

    Description

      Hello,
      I have a problem with a stylesheet containing a xsl:key.

      I have the impression that the Transformer object guard into memory preceding xml source.
      Here a testcase to reproduce the problem.
      The first transformation and the third should produce the same thing.
      It is true with Xalan interpretive.
      It is not the case in xsltc.
      _________________________
      package test;

      import junit.framework.TestCase;

      import java.io.ByteArrayOutputStream;
      import java.io.File;

      import java.util.Properties;

      import javax.xml.transform.Source;
      import javax.xml.transform.Transformer;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.stream.StreamResult;
      import javax.xml.transform.stream.StreamSource;

      public class XSLTTest extends TestCase {
      public XSLTTest(String arg0)

      { super(arg0); }

      public void testKey() throws Exception

      { String key = "javax.xml.transform.TransformerFactory"; String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; Properties props = System.getProperties(); props.put(key, value); System.setProperties(props); TransformerFactory tFactory = TransformerFactory.newInstance(); String xsl = getClass().getResource("test.xsl").getPath(); //1 transformation Source xml = new StreamSource(new File(getClass() .getResource("habP1.xml") .getPath())); ByteArrayOutputStream out = new ByteArrayOutputStream(); Transformer transformer = tFactory.newTransformer(new StreamSource(xsl)); transformer.transform(xml, new StreamResult(out)); System.out.println(out.toString()); //2 transformation xml = new StreamSource(new File(getClass().getResource("habP0.xml") .getPath())); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); transformer.transform(xml, new StreamResult(out2)); System.out.println(out2.toString()); //3 transformation xml = new StreamSource(new File(getClass().getResource("habP1.xml") .getPath())); ByteArrayOutputStream out3 = new ByteArrayOutputStream(); transformer.transform(xml, new StreamResult(out3)); System.out.println(out3.toString()); assertEquals(out.toString(),out3.toString()); }

      }
      -------test.xsl---------------------
      <?xml version="1.0"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="text" encoding="ISO-8859-1" indent="yes" />

      <xsl:key name="clef_habilitations" match ="action" use = "nom" />

      <xsl:template match="/">

      <xsl:value-of select="key('clef_habilitations','nom1')/nom" />
      <xsl:value-of select="key('clef_habilitations','nom2')/nom" />
      </xsl:template>
      </xsl:stylesheet>
      --------habP0.xml-----------------------
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <habilitation>

      <action>
      <nom>nom1</nom>
      </action>
      <action>
      <nom>nom2</nom>
      </action>
      <action>
      <nom>nom3</nom>
      </action>
      <action>
      <nom>nom4</nom>
      </action>

      </habilitation>
      -----------habP1.xml-------------
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <habilitation>

      <action>
      <nom>nom1</nom>
      </action>
      <action>
      <nom>nom3</nom>
      </action>
      <action>
      <nom>nom4</nom>
      </action>

      </habilitation>
      ---------System.out--------------------

      nom1

      nom1
      nom2

      nom1
      nom3

      Attachments

        1. j2140.patch.txt
          0.9 kB
          Henry Zongaro

        Activity

          People

            zongaro@ca.ibm.com Henry Zongaro
            arn44fr@yahoo.fr arnaud
            Brian Minchau Brian Minchau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: