You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2025/03/28 08:36:56 UTC

(xalan-java) branch xalan-j_xslt3.0_mvn updated: when xsl:source-document instruction has 'streamable' attribute's value 'yes', xalan-j xsl 3 transformation expects an input document source as SAXSource

This is an automated email from the ASF dual-hosted git repository.

mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git


The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
     new 74dab807e when xsl:source-document instruction has 'streamable' attribute's value 'yes', xalan-j xsl 3 transformation expects an input document source as SAXSource
74dab807e is described below

commit 74dab807e5a6fd2d64f03e6a54ea110a45f14ab9
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Mar 28 14:06:44 2025 +0530

    when xsl:source-document instruction has 'streamable' attribute's value 'yes', xalan-j xsl 3 transformation expects an input document source as SAXSource
---
 .../apache/xalan/templates/ElemSourceDocument.java | 17 ++++++++++++
 .../apache/xalan/transformer/TransformerImpl.java  | 27 +++++++++++++++----
 src/main/java/org/apache/xalan/xslt/Process.java   | 31 +++++++++++++++++++++-
 3 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/xalan/templates/ElemSourceDocument.java b/src/main/java/org/apache/xalan/templates/ElemSourceDocument.java
index 529872910..c5d7a7934 100644
--- a/src/main/java/org/apache/xalan/templates/ElemSourceDocument.java
+++ b/src/main/java/org/apache/xalan/templates/ElemSourceDocument.java
@@ -17,7 +17,10 @@
  */
 package org.apache.xalan.templates;
 
+import javax.xml.transform.Source;
+import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXSource;
 
 import org.apache.xalan.transformer.TransformerImpl;
 import org.apache.xml.dtm.DTMIterator;
@@ -152,6 +155,20 @@ public class ElemSourceDocument extends ElemTemplateElement
   {
 	    
 	    XPathContext xctxt = transformer.getXPathContext();
+	    
+	    SourceLocator srcLocator = xctxt.getSAXLocator(); 
+	    
+	    if (m_streamable) {
+	       Source source = transformer.getSource();	       	       
+	       if (!(source instanceof SAXSource)) {
+	    	   String srcClassName = (source.getClass()).getName();
+	    	   throw new TransformerException("XTTE0505 : xsl:source-document instruction has attribute "
+	    	   		                                            + "\"streamable\" with value 'yes', but XSL transformation "
+	    	   		                                            + "has not been invoked with a SAXSource document input. "
+	    	   		                                            + "This XSL transformation has been invoked with " + 
+	    	   		                                               srcClassName + " document input.", srcLocator);  
+	       }
+	    }
 	  
 	    try {
 	    	transformer.pushCurrentTemplateRuleIsNull(true);
diff --git a/src/main/java/org/apache/xalan/transformer/TransformerImpl.java b/src/main/java/org/apache/xalan/transformer/TransformerImpl.java
index 899147e6e..fc81a1a17 100644
--- a/src/main/java/org/apache/xalan/transformer/TransformerImpl.java
+++ b/src/main/java/org/apache/xalan/transformer/TransformerImpl.java
@@ -417,6 +417,12 @@ public class TransformerImpl extends Transformer
    * A stack of current template modes.
    */
   private Stack m_modes = new Stack();
+  
+  /**
+   * Reference to javax.xml.transform.Source object instance, 
+   * that is used for an XSL transformation.
+   */
+  private Source m_source;
 
   //==========================================================
   // SECTION: Constructor
@@ -670,8 +676,8 @@ public class TransformerImpl extends Transformer
    */
   public void transform(Source source) throws TransformerException
   {
-                transform(source, true); 
-        }
+    transform(source, true); 
+  }
 
   /**
    * Process the source tree to SAX parse events.
@@ -682,6 +688,8 @@ public class TransformerImpl extends Transformer
    */
   public void transform(Source source, boolean shouldRelease) throws TransformerException
   {
+	  
+	m_source = source;
 
     try
     {
@@ -1309,8 +1317,8 @@ public class TransformerImpl extends Transformer
   public void transform(Source xmlSource, Result outputTarget)
           throws TransformerException
   {
-                transform(xmlSource, outputTarget, true);
-        }
+    transform(xmlSource, outputTarget, true);
+  }
 
   /**
    * Process the source tree to the output result.
@@ -1323,7 +1331,8 @@ public class TransformerImpl extends Transformer
   public void transform(Source xmlSource, Result outputTarget, boolean shouldRelease)
           throws TransformerException
   {
-
+	m_source = xmlSource;
+	  
     synchronized (m_reentryGuard)
     {
       SerializationHandler xoh = createSerializationHandler(outputTarget);
@@ -4000,5 +4009,13 @@ public class TransformerImpl extends Transformer
         this.m_isXslIterateOnCompletionActive = isXslIterateOnCompletionActive;
     }
 
+	public Source getSource() {
+		return m_source;
+	}
+
+	public void setSource(Source source) {
+		this.m_source = source;
+	}
+
 }  // end TransformerImpl class
 
diff --git a/src/main/java/org/apache/xalan/xslt/Process.java b/src/main/java/org/apache/xalan/xslt/Process.java
index 153550b1a..79d998486 100644
--- a/src/main/java/org/apache/xalan/xslt/Process.java
+++ b/src/main/java/org/apache/xalan/xslt/Process.java
@@ -871,7 +871,6 @@ public class Process
           {
             if (flavor.equals("d2d"))
             {
-
               // Parse in the xml data into a DOM
               DocumentBuilderFactory dfactory =
                 DocumentBuilderFactory.newInstance();
@@ -919,6 +918,36 @@ public class Process
               else
                 serializer.transform(new DOMSource(outNode), strResult);
             }
+            else if (flavor.equals("s2s"))
+            {            	
+            	DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
+                dfactory.setNamespaceAware(true);
+                
+                DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
+                      
+            	Document doc = docBuilder.newDocument();
+                org.w3c.dom.DocumentFragment outNode = doc.createDocumentFragment();
+
+                transformer.transform(new SAXSource(new InputSource(inFileName)),
+                                      new DOMResult(outNode));
+                
+                // Now serialize output to disk with identity transformer
+                Transformer serializer = stf.newTransformer();
+                serializer.setErrorListener(new DefaultErrorHandler(false));
+                
+                Properties serializationProps = stylesheet.getOutputProperties();
+
+                serializer.setOutputProperties(serializationProps);
+
+                if (contentHandler != null)
+                {
+                  SAXResult result = new SAXResult(contentHandler);
+
+                  serializer.transform(new DOMSource(outNode), result);
+                }
+                else
+                  serializer.transform(new DOMSource(outNode), strResult);
+            }
             else if (flavor.equals("th"))
             {
               for (int i = 0; i < 1; i++) // Loop for diagnosing bugs with inconsistent behavior


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org