0

My XML looks like this.

<?xml version="1.0" encoding="utf-8"?>
 <ns0:Respuesta xmlns:ns0="http://www.siebel.com/xml/SBL_EAI_RC13_SC03_HPFMS_ConsultaTajetadeCreditoenBlackList_29004_Respuesta">
  <ns0:Error>
   <ns0:Codigo>30</ns0:Codigo>
   <ns0:Descripcion>Numero no encontrado en la lista</ns0:Descripcion>
   <ns0:Sistema>adaptadorCFMS</ns0:Sistema>
   <ns0:Tipo>Adaptador</ns0:Tipo>
   <ns0:TimeStamp>2014-06-26T14:40:42</ns0:TimeStamp>
   <ns0:IdHost>medusa10</ns0:IdHost>
  </ns0:Error>
 </ns0:Respuesta>

I need to remove the 'ns0:' part of elements. It doesnt necessarily need to be 'ns0:', it can be 'ns1:' or 'ns2:, hence all those that look like that starting with 'ns' needs to be removed.

The 'ns0:' is also present as a suffix in the namespace xmlns attribute which needs to be removed too.

so the output xml should look like this.

<?xml version="1.0" encoding="utf-8"?>
 <Respuesta xmlns="http://www.siebel.com/xml/SBL_EAI_RC13_SC03_HPFMS_ConsultaTajetadeCreditoenBlackList_29004_Respuesta">
 <Error>
  <Codigo>30</Codigo>
  <Descripcion>Numero no encontrado en la lista</Descripcion>
  <Sistema>adaptadorCFMS</Sistema>
  <Tipo>Adaptador</Tipo>
  <TimeStamp>2014-06-26T14:40:42</TimeStamp>
  <IdHost>medusa10</IdHost>
 </Error>
</Respuesta>

Can you please help me with this? I would really appreciate your help.

1 Answer 1

1

Write a template that strips namespace prefixes from element nodes using e.g.

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

then add a template copying attributes, comments, text

<xsl:template match="@* | text() | processing-instruction() | comment()">
  <xsl:copy/>
</xsl:template>
Sign up to request clarification or add additional context in comments.

1 Comment

Note that technically, in XSLT 1.0 the processor has absolute discretion over choice of namespace prefixes, so the above isn't guaranteed to work. In XSLT 2.0 the spec is more prescriptive, and requires this stylesheet to produce elements in the default namespace (that is, unprefixed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.