Sen
Sen

Reputation: 21

Ignore namespace in XSLT

I have input file comes with different namespace. However, for my requirement I need to handle it with 1 xslt.

Input file 1:

    <header xmlns="urn:xyz:hello">
       <body>
           <element1>hi</element1>
           <element2>sen</element2>
       </body>
    </header>

Input file 2:

<header xmlns="urn:abc:hello1">
   <body>
       <element1>hi</element1>
       <element2>sam</element2>
   </body>
</header>

Similar to the above sample, I would get files with different namespace urn:cdf:well, urn:cdf:hello, ....

How do I handle this in 1 xslt?

Your advise is much appreciated.

Thanks Sen

Upvotes: 1

Views: 606

Answers (1)

Valdi_Bo
Valdi_Bo

Reputation: 30971

Instead of the identity template use the following templates, "deleting" any namespace.

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

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

Upvotes: 1

Related Questions