XSLT to remove some attributes

I have the following XML that can be displayed in any form in my XML document:

<Message xsi:schemaLocation="http://www.location.com StructureFile.xsd" xmlns=http://www.thenamespace.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

or

<Message xmlns="http://www.thenamespace.com">

and I need a conclusion:

<Message xmlns="http://www.theNEWnamespace.com">

This template currently handles a shorter version of two xml features:

<xsl:template match="*">
  <xsl:element name="{name()}" namespace="http://www.theNEWnamespace.com">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

However, this does not delete the SchemeLocation or xmlns: xsi xml sections, if they exist.

How do I proceed to adapt the above to handle both possibilities.

Greetings

Edit: XML structure:

<?xml version="1.0" encoding="utf-8"?>
<Message xsi:schemaLocation="http://www.location.com StructureFile.xsd" xmlns="http://www.thenamespace.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Header>
    <Info></Info>
  </Header>
</Message>
+3
source share
2 answers

Here is the complete conversion creating the desired result :

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

 <xsl:template match="x:Message">
  <xsl:element name="{name()}" namespace="http://www.theNEWnamespace.com">
    <xsl:copy-of select="@*[not(name() = 'xsi:SchemaLocation')]"/>
    <xsl:apply-templates/>
  </xsl:element>
 </xsl:template>
</xsl:stylesheet>

When this conversion is applied to the following XML document (none provided!):

<t>
  <Message
  xsi:SchemaLocation="http://www.location.com StructureFile.xsd"
  xmlns="http://www.thenamespace.com"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</t>

the desired, correct result is output:

<Message xmlns="http://www.theNEWnamespace.com"/>
+4
source

, XSLT/XPath xsi:schemaLocation . - , <xsl:copy-of select="@*"/>, . , , <xsl:copy-of select="@*"/> <xsl:apply-templates select="@*"/>, , , , .

<xsl:template match="@*">
  <xsl:copy/>
</xsl:template>

<xsl:template match="@xsi:schemaLocation"/>

xmlns:xsi, , XSLT/XPath . , , - , , , .

, exclude-result-prefixes="xsi" xsl:stylesheet.

+2

All Articles