0

I have an xml from one of our 'legacy' systems. I want to remove the ExtLineNum tag but it's not located in the root.

I have stripped the xml for my example:

  <?xml version="1.0" encoding="utf-8"?><ns0:Envelope xmlns:ns0="http://schemas.microsoft.com/dynamics/2008/01/documents/Message"><ns0:Header><ns0:MessageId>{F2BCADA1-AC26-4A0C-BA44-11D75E249150}</ns0:MessageId><ns0:SourceEndpointUser>du.msad\btshostinstance</ns0:SourceEndpointUser><ns0:SourceEndpoint>EDI</ns0:SourceEndpoint><ns0:DestinationEndpoint>JWR</ns0:DestinationEndpoint><ns0:Action>http://schemas.microsoft.com/dynamics/2008/01/services/SalesOrderService/create</ns0:Action><ns0:ConversationId /><ns0:RequestMessageId /></ns0:Header><ns0:Body><ns0:MessageParts><SalesOrder xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SalesTable class="entity">
    <ActionCode></ActionCode>
    <SalesLine class="entity">
      <ExtLineNum></ExtLineNum>
    </SalesLine>
  </SalesTable>
</SalesOrder></ns0:MessageParts></ns0:Body></ns0:Envelope>

I've tried:

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

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="ExtLineNum"/>

</xsl:stylesheet>

But that didn't work out.. Guess it's a simple question but I can't find the answer?

Thanks in advance,

Mike

Mike Dole
  • 675
  • 2
  • 14
  • 30

2 Answers2

1

Thanks to the link provided by Michael.hor257k I found the correct namespace syntax:

    <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:met="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder"
exclude-result-prefixes="met">

 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="met:SalesOrder/met:SalesTable/met:SalesLine/met:ExtLineNum"/>
</xsl:stylesheet>

Thnx guys for your help!

Kind regards,

Mike

Community
  • 1
  • 1
Mike Dole
  • 675
  • 2
  • 14
  • 30
-1

Try matching the parent node and skip the inner node with node-nam 'ExtLineNum':

<xsl:template match="SalesLine">
    <xsl:copy-of select="*[node-name() != 'ExtLineNum']" />
</xsl:template>
  • This is not a good answer, on several counts: (a) the syntax is invalid; (b) it will not work, because the template does not match anything; (c) the underlying idea of ignoring the namespace is bad practice. – michael.hor257k Jun 20 '16 at 13:44