[ http://issues.apache.org/jira/browse/XALANJ-1446?page=all ]
Brian Minchau updated XALANJ-1446:
----------------------------------
Version: Latest Development Code
(was: 2.3)
> Transformations using DOMSource apply templates differently than with
> StreamSource
> ----------------------------------------------------------------------------------
>
> Key: XALANJ-1446
> URL: http://issues.apache.org/jira/browse/XALANJ-1446
> Project: XalanJ2
> Type: Bug
> Components: DTM
> Versions: Latest Development Code
> Environment: Operating System: All
> Platform: All
> Reporter: Joseph Sinclair
> Assignee: Xalan Developers Mailing List
>
> When transforming documents, the Xalan processor may produce different
> results
> when using the DOMSource vs. StreamSource. It applies the default templates
> to
> non-selected elements in the DOMSource document, but properly ignores non-
> selected elements (per XSLT) with the StreamSource. Note this generally
> shows
> up only when embedding Xalan into another application, as the command-line
> code
> uses the StreamSource to load the document to be transformed. This does not
> seem to be an issue if the DOMSource is used to load the stylesheet, only
> when
> the DOMSource is used to load the document to be transformed.
> As an example, execute the following code:
> _______________________________________________________________________________
> private static final String testDocumentString =
> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.getProperty
> ("line.separator", "\n") +
>
> "<!--********************************************************************-->"
> + System.getProperty("line.separator", "\n") +
> "<testRoot>" + System.getProperty("line.separator", "\n") +
> " <testHeader>" + System.getProperty("line.separator", "\n") +
> " <testItem>" + System.getProperty("line.separator", "\n") +
> " This is the testItem content" + System.getProperty
> ("line.separator", "\n") +
> " </testItem>" + System.getProperty("line.separator", "\n") +
> " </testHeader>" + System.getProperty("line.separator", "\n") +
> " <testPayload>" + System.getProperty("line.separator", "\n") +
> " <testValue item1=\"This is Item 1\" item2=\"This is Item 2\">" +
> System.getProperty("line.separator", "\n") +
> " This is the testValue content" + System.getProperty
> ("line.separator", "\n") +
> " </testValue>" + System.getProperty("line.separator", "\n") +
> " </testPayload>" + System.getProperty("line.separator", "\n") +
> " <testTrailer>" + System.getProperty("line.separator", "\n") +
> " <testItem>" + System.getProperty("line.separator", "\n") +
> " This is the testItem content" + System.getProperty
> ("line.separator", "\n") +
> " </testItem>" + System.getProperty("line.separator", "\n") +
> " </testTrailer>" + System.getProperty("line.separator", "\n") +
> "</testRoot>" + System.getProperty("line.separator", "\n") +
>
> "<!--********************************************************************-->"
> + System.getProperty("line.separator", "\n") +
> "";
> private static final String breakLine
> =
> "/////////////////////////////////////////////////////////////////////////////
> ///\n";
> private static final String testStylesheetString =
> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.getProperty
> ("line.separator", "\n") +
> "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " +
> System.getProperty("line.separator", "\n") +
> " exclude-result-prefixes=\"xsl\" " + System.getProperty
> ("line.separator", "\n") +
> " version=\"1.0\">" + System.getProperty
> ("line.separator", "\n") +
> " <xsl:output method=\"text\" indent=\"yes\" encoding=\"UTF-8\" omit-xml-
> declaration=\"no\"/>" + System.getProperty("line.separator", "\n") +
> "" + System.getProperty("line.separator", "\n") +
> " <xsl:template match=\"/\">" + System.getProperty("line.separator", "\n")
> +
> " <xsl:apply-templates
> select=\"/child::testRoot/child::testPayload/child::testValue\"/>" +
> System.getProperty("line.separator", "\n") +
> " </xsl:template>" + System.getProperty("line.separator", "\n") +
> "" + System.getProperty("line.separator", "\n") +
> " <xsl:template match=\"testValue\">" + System.getProperty
> ("line.separator", "\n") +
> " <xsl:text>" + System.getProperty("line.separator", "\n") +
> " Item1=</xsl:text>" + System.getProperty("line.separator", "\n") +
> " <xsl:value-of select=\"attribute::item1\" />" + System.getProperty
> ("line.separator", "\n") +
> " <xsl:text>" + System.getProperty("line.separator", "\n") +
> " Item2=</xsl:text>" + System.getProperty("line.separator", "\n") +
> " <xsl:value-of select=\"attribute::item2\" />" + System.getProperty
> ("line.separator", "\n") +
> " <xsl:text>" + System.getProperty("line.separator", "\n") +
> " </xsl:text>" + System.getProperty("line.separator", "\n") +
> " </xsl:template>" + System.getProperty("line.separator", "\n") +
> "" + System.getProperty("line.separator", "\n") +
> "</xsl:stylesheet>" + System.getProperty("line.separator", "\n") +
> "";
> public void testShowDOMSourceError() throws Exception
> {
> String translationResult;
> Transformer xslTransformer;
> Templates xslTemplate = null;
> Source templateSource = null;
> // Get the transformer
> templateSource = new StreamSource(new StringReader(testStylesheetString));
> xslTemplate =
> TransformerFactory.newInstance().newTemplates(templateSource);
> xslTransformer = xslTemplate.newTransformer();
> DocumentBuilderFactory xmlFactory = DocumentBuilderFactory.newInstance();
> xmlFactory.setExpandEntityReferences(true);
> xmlFactory.setNamespaceAware(true);
> xmlFactory.setValidating(false);
> xmlFactory.setCoalescing(true);
> xmlFactory.setIgnoringElementContentWhitespace(true);
> ByteArrayInputStream inputStream =
> new ByteArrayInputStream(testDocumentString.getBytes
> ("UTF-8"));
> DocumentBuilder xmlBuilder = xmlFactory.newDocumentBuilder();
> translationResult = transformMessageToText(xslTransformer, new DOMSource
> (xmlBuilder.parse(inputStream).getDocumentElement()));
> System.out.println(breakLine);
> System.out.println(translationResult);
> System.out.println(breakLine);
> translationResult = transformMessageToText(xslTransformer, new
> StreamSource
> (new StringReader(testDocumentString)));
> System.out.println(breakLine);
> System.out.println(translationResult);
> System.out.println(breakLine);
> }
> public final String transformMessageToText(Transformer xslTransformer,
> Source
> documentSource) throws TransformerException, TransformerConfigurationException
> {
> StringWriter outputWriter = new StringWriter(4000);
> Result outputResult = new StreamResult(outputWriter);
> xslTransformer.transform(documentSource, outputResult);
> return outputWriter.getBuffer().toString();
> }
> _______________________________________________________________________________
> The following output is produced:
> _______________________________________________________________________________
> ////////////////////////////////////////////////////////////////////////////////
>
>
> This is the testItem content
>
>
>
>
> Item1=This is Item 1
> Item2=This is Item 2
>
>
>
>
> This is the testItem content
>
>
> ////////////////////////////////////////////////////////////////////////////////
> ////////////////////////////////////////////////////////////////////////////////
> Item1=This is Item 1
> Item2=This is Item 2
>
> ////////////////////////////////////////////////////////////////////////////////
> _______________________________________________________________________________
> Note how the DOMSource run executes the default templates for the unmatched
> items prior to, and following, the one matched item. This despite the fact
> that the root template is overridden, and only the one item of interest is
> selected in the contained apply-templates rule. The StreamSource run
> correctly
> applies the defined template only to the selected item, and does not produce
> inappropriate output.
> This test was run with Xalan 2.3.1. I tried using both Xerces 1.4.4, and
> Xerces 2.3.0 for the XML parser used to build the DOM. In both cases the
> output was the same.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]