Reputation: 21
Here is the minimal code I want to add the namespace in the header tag. Here is my input XML.Can any one Help me.
<?xml version="1.0"?>
<R>
<M>
<H>1</H>
<B>
<p Ccy="GBP">1</p>
</B>
</M>
<M>
<H>1</H>
<B>
<p Ccy="GBP">4</p>
</B>
</M>
I have tried like this
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
<xsl:output indent="yes" />
<xsl:template match="/*">
<R>
<M>
<xsl:apply-templates select="M[1]/H | M/B" />
</M>
</R>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
Expected output
<R xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 Y:\Data\Dokument\Kommunikation\Layouter\ISO20022\Schema\Pain001\pain.001.001.03.xsd">
<M>
<H>1</H>
<B>
<p Ccy="GBP">1</p>
</B>
<B>
<p Ccy="GBP">4</p>
</B>
</M>
</R>
Fiddle https://xsltfiddle.liberty-development.net/ej9EGbG/41
Upvotes: 0
Views: 66
Reputation: 461
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
<xsl:output indent="yes" />
<xsl:template match="/*">
<R xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 Y:\Data\Dokument\Kommunikation\Layouter\ISO20022\Schema\Pain001\pain.001.001.03.xsd">
<M>
<xsl:apply-templates select="M[1]/H | M/B" />
</M>
</R>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
Chek it.
Upvotes: 1