This is my input XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Payload>
<a1>GDS</a1>
<a2>82.0</a2>
<tag0000>
<array>
<dateSent><string>20230130</string></dateSent>
<timeSent><string>1259</string></timeSent>
</array>
</tag0000>
</Payload>
I need to remove the array tag and remove string tag as well, and i need to rename tag0000 to Tagx00 if tag0000 comes and tagx200 is tag2000 comes, so basically in need the output like this
<?xml version="1.0" encoding="UTF-8"?>
<Payload>
<a1>GDS</a1>
<a2>82.0</a2>
<tagx000>
<dateSent>20230130</dateSent>
<timeSent>1259</timeSent>
</tagx000>
</Payload>
this is my code, i am relatively new to xslt
<?xml version="1.0" encoding="UTF-8"?>
\<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\>
\<xsl:template match="string"\>
\<xsl:value-of select="."/\>
\</xsl:template\>
\<xsl:template match="@*|node()"\>
\<xsl:copy\>
\<xsl:apply-templates select="@*|node()"/\>
\</xsl:copy\>
\</xsl:template\>
\<xsl:template match="*/text()\[normalize-space()\]"\>
\<xsl:value-of select="normalize-space()"/\>
\</xsl:template\>
\<xsl:template match="*/text()\[not(normalize-space())\]" /\>
\<xsl:template match="*\[starts-with(name(), 'tag0') or starts-with(name(), 'tag2') \]"\>
\<xsl:element name="{concat('tagx', substring(name(), 5))}"\>
\<xsl:apply-templates select="*" /\>
\</xsl:element\>
\</xsl:template\>
<!-- rename item to its parent's name -->
\<xsl:template match="array"\>
\<xsl:element name="{name(..)}"\>
\<xsl:apply-templates/\>
\</xsl:element\>
\</xsl:template\>
\</xsl:stylesheet\>
but i am getting the result where <tag0000> is still coming alongwith tagx000
<?xml version="1.0" encoding="UTF-8"?>
<Payload>
<a1>GDS</a1>
<a2>82.0</a2>
<tagx000><tag0000>
<dateSent>20230130</dateSent>
<timeSent>1259</timeSent>
</tag0000></tagx000>
</Payload>
please help me do all the operations within one code
How about:
XSLT 1.0
If you want, you could combine the last two templates into something like: