Sarah: XSL Transformation - nur Namespaceänderung!

Hallo zäme

Ich möchte gerne mit Hilfe eines XSL nur den Namespace einer XML Datei ändern. Ich muss zwingend XSL Version 1.0 verwenden.

Mein XML sieht folgendermassen aus:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ass="http://www.test.com/OLD">  
   <soapenv:Header/>  
   <soapenv:Body>  
      <ass:GetCFSObjectStateResponse>  
         <ass:ExceptionDetails>  
            <ass:Type>CFSInstanceNotFoundException</ass:Type>  
            <ass:Message>CFSInstanceNotFoundException</ass:Message>  
         </ass:ExceptionDetails>  
      </ass:GetCFSObjectStateResponse>  
   </soapenv:Body>  
</soapenv:Envelope>

Das bisherige XSL kopierte die XML Datei 1:1:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">  
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>  
	<xsl:template match="/">  
		<xsl:copy-of select="."/>  
	</xsl:template>  
</xsl:stylesheet>

Nun muss ich aber den Namespace mit Hilfe der XSL Datei anpassen, dass schlussendlich folgendes steht:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ass="http://www.test.com/NEW">  
   <soapenv:Header/>  
   <soapenv:Body>  
      <ass:GetCFSObjectStateResponse>  
         <ass:ExceptionDetails>  
            <ass:Type>CFSInstanceNotFoundException</ass:Type>  
            <ass:Message>CFSInstanceNotFoundException</ass:Message>  
         </ass:ExceptionDetails>  
      </ass:GetCFSObjectStateResponse>  
   </soapenv:Body>  
</soapenv:Envelope>

Kann mir jemand bei der XSL Transformation helfen? Im Internet habe ich auch schon sehr lange gesucht, habe aber nichts brauchbares gefunden...

Merci
Sarah

  1. Hallo Sarah,

    Ich bekomme das gesuchte Ergebnis mit diesem Ansatz fast hin:

    <?xml version="1.0" encoding="UTF-8"?>  
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
      
      <xsl:output method="xml" encoding="UTF-8" indent="yes"/>  
      
      <xsl:template match="@* | node()">  
        <xsl:copy>  
          <xsl:apply-templates select="@* | node()"/>  
        </xsl:copy>  
      </xsl:template>  
      
      <xsl:template match="*[starts-with(name(),'soapenv')]">  
        <xsl:element name="{name()}" namespace="http://schemas.xmlsoap.org/soap/envelope">  
          <xsl:apply-templates select="@* | node()"/>  
        </xsl:element>  
      </xsl:template>  
      
      <xsl:template match="*[starts-with(name(),'ass')]">  
        <xsl:element name="{name()}" namespace="http://www.test.com/NEW">  
          <xsl:apply-templates select="@* | node()"/>  
        </xsl:element>  
      </xsl:template>  
      
    </xsl:stylesheet>
    

    Ergebnis:

    <?xml version="1.0" encoding="UTF-8"?>  
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">  
       <soapenv:Header/>  
       <soapenv:Body>  
          <ass:GetCFSObjectStateResponse xmlns:ass="http://www.test.com/NEW">  
             <ass:ExceptionDetails>  
                <ass:Type>CFSInstanceNotFoundException</ass:Type>  
                <ass:Message>CFSInstanceNotFoundException</ass:Message>  
             </ass:ExceptionDetails>  
          </ass:GetCFSObjectStateResponse>  
       </soapenv:Body>  
    </soapenv:Envelope>
    

    xmlns:ass steht zwar nicht beim Wurzelelement, aber immerhin beim ersten Auftreten eines Elements aus dem ass-Namensraum, funktional ok.

    Grüße,
    Thomas

    1. Hey ThomasM

      Vielen herzichen Dank für deine Antwort!

      Mit dieser Variante ist das XML nach der Transformation gültig gegen das Schema!

      Älg
      Sarah