[jira] [Commented] (XALANJ-2629) Trasformation using Xalan removes multiple namespaces from XML

2023-06-14 Thread Joe Kesselman (Jira)


[ 
https://issues.apache.org/jira/browse/XALANJ-2629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17732674#comment-17732674
 ] 

Joe Kesselman commented on XALANJ-2629:
---

If desired, we could add my test to the Xalan regression tests. At the moment I 
have it as tests/jira/jira_xalanj_2629.*, not yet checked in.

> Trasformation using Xalan removes multiple namespaces from XML 
> ---
>
> Key: XALANJ-2629
> URL: https://issues.apache.org/jira/browse/XALANJ-2629
> Project: XalanJ2
>  Issue Type: Bug
>  Security Level: No security risk; visible to anyone(Ordinary problems in 
> Xalan projects.  Anybody can view the issue.) 
>  Components: transformation
>Reporter: Lavanya Hegde
>Assignee: Gary D. Gregory
>Priority: Blocker
>
> Use below Java code to transform an xml string using xsl
>  
> package main;
> import java.io.StringReader;
> import java.io.StringWriter;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class testwsdl
> {     static String xmlIn = " standalone=\"yes\"?>\r\n" +          " continueOnError=\"false\" enabled=\"true\" name=\"SetWSDL\">\r\n" +          
> "    \r\n" +          "        \r\n" +          "            
> http://schemas.xmlsoap.org/wsdl/\; 
> targetNamespace=\"urn:sap-com:document:sap:soap:functions:mc-style\" 
> xmlns:n1=\"urn:sap-com:document:sap:rfc:functions\" 
> xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\; 
> xmlns:tns=\"urn:sap-com:document:sap:soap:functions:mc-style\" 
> xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\; 
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\; 
> xmlns:wsoap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\; 
> xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\; 
> xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\; 
> xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\;>\r\n"
>  +          "            \r\n" +          "        
> \r\n" +          "    \r\n" +          "    
> \r\n" +          "        name\r\n" +          " 
>        \r\n" +          "        \r\n" +          "    
> \r\n" +          "    
> true\r\n" +          " 
>    \r\n" + 
>          "";   static String xsl = " version=\"1.0\"?>\r\n" +        "  "  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\;>\r\n" +        "\r\n" 
> +        "   />\r\n" +        "\r\n" +        "   name=\"vTopDefaultNamespace\" select=\"namespace-uri(/*)\" />\r\n" +        
> "\r\n" +        "\r\n" +        "  \r\n" +  
>       "    \r\n" +        "       select=\"node()|@*\" />\r\n" +        "    \r\n" +        "  
> \r\n" +        "\r\n" +        "   priority=\"10\"\r\n" +        "    match=\"*[name() = local-name()\r\n" +     
>    "        and\r\n" +        "          namespace-uri() = 
> namespace-uri(/*)\r\n" +        "         ]\">\r\n" +        "    
>  \">\r\n" + 
>       "      \r\n" + 
>       "    \r\n" + 
>       "  \r\n" + 
>       "\r\n" + 
>       "  \r\n" + 
>       "     select=\"substring-before(name(), ':')\" />\r\n" + 
>       "\r\n" + 
>       "     namespace=\"\{namespace-uri()}\">\r\n" + 
>       "       $velemNSName)]\" />\r\n" + 
>       "      \r\n" + 
>       "    \r\n" + 
>       "  \r\n" + 
>       "  \r\n" + 
>       "";
>     public static void main(String[] args) throws Exception
> {         StreamSource xslSource = new StreamSource(new StringReader(xsl));   
>       StreamSource xmlInSource = new StreamSource(new StringReader(xmlIn));   
>       Transformer tf = 
> TransformerFactory.newInstance().newTransformer(xslSource);         
> StringWriter xmlOutWriter = new StringWriter();         
> tf.transform(xmlInSource, new StreamResult(xmlOutWriter));         
> System.out.println(xmlOutWriter.toString());     }
> }
>  
> Expected output is:
>  continueOnError="false" enabled="true" name="SetWSDL">
>     
>         
>             http://schemas.xmlsoap.org/wsdl/; 
> xmlns:n1="urn:sap-com:document:sap:rfc:functions" 
> xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy; 
> xmlns:tns="urn:sap-com:document:sap:soap:functions:mc-style" 
> xmlns:http="http://schemas.xmlsoap.org/wsdl/http/; 
> xmlns:xsd="http://www.w3.org/2001/XMLSchema; 
> xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12/; 
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/; 
> xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/; 
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd;
>  targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style">
>             
>         
>     
>     
>         name
>         
>         
>     
>     true
>     
> 
>  
> It works when Trasformer from default library from JDK is 

[jira] [Commented] (XALANJ-2629) Trasformation using Xalan removes multiple namespaces from XML

2023-06-14 Thread Joe Kesselman (Jira)


[ 
https://issues.apache.org/jira/browse/XALANJ-2629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17732670#comment-17732670
 ] 

Joe Kesselman commented on XALANJ-2629:
---

{*}NOTE{*}: The version of Xalan that shipped with Sun's Java processors was 
badly backlevel, and in this case I believe it is, in fact, in error.

XSLT 1.0 had the problem that it had no way to match templates against 
namespace nodes, and thus the default identity transformation published in the 
spec:
{code:java}
  
    
      
    
  {code}
did not preserve them where they occurred. Instead, the system creates new 
namespace nodes where demanded in the output document. In our code, that's 
implemented in the serializer.

Alas, this is a problem when transforming documents that (like XSLT itself!) 
may reference namespace prefixes within strings and expect them to be 
interpreted by context. Since this user embeds the Identity Transform in their 
stylesheet

The *workaround* is to use the namespace:: axis to explicitly preserve these:
     
{code:java}
  
    
       
      
    
  {code}

One can quibble about whether the XSLT 1.0 Working Group should have published 
this rather than the simpler version above, but they didn't.

I've tested this against the "expected output" and namespace nodes were 
preserved:


{code:java}

    
        
            http://schemas.xmlsoap.org/wsdl/; 
xmlns:n1="urn:sap-com:document:sap:rfc:functions" 
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy; 
xmlns:tns="urn:sap-com:document:sap:soap:functions:mc-style" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema; 
xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12/; 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/; 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/; 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd;
 targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style">
            
        
    
    
        name
        
        
    
    true
    
{code}

So I'm afraid the answer is that [~LavanyaHegde]  needs to modify the 
stylesheet, replacing its version of the default template with one that 
includes this additional clause.

Or to move to an XSLT 2.0 compatable processor, where this was addressed in 
https://www.w3.org/TR/xslt20/#copying:
{quote}The [{{xsl:copy}}|https://www.w3.org/TR/xslt20/#element-copy] 
instruction has an optional {{inherit-namespaces}} attribute, with the value 
{{yes}} or {{{}no{}}}. The default value is {{{}yes{}}}. 
{quote}
*Move to close, working as designed, explanation and solution provided.*

> Trasformation using Xalan removes multiple namespaces from XML 
> ---
>
> Key: XALANJ-2629
> URL: https://issues.apache.org/jira/browse/XALANJ-2629
> Project: XalanJ2
>  Issue Type: Bug
>  Security Level: No security risk; visible to anyone(Ordinary problems in 
> Xalan projects.  Anybody can view the issue.) 
>  Components: transformation
>Reporter: Lavanya Hegde
>Assignee: Gary D. Gregory
>Priority: Blocker
>
> Use below Java code to transform an xml string using xsl
>  
> package main;
> import java.io.StringReader;
> import java.io.StringWriter;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class testwsdl
> {     static String xmlIn = " standalone=\"yes\"?>\r\n" +          " continueOnError=\"false\" enabled=\"true\" name=\"SetWSDL\">\r\n" +          
> "    \r\n" +          "        \r\n" +          "            
> http://schemas.xmlsoap.org/wsdl/\; 
> targetNamespace=\"urn:sap-com:document:sap:soap:functions:mc-style\" 
> xmlns:n1=\"urn:sap-com:document:sap:rfc:functions\" 
> xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\; 
> xmlns:tns=\"urn:sap-com:document:sap:soap:functions:mc-style\" 
> xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\; 
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\; 
> xmlns:wsoap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\; 
> xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\; 
> xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\; 
> xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\;>\r\n"
>  +          "            \r\n" +          "        
> \r\n" +          "    \r\n" +          "    
> \r\n" +          "        name\r\n" +          " 
>        \r\n" +          "        \r\n" +          "    
> \r\n" +          "    
> true\r\n" +          " 
>    \r\n" + 
>          "";   static String xsl = " version=\"1.0\"?>\r\n" +        "  "  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\;>\r\n" +        "\r\n" 
> +        "   />\r\n" +