on 2021 Mar 04 11:34 AM
Hi,
I need to map input to output xml in cpi.
The element "value" can come n number of times in input. It should rename input value segments to value1,value2,value3 etc in output xml.
Can you please let me know how can I handle it.
Input XML - <a> <e> <e> <value>12</value> </e> <e> <value>decribe 12</value> </e> </e> </a>
Output XML - <a> <e> <e> <value1>12</value1> </e> <e> <value2>decribe 12</value2> </e> </e> </a>
Regards
Hi Vijay
Here's a quick and dirty XSLT 3.0 stylesheet, that does what you describe:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<a>
<e>
<xsl:for-each select="//value">
<e>
<xsl:element name="{concat(name(), position())}">
<xsl:value-of select="." />
</xsl:element>
</e>
</xsl:for-each>
</e>
</a>
</xsl:template>
</xsl:stylesheet>
It can be done more elegantly, but I'm in a bit of a hurry 😄
With this input:
<?xml version="1.0" encoding="UTF-8"?>
<a>
<e>
<e>
<value>12</value>
</e>
<e>
<value>decribe 12</value>
</e>
</e>
</a>
It produces the following output:
<?xml version="1.0" encoding="UTF-8"?>
<a>
<e>
<e>
<value1>12</value1>
</e>
<e>
<value2>decribe 12</value2>
</e>
</e>
</a>
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
72 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.