Topic
5 replies Latest Post - ‏2012-11-08T23:00:12Z by triniman10
triniman10
triniman10
29 Posts
ACCEPTED ANSWER

Pinned topic Remove Namespace not working

‏2012-11-07T16:43:05Z |
We have a xsl that does a soap injection to include the date time stamp for each message. It also seems to add xmlns="" attribute to the DataPowerReceiptDateTime we inject which the client can't accept. I'm trying to use another style sheet (see attached for test xml) to remove this specific namespace before sending on to client. My question is, when we do this injection is there a way to stop the addition of the xmlns="" so that we don't have to strip after?

If not, the issue I'm having with my xsl is that it's copying only the node where the DataPowerReceiptDateTime (without the xmlns="" which is what I want) resides but stripping the Envelope, Header and Body.

How do I preserve the SOAP Envelope and just strip out the namepace on this tag?

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dp="http://www.datapower.com/extensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" extension-element-prefixes="dp"
exclude-result-prefixes="dp soapenv">

<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="soapenv:Envelope/soapenv:Header/*/node

()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*" />
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="node()"/>
</xsl:attribute>
</xsl:template>

<xsl:template match="text() | processing-instruction() | comment()">
<xsl:copy />
</xsl:template>
</xsl:stylesheet>

Attachments

Updated on 2012-11-08T23:00:12Z at 2012-11-08T23:00:12Z by triniman10
  • HermannSW
    HermannSW
    2818 Posts
    ACCEPTED ANSWER

    Re: Remove Namespace not working

    ‏2012-11-07T20:09:59Z  in response to triniman10
    Please clarify on what you want to achieve.

    <DataPowerReceiptDateTime xmlns="">
    is the only child of
    <outboundHeader xmlns="urn:Common_Soap_Header_201002">
    with empty default namespace.

    If you would remove xmlns="" then <DataPowerReceiptDateTime> would be in "urn:Common_Soap_Header_201002" namespace, which it is currently not:
    $ xpath++ "/*/*/*[1]/*[position()>2]" Test.xml
     
    -------------------------------------------------------------------------------
    <origination component="TSS-FOS" node="S011UNUS02" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns="urn:Common_Soap_Header_201002"/>
    -------------------------------------------------------------------------------
    <DataPowerReceiptDateTime xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">2012-11-07T11:30:57-05:00</DataPowerReceiptDateTime>
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:46:08Z at 2014-03-25T02:46:08Z by iron-man
    • triniman10
      triniman10
      29 Posts
      ACCEPTED ANSWER

      Re: Remove Namespace not working

      ‏2012-11-07T20:42:19Z  in response to HermannSW
      the urn: namespace is a client provided xsd along with the wsdls. The DataPowerReceiptDateTime was injected with the following xsl used in WSP:
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:SOAP-ENV ="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:date="http://exslt.org/dates-and-times"
      version="1.0"
      extension-element-prefixes="date"
      exclude-result-prefixes="date">
      <!-- Template to match the soap Header element -->
      <xsl:template match="/SOAP-ENV:Envelope/SOAP-ENV:Header[1]/*[1]">
      <xsl:copy>
      <xsl:apply-templates/>
      <!-- Insert new headers here -->
      <DataPowerReceiptDateTime><xsl:value-of select="date:date-time()" /></DataPowerReceiptDateTime>
      </xsl:copy>
      </xsl:template>
      <!-- Template to perform a Standard Identity Transform -->
      <xsl:template match="@*|node()">
      <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
      </xsl:template>
      </xsl:stylesheet>

      Client required a Date Time stamp in SOAP Header so after this injection it created the xmlns="" and now I understand why due to your explanation. We don't have flexibility to update the client's wsdls/xsds as they delivered to us and they've already coded the backend receiving app to accept this injected tag of DataPowerReceiptDateTime. This brought me to the question of how to effectively remove the xmlns="" after the injection.

      Does this clarify it further. This is a configuration I took over so trying to figure out how to meet this requirement with what's already been done.
    • triniman10
      triniman10
      29 Posts
      ACCEPTED ANSWER

      Re: Remove Namespace not working

      ‏2012-11-08T05:57:55Z  in response to HermannSW
      Hermann, I believe I misunderstood what you said about removing the namespace from DataPowerRecipt but I believe I do now. I will pose the question to the receiving service to see if that is acceptable. All I've been told is that the xmlns="" is causing errors with their code but were never told what type. Is it possible their code is failing in already trying to validate that inject SOAP element but can't and by us removing the blank namespace their code will still error out in trying to validate that element? Either way I'd still like to see if I can strip it out and then if it fails on the backend service they would have a better idea of what they want or need to handle. Thoughts?
      • HermannSW
        HermannSW
        2818 Posts
        ACCEPTED ANSWER

        Re: Remove Namespace not working

        ‏2012-11-08T22:22:01Z  in response to triniman10
        Hi Burt,

        better than extracting the xmlns="" (and changing the namespace of <DataPowerReceiptDateTime> that way),
        it is to inject <DataPowerReceiptDateTime> in the correct namespace in the first place.

        See below the single line change to your inject.xsl stylesheet that makes this happen:
        
        $ diff original.xml Test.xml 7a8 >                 <DataPowerReceiptDateTime xmlns=
        "">2012-11-07T11:30:57-05:00</DataPowerReceiptDateTime> $ $ coproc2 inject.2.xsl original.xml http:
        //dp3-l3:2223 ; echo <?xml version=
        "1.0" encoding=
        "UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=
        "http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header xmlns:wsa=
        "http://www.w3.org/2005/08/addressing"> <outboundHeader xmlns=
        "urn:Common_Soap_Header_201002"> <messageName>SomeMessage</messageName> <transactionId>-1091134092</transactionId> <origination component=
        "TSS-FOS" node=
        "S011UNUS02"/> <DataPowerReceiptDateTime>2012-11-08T17:10:16-05:00</DataPowerReceiptDateTime></outboundHeader> <wsa:Action>SomeAction</wsa:Action> </SOAP-ENV:Header> <SOAP-ENV:Body>.....</SOAP-ENV:Body> </SOAP-ENV:Envelope> $ $ diff inject.xsl inject.2.xsl 14c14 < <DataPowerReceiptDateTime><xsl:value-of select=
        "date:date-time()" /></DataPowerReceiptDateTime> --- > <DataPowerReceiptDateTime xmlns=
        "urn:Common_Soap_Header_201002"><xsl:value-of select=
        "date:date-time()" /></DataPowerReceiptDateTime> $
        


         
        Hermann<myXsltBlog/> <myXsltTweets/>
        • triniman10
          triniman10
          29 Posts
          ACCEPTED ANSWER

          Re: Remove Namespace not working

          ‏2012-11-08T23:00:12Z  in response to HermannSW
          So, this is interesting as I incorporated your idea into our stylesheet (see attached) and instead of seeing the result you posted it achieved what I've been trying to do all this time. It removed the default xmlns="" completely.

          <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
          <SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
          <outboundHeader xmlns="urn:ALIS_Common_Soap_Header_201002">
          <messageName>SomeMessage</messageName>
          <transactionId>-1091134092</transactionId>
          <origination component="TSS-FOS" node="S011UNUS02" />
          <DataPowerReceiptDateTime>2012-11-08T17:46:16-05:00</DataPowerReceiptDateTime>
          </outboundHeader>
          <wsa:Action>SomeAction</wsa:Action>
          </SOAP-ENV:Header>
          <SOAP-ENV:Body>.... </SOAP-ENV:Body></SOAP-ENV:Envelope>
          I would have expected to see the urn:Common_Soap_Header_201002 attribute in that element but now by definining it as having a namespace in the stylesheet it doesn't not assign that xmlns attribute.

          Is this because the processor sees a namespace assignment so sees no need to add the default namespace?

          Also, since I haven't been able to figure it out as yet, just for future reference if the need arises how would I would remove that attribute xmlns=""?

          Thanks for the help as that at least gives the customer what they need to process these messages as I still don't know why there parser couldn't handle the default namespace.