Delete namespace for a specific item

Is there a way to remove the namespace for a specific item?

+3
source share
2 answers

This conversion is :

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

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

 <xsl:template match="x:*">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="namespace::*[not(. = namespace-uri(..))]"/>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
 </xsl:template>
</xsl:stylesheet>

removes any element from the namespace "my:x"and puts it in "no namespace".

For example, when applied to the following XML document:

<t>
  <x:a  xmlns:x="my:x"/>
</t>

required, the correct result is obtained :

<t>
   <a/>
</t>

To remove only a specific item from a specific namespace, a template that overrides an identification rule must be more specific to match only the desired item .

+7
source

XSLT (Node ), . , "http://www.foo/". (, , ) .

<xsl:stylesheet xmnls:h="http://www.foo/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- other elements and root omitted -->

    <xsl:template match="h:table">
      <table>
        <!-- copy or transform attributes and children -->
      </table>
    </xsl:table>

</xsl:stylesheet>

node , , , , . [, xsl: copy... -

UPDATE:... @Dmitri !

0

Source: https://habr.com/ru/post/1779173/


All Articles