0

I have this xml and I only want to get the 'responseMessage' and all its content. My xsl below doesn't work. When I remove the namespace beside the requestMessage node, I'm getting the desired output but that should not be the case because it is always expected that the requestNode must have the namespace.

XML Input

 <?xml version="1.0" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body >
<requestMessage xmlns="http://xmlns.oracle.com/OUMWM/Message">
  <language>ENG</language>
  <deviceFlag>M2ER</deviceFlag>
  <badgeNumber>222</badgeNumber>
  <responseMessage>
    
    <response>
      
      <ertResponse>
        
        <verificationStatus>F</verificationStatus>
        <errorCode>22601</errorCode>
        <errorText>Badge Number 222 not found</errorText>
      </ertResponse>
    </response>
  </responseMessage>
</requestMessage>
</soap:Body >
</soap:Envelope>

XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" />

    <!-- Pretty Print Output -->
    <xsl:strip-space elements="*"/>
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

    <!-- Remove namepsaces -->
    <xsl:template match="*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
    
    <!-- Construct response -->
    <xsl:template match="/*">
        <xsl:apply-templates select="//responseMessage"/>
    </xsl:template>

</xsl:stylesheet>

Desired Output:

<responseMessage>
   <response>
      <ertResponse>
         <verificationStatus>F</verificationStatus>
         <errorCode>22601</errorCode>
         <errorText>Badge Number 222 not found</errorText>
      </ertResponse>
   </response>
</responseMessage>
Ti J
  • 261
  • 2
  • 7
  • 15

1 Answers1

2

You should declare the namespace "http://xmlns.oracle.com/OUMWM/Message" and i.e. use it like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
  xmlns:or="http://xmlns.oracle.com/OUMWM/Message"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" />
  
  <!-- Pretty Print Output -->
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
  
  <!-- Remove namepsaces -->
  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
  
  <!-- Construct response match on root-->
  <xsl:template match="/">
    <xsl:apply-templates select="*/*/or:requestMessage/or:responseMessage"/>
  </xsl:template>
    
</xsl:stylesheet>
Siebe Jongebloed
  • 3,906
  • 2
  • 14
  • 19